add support for stackfield notifications

This commit is contained in:
Jonas Liebert 2021-12-02 08:53:45 +01:00
parent ee79a34148
commit 67849a9e84
5 changed files with 59 additions and 0 deletions

View File

@ -0,0 +1,41 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const { setting } = require("../util-server");
const { getMonitorRelativeURL } = require("../../src/util");
class Stackfield extends NotificationProvider {
name = "stackfield";
async send(notification, msg, monitorJSON = null) {
let okMsg = "Sent Successfully.";
try {
// Stackfield message formatting: https://www.stackfield.com/help/formatting-messages-2001
let textMsg = "+Uptime Kuma Alert+";
if (monitorJSON && monitorJSON.name) {
textMsg += `\n*${monitorJSON.name}*`;
}
textMsg += `\n${msg}`;
const baseURL = await setting("primaryBaseURL");
if (baseURL) {
textMsg += `\n${baseURL + getMonitorRelativeURL(monitorJSON.id)}`;
}
const data = {
"Title": textMsg,
};
await axios.post(notification.stackfieldwebhookURL, data);
return okMsg;
} catch (error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = Stackfield;

View File

@ -24,6 +24,7 @@ const AliyunSms = require("./notification-providers/aliyun-sms");
const DingDing = require("./notification-providers/dingding"); const DingDing = require("./notification-providers/dingding");
const Bark = require("./notification-providers/bark"); const Bark = require("./notification-providers/bark");
const SerwerSMS = require("./notification-providers/serwersms"); const SerwerSMS = require("./notification-providers/serwersms");
const Stackfield = require("./notification-providers/stackfield");
class Notification { class Notification {
@ -60,6 +61,7 @@ class Notification {
new Webhook(), new Webhook(),
new Bark(), new Bark(),
new SerwerSMS(), new SerwerSMS(),
new Stackfield(),
]; ];
for (let item of list) { for (let item of list) {

View File

@ -0,0 +1,13 @@
<template>
<div class="mb-3">
<label for="stackfield-webhook-url" class="form-label">{{ $t("Webhook URL") }}<span style="color: red;"><sup>*</sup></span></label>
<input id="stackfield-webhook-url" v-model="$parent.notification.stackfieldwebhookURL" 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://www.stackfield.com/developer-api#AnchorAPI2" target="_blank">https://www.stackfield.com/developer-api#AnchorAPI2</a>
</i18n-t>
</div>
</div>
</template>

View File

@ -23,6 +23,7 @@ import AliyunSMS from "./AliyunSms.vue";
import DingDing from "./DingDing.vue"; import DingDing from "./DingDing.vue";
import Bark from "./Bark.vue"; import Bark from "./Bark.vue";
import SerwerSMS from "./SerwerSMS.vue"; import SerwerSMS from "./SerwerSMS.vue";
import Stackfield from './Stackfield.vue';
/** /**
* Manage all notification form. * Manage all notification form.
@ -55,6 +56,7 @@ const NotificationFormList = {
"DingDing": DingDing, "DingDing": DingDing,
"Bark": Bark, "Bark": Bark,
"serwersms": SerwerSMS, "serwersms": SerwerSMS,
"stackfield": Stackfield,
} }
export default NotificationFormList export default NotificationFormList

View File

@ -351,4 +351,5 @@ export default {
serwersmsAPIPassword: "API Password", serwersmsAPIPassword: "API Password",
serwersmsPhoneNumber: "Phone number", serwersmsPhoneNumber: "Phone number",
serwersmsSenderName: "SMS Sender Name (registered via customer portal)", serwersmsSenderName: "SMS Sender Name (registered via customer portal)",
"stackfield": "Stackfield",
}; };