Merge pull request #992 from jlbrt/stackfield-notifications

Add support for Stackfield notifications
This commit is contained in:
Louis Lam 2021-12-05 16:45:30 +08:00 committed by GitHub
commit b4507f9706
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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 Bark = require("./notification-providers/bark");
const SerwerSMS = require("./notification-providers/serwersms");
const Stackfield = require("./notification-providers/stackfield");
class Notification {
@ -60,6 +61,7 @@ class Notification {
new Webhook(),
new Bark(),
new SerwerSMS(),
new Stackfield(),
];
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 Bark from "./Bark.vue";
import SerwerSMS from "./SerwerSMS.vue";
import Stackfield from './Stackfield.vue';
/**
* Manage all notification form.
@ -55,6 +56,7 @@ const NotificationFormList = {
"DingDing": DingDing,
"Bark": Bark,
"serwersms": SerwerSMS,
"stackfield": Stackfield,
}
export default NotificationFormList

View file

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