SevenIO Notification Provider (#4219)
Co-authored-by: Frank Elsinga <frank@elsinga.de>pull/4727/head
parent
126d6cd912
commit
19e8c75c3b
@ -0,0 +1,78 @@
|
|||||||
|
const NotificationProvider = require("./notification-provider");
|
||||||
|
const axios = require("axios");
|
||||||
|
const { DOWN, UP } = require("../../src/util");
|
||||||
|
|
||||||
|
class SevenIO extends NotificationProvider {
|
||||||
|
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",
|
||||||
|
text: msg,
|
||||||
|
};
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
baseURL: "https://gateway.seven.io/api/",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
"X-API-Key": notification.sevenioApiKey,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
try {
|
||||||
|
// testing or certificate expiry notification
|
||||||
|
if (heartbeatJSON == null) {
|
||||||
|
await axios.post("sms", data, config);
|
||||||
|
return okMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
let address = "";
|
||||||
|
|
||||||
|
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"])) {
|
||||||
|
address = monitorJSON["url"];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (address !== "") {
|
||||||
|
address = `(${address}) `;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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, config);
|
||||||
|
return okMsg;
|
||||||
|
} catch (error) {
|
||||||
|
this.throwGeneralAxiosError(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = SevenIO;
|
@ -0,0 +1,31 @@
|
|||||||
|
<template>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="sevenio-api-key" class="form-label">{{ $t("apiKeySevenIO") }}</label>
|
||||||
|
<HiddenInput id="sevenio-api-key" v-model="$parent.notification.sevenioApiKey" :required="true" autocomplete="new-password"></HiddenInput>
|
||||||
|
<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>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import HiddenInput from "../HiddenInput.vue";
|
||||||
|
export default {
|
||||||
|
components: {
|
||||||
|
HiddenInput,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
</script>
|
Loading…
Reference in new issue