-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf44d39
commit a298561
Showing
7 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
||
const {default: axios} = require("axios"); | ||
Check failure on line 3 in server/notification-providers/yzj.js
|
||
|
||
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 | ||
Check warning on line 34 in server/notification-providers/yzj.js
|
||
* @param {Object} params Parameters of message | ||
Check failure on line 35 in server/notification-providers/yzj.js
|
||
* @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
|
||
*/ | ||
statusToString(status) { | ||
switch (status) { | ||
case DOWN: | ||
return "❌"; | ||
case UP: | ||
return "✅"; | ||
default: | ||
return status; | ||
} | ||
} | ||
} | ||
|
||
module.exports = YZJ; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters