mirror of https://github.com/louislam/uptime-kuma
yzj notification provider
parent
d493a0171e
commit
efbfc11c39
|
@ -0,0 +1,73 @@
|
|||
const NotificationProvider = require("./notification-provider");
|
||||
const {DOWN, UP} = require("../../src/util");
|
||||
const {default: axios} = require("axios");
|
||||
|
||||
class YZJ extends NotificationProvider {
|
||||
name = "YZJ";
|
||||
|
||||
async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {
|
||||
let okMsg = "Sent Successfully.";
|
||||
|
||||
try {
|
||||
if (heartbeatJSON != null) {
|
||||
let params = {
|
||||
content: `${this.statusToString(heartbeatJSON["status"])} ${monitorJSON["name"]} \n> ${heartbeatJSON["msg"]}\n> Time (${heartbeatJSON["timezone"]}): ${heartbeatJSON["localDateTime"]}`
|
||||
};
|
||||
if (await this.sendToYZJ(notification, params)) {
|
||||
return okMsg;
|
||||
}
|
||||
} else {
|
||||
let params = {
|
||||
content: msg
|
||||
};
|
||||
if (await this.sendToYZJ(notification, params)) {
|
||||
return okMsg;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send message to YZJ
|
||||
* @param {BeanModel} notification
|
||||
* @param {Object} params Parameters of message
|
||||
* @returns {boolean} True if successful else false
|
||||
*/
|
||||
async sendToYZJ(notification, params) {
|
||||
|
||||
let config = {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
url: `${notification.yzjWebHookUrl}?yzjtype=${notification.yzjType}&yzjtoken=${notification.yzjToken}`,
|
||||
data: JSON.stringify(params),
|
||||
};
|
||||
|
||||
let result = await axios(config);
|
||||
if (result.data.success === true) {
|
||||
return true;
|
||||
}
|
||||
throw new Error(result.data.errmsg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert status constant to string
|
||||
* @param {string} status The status constant
|
||||
* @returns {string}
|
||||
*/
|
||||
statusToString(status) {
|
||||
switch (status) {
|
||||
case DOWN:
|
||||
return "❌";
|
||||
case UP:
|
||||
return "✅";
|
||||
default:
|
||||
return status;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = YZJ;
|
|
@ -69,6 +69,7 @@ const Cellsynt = require("./notification-providers/cellsynt");
|
|||
const Onesender = require("./notification-providers/onesender");
|
||||
const Wpush = require("./notification-providers/wpush");
|
||||
const SendGrid = require("./notification-providers/send-grid");
|
||||
const YZJ = require("./notification-providers/yzj");
|
||||
|
||||
class Notification {
|
||||
|
||||
|
@ -154,7 +155,8 @@ class Notification {
|
|||
new GtxMessaging(),
|
||||
new Cellsynt(),
|
||||
new Wpush(),
|
||||
new SendGrid()
|
||||
new SendGrid(),
|
||||
new YZJ()
|
||||
];
|
||||
for (let item of list) {
|
||||
if (! item.name) {
|
||||
|
|
|
@ -183,6 +183,7 @@ export default {
|
|||
"ServerChan": "ServerChan (Server酱)",
|
||||
"smsc": "SMSC",
|
||||
"WPush": "WPush(wpush.cn)",
|
||||
"YZJ": "YZJ(云之家群里机器人)"
|
||||
};
|
||||
|
||||
// Sort by notification name
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<template>
|
||||
<div class="mb-3">
|
||||
<label for="yzjWebHookUrl" class="form-label">{{ $t("YZJ Webhook URL") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||
<input id="yzjWebHookUrl" v-model="$parent.notification.yzjWebHookUrl" type="text" class="form-control"
|
||||
required>
|
||||
|
||||
<label for="yzjType" class="form-label">{{ $t("YZJ Robot Type") }}<span style="color: red;"><sup>*</sup></span></label>
|
||||
<input id="yzjType" v-model="$parent.notification.yzjType" type="text" class="form-control" required>
|
||||
|
||||
<label for="yzjToken" class="form-label">{{ $t("YZJ Robot Token") }}<span
|
||||
style="color: red;"><sup>*</sup></span></label>
|
||||
<hidden-input id="yzjToken" v-model="$parent.notification.yzjToken" type="text" class="form-control" required />
|
||||
|
||||
<i18n-t class="form-text" keypath="wayToGetTeamsURL">
|
||||
<a
|
||||
href="https://www.yunzhijia.com/opendocs/docs.html#/tutorial/index/robot" target="_blank">
|
||||
{{ $t("here") }}
|
||||
</a>
|
||||
</i18n-t>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import HiddenInput from "../HiddenInput.vue";
|
||||
</script>
|
|
@ -67,6 +67,7 @@ import Cellsynt from "./Cellsynt.vue";
|
|||
import WPush from "./WPush.vue";
|
||||
import SIGNL4 from "./SIGNL4.vue";
|
||||
import SendGrid from "./SendGrid.vue";
|
||||
import YZJ from "./YZJ.vue";
|
||||
|
||||
/**
|
||||
* Manage all notification form.
|
||||
|
@ -142,6 +143,7 @@ const NotificationFormList = {
|
|||
"Cellsynt": Cellsynt,
|
||||
"WPush": WPush,
|
||||
"SendGrid": SendGrid,
|
||||
"YZJ": YZJ,
|
||||
};
|
||||
|
||||
export default NotificationFormList;
|
||||
|
|
|
@ -1051,5 +1051,9 @@
|
|||
"RabbitMQ Password": "RabbitMQ Password",
|
||||
"rabbitmqHelpText": "To use the monitor, you will need to enable the Management Plugin in your RabbitMQ setup. For more information, please consult the {rabitmq_documentation}.",
|
||||
"SendGrid API Key": "SendGrid API Key",
|
||||
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas"
|
||||
"Separate multiple email addresses with commas": "Separate multiple email addresses with commas",
|
||||
"YZJ": "YZJ",
|
||||
"YZJ Webhook URL": "YZJ Webhook URL",
|
||||
"YZJ Robot Type": "YZJ Robot type",
|
||||
"YZJ Robot Token": "YZJ Robot token"
|
||||
}
|
||||
|
|
|
@ -1100,5 +1100,9 @@
|
|||
"RabbitMQ Nodes": "RabbitMQ 管理节点",
|
||||
"Separate multiple email addresses with commas": "用逗号分隔多个电子邮件地址",
|
||||
"rabbitmqHelpText": "要使用此监控项,您需要在 RabbitMQ 设置中启用管理插件。有关更多信息,请参阅 {rabitmq_documentation}。",
|
||||
"aboutSlackUsername": "更改消息发件人的显示名称。如果您想提及某人,请另行将其包含在友好名称中。"
|
||||
"aboutSlackUsername": "更改消息发件人的显示名称。如果您想提及某人,请另行将其包含在友好名称中。",
|
||||
"YZJ": "YZJ",
|
||||
"YZJ Webhook URL": "YZJ Webhook 网址",
|
||||
"YZJ Robot Type": "YZJ 机器人类型",
|
||||
"YZJ Robot Token": "YZJ 机器人访问秘钥"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue