zoho cliq notification provider

This commit is contained in:
panos 2022-12-08 13:32:10 +02:00
parent ecbc0f0477
commit 73bfdb9ef9
7 changed files with 147 additions and 0 deletions

View file

@ -0,0 +1,119 @@
const NotificationProvider = require("./notification-provider");
const axios = require("axios");
const {DOWN, UP} = require("../../src/util");
class ZohoCliq extends NotificationProvider {
name = "ZohoCliq";
/**
* Generate the message to send
* @param {const} status The status constant
* @param {string} monitorName Name of monitor
* @returns {string}
*/
_statusMessageFactory = (status, monitorName) => {
if (status === DOWN) {
return `🔴 Application [${monitorName}] went down\n`;
} else if (status === UP) {
return `✅ Application [${monitorName}] is back online\n`;
}
return "Notification\n";
};
/**
* Send the notification
* @param {string} webhookUrl URL to send the request to
* @param {Array} payload Payload generated by _notificationPayloadFactory
*/
_sendNotification = async(webhookUrl, payload) => {
await axios.post(webhookUrl, {text: payload.join("\n")});
};
/**
* Generate payload for notification
* @param {const} status The status of the monitor
* @param {string} monitorMessage Message to send
* @param {string} monitorName Name of monitor affected
* @param {string} monitorUrl URL of monitor affected
* @returns {Array}
*/
_notificationPayloadFactory = ({
status,
monitorMessage,
monitorName,
monitorUrl,
}) => {
const payload = ["### Uptime Kuma\n"];
payload.push(this._statusMessageFactory(status, monitorName));
payload.push(`*Description:* ${monitorMessage}`);
if (monitorName) {
payload.push(`*Monitor:* ${monitorName}`);
}
if (monitorUrl && monitorUrl !== "https://") {
payload.push(`*URL:* [${monitorUrl}](${monitorUrl})`);
}
return payload;
};
/**
* Send a general notification
* @param {string} webhookUrl URL to send request to
* @param {string} msg Message to send
* @returns {Promise<void>}
*/
_handleGeneralNotification = (webhookUrl, msg) => {
const payload = this._notificationPayloadFactory({
monitorMessage: msg
});
return this._sendNotification(webhookUrl, payload);
};
_monitorUrlFactory = (monitorJSON) => {
let url;
switch(monitorJSON["type"]) {
case "http":
case "keywork":
url = monitorJSON["url"];
break;
case "docker":
url = monitorJSON["docker_host"];
break;
default:
url = monitorJSON["hostname"];
break;
}
return url;
};
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
let okMsg = "Sent Successfully.";
try {
if (heartbeatJSON == null) {
await this._handleGeneralNotification(notification.webhookUrl, msg);
return okMsg;
}
const payload = this._notificationPayloadFactory({
monitorMessage: heartbeatJSON.msg,
monitorName: monitorJSON.name,
monitorUrl: this._monitorUrlFactory(monitorJSON),
status: heartbeatJSON.status,
});
await this._sendNotification(notification.webhookUrl, payload);
return okMsg;
} catch(error) {
this.throwGeneralAxiosError(error);
}
}
}
module.exports = ZohoCliq;

View file

@ -44,6 +44,7 @@ const WeCom = require("./notification-providers/wecom");
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");
class Notification {
@ -100,6 +101,7 @@ class Notification {
new Webhook(),
new WeCom(),
new GoAlert(),
new ZohoCliq()
];
for (let item of list) {

View file

@ -0,0 +1,18 @@
<template>
<div class="mb-3">
<label for="zcliq-webhookurl" class="form-label">{{ $t("Webhook URL") }}</label>
<input
id="zcliq-webhookurl"
v-model="$parent.notification.webhookUrl"
type="text"
class="form-control"
required
/>
<i18n-t tag="div" keypath="wayToGetZohoCliqURL" class="form-text">
<a
href="https://www.zoho.com/cliq/help/platform/webhook-tokens.html"
target="_blank"
>{{ $t("here") }}</a>
</i18n-t>
</div>
</template>

View file

@ -42,6 +42,7 @@ import Telegram from "./Telegram.vue";
import Webhook from "./Webhook.vue";
import WeCom from "./WeCom.vue";
import GoAlert from "./GoAlert.vue";
import ZohoCliq from "./ZohoCliq.vue";
/**
* Manage all notification form.
@ -93,6 +94,7 @@ const NotificationFormList = {
"WeCom": WeCom,
"GoAlert": GoAlert,
"ServerChan": ServerChan,
"ZohoCliq": ZohoCliq
};
export default NotificationFormList;

View file

@ -194,6 +194,7 @@ export default {
here: "εδώ",
Required: "Απαιτείται",
telegram: "Telegram",
"ZohoCliq": "ZohoCliq",
"Bot Token": "Διακριτικό Bot",
wayToGetTelegramToken: "Μπορείτε να πάρετε ένα διακριτικό από {0}.",
"Chat ID": "Chat ID",
@ -224,6 +225,7 @@ export default {
teams: "Microsoft Teams",
"Webhook URL": "Webhook URL",
wayToGetTeamsURL: "Μπορείτε να μάθετε πώς να δημιουργείτε μια διεύθυνση URL webhook {0}.",
wayToGetZohoCliqURL: "Μπορείτε να μάθετε πώς να δημιουργείτε μια διεύθυνση URL webhook {0}.",
signal: "Signal",
Number: "Αριθμός",
Recipients: "Αποδέκτες",

View file

@ -209,6 +209,7 @@ export default {
here: "here",
Required: "Required",
telegram: "Telegram",
"ZohoCliq": "ZohoCliq",
"Bot Token": "Bot Token",
wayToGetTelegramToken: "You can get a token from {0}.",
"Chat ID": "Chat ID",
@ -241,6 +242,7 @@ export default {
teams: "Microsoft Teams",
"Webhook URL": "Webhook URL",
wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.",
wayToGetZohoCliqURL: "You can learn how to create a webhook URL {0}.",
signal: "Signal",
Number: "Number",
Recipients: "Recipients",

View file

@ -191,6 +191,7 @@ export default {
here: "Hemen",
Required: "Beharrezkoa",
telegram: "Telegram",
"ZohoCliq": "ZohoCliq",
"Bot Token": "Bot Tokena",
wayToGetTelegramToken: "You can get a token from {0}.",
"Chat ID": "Txat IDa",
@ -221,6 +222,7 @@ export default {
teams: "Microsoft Teams",
"Webhook URL": "Webhook URL",
wayToGetTeamsURL: "You can learn how to create a webhook URL {0}.",
wayToGetZohoCliqURL: "You can learn how to create a webhook URL {0}.",
signal: "Signal",
Number: "Zenbakia",
Recipients: "Recipients",