Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SevenIO Notification Provider #4219

Merged
merged 10 commits into from
Apr 27, 2024
77 changes: 77 additions & 0 deletions server/notification-providers/sevenio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
const NotificationProvider = require("./notification-provider");
const Axios = require("axios");
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
const { DOWN, UP } = require("../../src/util");

class SevenIO extends NotificationProvider {

CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
name = "SevenIO";

/**
* @inheritdoc
*/
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
const okMsg = "Sent Successfully.";

const data = {
to: notification.sevenioTo,
from: notification.sevenioSender || "Uptime Kuma",
scolastico marked this conversation as resolved.
Show resolved Hide resolved
text: msg,
};

const axios = Axios.create({
baseURL: "https://gateway.seven.io/api/",
headers: {
"Content-Type": "application/json",
"X-API-Key": notification.sevenioApiKey,
},
});
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved

try {
// testing or certificate expiry notification
if (heartbeatJSON == null) {
await axios.post("sms", data);
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
return okMsg;
}

let address;
scolastico marked this conversation as resolved.
Show resolved Hide resolved

switch (monitorJSON["type"]) {
case "ping":
address = monitorJSON["hostname"];
break;
case "port":
case "dns":
case "gamedig":
case "steam":
address = monitorJSON["hostname"];
if (monitorJSON["port"]) {
address += ":" + monitorJSON["port"];
}
break;
default:
if (![ "https://", "http://" ].includes(monitorJSON["url"])) {
scolastico marked this conversation as resolved.
Show resolved Hide resolved
address = monitorJSON["url"];
} else {
address = "n/a";
scolastico marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}

// If heartbeatJSON is not null, we go into the normal alerting loop.
if (heartbeatJSON["status"] === DOWN) {
data.text = `Your service ${monitorJSON["name"]} (${address}) went down at ${heartbeatJSON["localDateTime"]} ` +
`(${heartbeatJSON["timezone"]}). Error: ${heartbeatJSON["msg"]}`;
} else if (heartbeatJSON["status"] === UP) {
data.text = `Your service ${monitorJSON["name"]} (${address}) went back up at ${heartbeatJSON["localDateTime"]} ` +
`(${heartbeatJSON["timezone"]}).`;
}
await axios.post("sms", data);
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}

}

module.exports = SevenIO;
4 changes: 3 additions & 1 deletion server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const GoAlert = require("./notification-providers/goalert");
const SMSManager = require("./notification-providers/smsmanager");
const ServerChan = require("./notification-providers/serverchan");
const ZohoCliq = require("./notification-providers/zoho-cliq");
const SevenIO = require("./notification-providers/sevenio");

class Notification {

Expand Down Expand Up @@ -124,7 +125,8 @@ class Notification {
new Webhook(),
new WeCom(),
new GoAlert(),
new ZohoCliq()
new ZohoCliq(),
new SevenIO(),
];
for (let item of list) {
if (! item.name) {
Expand Down
3 changes: 2 additions & 1 deletion src/components/NotificationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ export default {
"Splunk": "Splunk",
"webhook": "Webhook",
"GoAlert": "GoAlert",
"ZohoCliq": "ZohoCliq"
"ZohoCliq": "ZohoCliq",
"SevenIO": "SevenIO",
};

// Put notifications here if it's not supported in most regions or its documentation is not in English
Expand Down
22 changes: 22 additions & 0 deletions src/components/notifications/SevenIO.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<template>
<div class="mb-3">
<label for="sevenio-api-key" class="form-label">{{ $t("apiKeySevenIO") }}</label>
<input id="sevenio-api-key" v-model="$parent.notification.sevenioApiKey" type="password" class="form-control" required autocomplete="false">
<div class="form-text">
{{ $t("wayToGetSevenIOApiKey") }}
</div>
</div>

<div class="mb-3">
<label for="sevenio-sender" class="form-label">{{ $t("senderSevenIO") }}</label>
<input id="sevenio-sender" v-model="$parent.notification.sevenioSender" type="text" class="form-control" autocomplete="false" placeholder="Uptime Kuma">
</div>

<div class="mb-3">
<label for="sevenio-receiver" class="form-label">{{ $t("receiverSevenIO") }}</label>
<input id="sevenio-receiver" v-model="$parent.notification.sevenioReceiver" type="number" class="form-control" required autocomplete="false" placeholder="0123456789">
<div class="form-text">
{{ $t("receiverInfoSevenIO") }}
</div>
</div>
</template>
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
4 changes: 3 additions & 1 deletion src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import WeCom from "./WeCom.vue";
import GoAlert from "./GoAlert.vue";
import ZohoCliq from "./ZohoCliq.vue";
import Splunk from "./Splunk.vue";
import SevenIO from "./SevenIO.vue";

/**
* Manage all notification form.
Expand Down Expand Up @@ -111,7 +112,8 @@ const NotificationFormList = {
"WeCom": WeCom,
"GoAlert": GoAlert,
"ServerChan": ServerChan,
"ZohoCliq": ZohoCliq
"ZohoCliq": ZohoCliq,
"SevenIO": SevenIO,
};

export default NotificationFormList;
7 changes: 6 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -880,5 +880,10 @@
"useRemoteBrowser": "Use a Remote Browser",
"deleteRemoteBrowserMessage": "Are you sure want to delete this Remote Browser for all monitors?",
"GrafanaOncallUrl": "Grafana Oncall URL",
"Browser Screenshot": "Browser Screenshot"
"Browser Screenshot": "Browser Screenshot",
"wayToGetSevenIOApiKey": "Visit the dashboard under app.seven.io > developer > api key > the green add button",
"senderSevenIO": "Sending number or name",
"receiverSevenIO": "Receiving number",
"receiverInfoSevenIO": "If receiving number is not located in germany you have to add the country code in front of the number, eg for the country code 1 from the us: 117612121212 (instead of 017612121212)",
scolastico marked this conversation as resolved.
Show resolved Hide resolved
"apiKeySevenIO": "SevenIO API Key"
}