Skip to content

Commit

Permalink
Support YZJ notification provider
Browse files Browse the repository at this point in the history
  • Loading branch information
innerpeacez committed Mar 10, 2025
1 parent cf44d39 commit a298561
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 3 deletions.
73 changes: 73 additions & 0 deletions server/notification-providers/yzj.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
const NotificationProvider = require("./notification-provider");
const {DOWN, UP} = require("../../src/util");

Check failure on line 2 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

A space is required after '{'

Check failure on line 2 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

A space is required before '}'
const {default: axios} = require("axios");

Check failure on line 3 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

A space is required after '{'

Check failure on line 3 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

A space is required before '}'

class YZJ extends NotificationProvider {
name = "YZJ";

async send(notification, msg, monitorJSON = null, heartbeatJSON = null) {

Check failure on line 8 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

Missing JSDoc comment
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

Check warning on line 34 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

Missing JSDoc @param "notification" description
* @param {Object} params Parameters of message

Check failure on line 35 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

Invalid JSDoc @param "params" type "Object"; prefer: "object"
* @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}

Check warning on line 59 in server/notification-providers/yzj.js

View workflow job for this annotation

GitHub Actions / check-linters

Missing JSDoc @returns description
*/
statusToString(status) {
switch (status) {
case DOWN:
return "❌";
case UP:
return "✅";
default:
return status;
}
}
}

module.exports = YZJ;
4 changes: 3 additions & 1 deletion server/notification.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/components/NotificationDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ export default {
"ServerChan": "ServerChan (Server酱)",
"smsc": "SMSC",
"WPush": "WPush(wpush.cn)",
"YZJ": "YZJ(云之家群里机器人)"
};
// Sort by notification name
Expand Down
24 changes: 24 additions & 0 deletions src/components/notifications/YZJ.vue
Original file line number Diff line number Diff line change
@@ -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"

Check warning on line 4 in src/components/notifications/YZJ.vue

View workflow job for this annotation

GitHub Actions / check-linters

Expected a linebreak before this attribute
required>

Check warning on line 5 in src/components/notifications/YZJ.vue

View workflow job for this annotation

GitHub Actions / check-linters

Expected 1 line break before closing bracket, but no line breaks found

<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>

Check warning on line 11 in src/components/notifications/YZJ.vue

View workflow job for this annotation

GitHub Actions / check-linters

Expected 1 line break before closing bracket, but no line breaks found
<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">

Check warning on line 16 in src/components/notifications/YZJ.vue

View workflow job for this annotation

GitHub Actions / check-linters

Expected 1 line break before closing bracket, but no line breaks found
{{ $t("here") }}
</a>
</i18n-t>
</div>
</template>
<script setup lang="ts">
import HiddenInput from "../HiddenInput.vue";
</script>
2 changes: 2 additions & 0 deletions src/components/notifications/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -142,6 +143,7 @@ const NotificationFormList = {
"Cellsynt": Cellsynt,
"WPush": WPush,
"SendGrid": SendGrid,
"YZJ": YZJ,
};

export default NotificationFormList;
6 changes: 5 additions & 1 deletion src/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 5 additions & 1 deletion src/lang/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 机器人访问秘钥"
}

0 comments on commit a298561

Please sign in to comment.