parent
11243a6ca1
commit
5f6347d277
@ -0,0 +1,50 @@
|
||||
const NotificationProvider = require("./notification-provider");
|
||||
const axios = require("axios");
|
||||
const { setting } = require("../util-server");
|
||||
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
|
||||
|
||||
class AlertNow extends NotificationProvider {
|
||||
|
||||
name = "AlertNow";
|
||||
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
let okMsg = "Sent Successfully.";
|
||||
try {
|
||||
let textMsg = "";
|
||||
let status = "open";
|
||||
let eventType = "ERROR";
|
||||
let eventId = new Date().toISOString().slice(0, 10).replace(/-/g, "");
|
||||
|
||||
if (heartbeatJSON && heartbeatJSON.status === UP) {
|
||||
textMsg = `[${heartbeatJSON.name}] ✅ Application is back online`;
|
||||
status = "close";
|
||||
eventType = "INFO";
|
||||
eventId += `_${heartbeatJSON.name.replace(/\s/g, "")}`;
|
||||
} else if (heartbeatJSON && heartbeatJSON.status === DOWN) {
|
||||
textMsg = `[${heartbeatJSON.name}] 🔴 Application went down`;
|
||||
}
|
||||
|
||||
textMsg += ` - ${msg}`;
|
||||
|
||||
const baseURL = await setting("primaryBaseURL");
|
||||
if (baseURL && monitorJSON) {
|
||||
textMsg += ` >> ${baseURL + getMonitorRelativeURL(monitorJSON.id)}`;
|
||||
}
|
||||
|
||||
const data = {
|
||||
"summary": textMsg,
|
||||
"status": status,
|
||||
"event_type": eventType,
|
||||
"event_id": eventId,
|
||||
};
|
||||
|
||||
await axios.post(notification.alertNowWebhookURL, data);
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = AlertNow;
|
@ -0,0 +1,13 @@
|
||||
<template>
|
||||
<div class="mb-3">
|
||||
<label for="alertnow-webhook-url" class="form-label">{{ $t("Webhook URL") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||
<input id="alertnow-webhook-url" v-model="$parent.notification.alertNowWebhookURL" type="text" class="form-control" required>
|
||||
|
||||
<div class="form-text">
|
||||
<span style="color: red;"><sup>*</sup></span>{{ $t("Required") }}
|
||||
<i18n-t tag="p" keypath="aboutWebhooks" style="margin-top: 8px;">
|
||||
<a href="https://service.opsnow.com/docs/alertnow/en/user-guide-alertnow-en.html#standard" target="_blank">{{ $t("here") }}</a>
|
||||
</i18n-t>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
Loading…
Reference in new issue