rebased new providers

pull/3182/head
Frank Elsinga 2 months ago
parent 5dea00737c
commit 2685153317

@ -3,19 +3,18 @@ const axios = require("axios");
const { DOWN, UP } = require("../../src/util");
class GrafanaOncall extends NotificationProvider {
name = "GrafanaOncall";
/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";
if (!notification.GrafanaOncallURL) {
throw new Error("GrafanaOncallURL cannot be empty");
}
let okMsg = "Sent Successfully.";
try {
if (heartbeatJSON === null) {
let grafanaupdata = {
@ -23,10 +22,7 @@ class GrafanaOncall extends NotificationProvider {
message: msg,
state: "alerting",
};
await axios.post(
notification.GrafanaOncallURL,
grafanaupdata
);
await axios.post(notification.GrafanaOncallURL, grafanaupdata);
return okMsg;
} else if (heartbeatJSON["status"] === DOWN) {
let grafanadowndata = {
@ -34,10 +30,7 @@ class GrafanaOncall extends NotificationProvider {
message: heartbeatJSON["msg"],
state: "alerting",
};
await axios.post(
notification.GrafanaOncallURL,
grafanadowndata
);
await axios.post(notification.GrafanaOncallURL, grafanadowndata);
return okMsg;
} else if (heartbeatJSON["status"] === UP) {
let grafanaupdata = {
@ -45,10 +38,7 @@ class GrafanaOncall extends NotificationProvider {
message: heartbeatJSON["msg"],
state: "ok",
};
await axios.post(
notification.GrafanaOncallURL,
grafanaupdata
);
await axios.post(notification.GrafanaOncallURL, grafanaupdata);
return okMsg;
}
} catch (error) {

@ -11,14 +11,14 @@ class OneBot extends NotificationProvider {
const okMsg = "Sent Successfully.";
try {
let httpAddr = notification.httpAddr;
if (!httpAddr.startsWith("http")) {
httpAddr = "http://" + httpAddr;
let url = notification.httpAddr;
if (!url.startsWith("http")) {
url = "http://" + url;
}
if (!httpAddr.endsWith("/")) {
httpAddr += "/";
if (!url.endsWith("/")) {
url += "/";
}
let onebotAPIUrl = httpAddr + "send_msg";
url += "send_msg";
let config = {
headers: {
"Content-Type": "application/json",
@ -37,7 +37,7 @@ class OneBot extends NotificationProvider {
data["message_type"] = "private";
data["user_id"] = notification.recieverId;
}
await axios.post(onebotAPIUrl, data, config);
await axios.post(url, data, config);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);

Loading…
Cancel
Save