mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-12-22 22:13:20 +02:00
b287a25de7
Some checks failed
Merge Conflict Labeler / Labeling (push) Has been skipped
json-yaml-validate / json-yaml-validate (push) Successful in 12s
Auto Test / check-linters (push) Failing after 22m10s
Auto Test / auto-test (18, ARM64) (push) Has been cancelled
Auto Test / auto-test (18, macos-latest) (push) Has been cancelled
Auto Test / auto-test (18, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (18, windows-latest) (push) Has been cancelled
Auto Test / auto-test (20.5, ARM64) (push) Has been cancelled
Auto Test / auto-test (20.5, macos-latest) (push) Has been cancelled
Auto Test / auto-test (20.5, ubuntu-latest) (push) Has been cancelled
Auto Test / auto-test (20.5, windows-latest) (push) Has been cancelled
Auto Test / armv7-simple-test (18, ARMv7) (push) Has been cancelled
Auto Test / armv7-simple-test (20, ARMv7) (push) Has been cancelled
Auto Test / e2e-test (push) Has been cancelled
Automatically close stale issues / stale (push) Successful in 16s
CodeQL / Analyze (go) (push) Failing after 56s
CodeQL / Analyze (javascript-typescript) (push) Failing after 27s
54 lines
1.7 KiB
JavaScript
54 lines
1.7 KiB
JavaScript
const NotificationProvider = require("./notification-provider");
|
|
const axios = require("axios");
|
|
const { getMonitorRelativeURL, UP, DOWN } = require("../../src/util");
|
|
const { Settings } = require("../settings");
|
|
|
|
class AlertNow extends NotificationProvider {
|
|
name = "AlertNow";
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
|
const 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 Settings.get("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;
|