mirror of
https://github.com/louislam/uptime-kuma.git
synced 2024-11-27 16:54:04 +00:00
Compare commits
4 commits
d939c20501
...
103da39cb5
Author | SHA1 | Date | |
---|---|---|---|
|
103da39cb5 | ||
|
6899603eb7 | ||
|
fafa1a78ee | ||
|
c70ec1ea50 |
2 changed files with 73 additions and 17 deletions
|
@ -12,13 +12,16 @@ class WeCom extends NotificationProvider {
|
|||
const okMsg = "Sent Successfully.";
|
||||
|
||||
try {
|
||||
let WeComUrl =
|
||||
"https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=" +
|
||||
notification.weComBotKey;
|
||||
let config = {
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
}
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
};
|
||||
let body = this.composeMessage(heartbeatJSON, msg);
|
||||
await axios.post(`https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=${notification.weComBotKey}`, body, config);
|
||||
let body = this.composeMessage(heartbeatJSON, monitorJSON, msg);
|
||||
await axios.post(WeComUrl, body, config);
|
||||
return okMsg;
|
||||
} catch (error) {
|
||||
this.throwGeneralAxiosError(error);
|
||||
|
@ -28,24 +31,77 @@ class WeCom extends NotificationProvider {
|
|||
/**
|
||||
* Generate the message to send
|
||||
* @param {object} heartbeatJSON Heartbeat details (For Up/Down only)
|
||||
* @param {object} monitorJSON Monitor details
|
||||
* @param {string} msg General message
|
||||
* @returns {object} Message
|
||||
*/
|
||||
composeMessage(heartbeatJSON, msg) {
|
||||
let title = "UptimeKuma Message";
|
||||
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === UP) {
|
||||
title = "UptimeKuma Monitor Up";
|
||||
composeMessage(heartbeatJSON, monitorJSON, msg) {
|
||||
const address = this.extractAddress(monitorJSON);
|
||||
if (heartbeatJSON != null) {
|
||||
const templateCard = {
|
||||
card_type: "text_notice",
|
||||
main_title: {
|
||||
title: this.statusToString(
|
||||
heartbeatJSON["status"],
|
||||
monitorJSON["name"]
|
||||
),
|
||||
},
|
||||
sub_title_text: heartbeatJSON["msg"],
|
||||
horizontal_content_list: [
|
||||
{
|
||||
keyname: "Timezone",
|
||||
value: heartbeatJSON["timezone"],
|
||||
},
|
||||
{
|
||||
keyname: "Time",
|
||||
value: heartbeatJSON["localDateTime"],
|
||||
},
|
||||
],
|
||||
card_action: {
|
||||
type: 1,
|
||||
url: address
|
||||
? address
|
||||
: "https://github.com/louislam/uptime-kuma", // both card_action and card_action.url are mandatory
|
||||
},
|
||||
};
|
||||
if (address) {
|
||||
templateCard["jump_list"] = [
|
||||
{
|
||||
type: 1,
|
||||
url: address,
|
||||
title: "Monitor URL",
|
||||
},
|
||||
];
|
||||
}
|
||||
if (msg != null && heartbeatJSON != null && heartbeatJSON["status"] === DOWN) {
|
||||
title = "UptimeKuma Monitor Down";
|
||||
return {
|
||||
msgtype: "template_card",
|
||||
template_card: templateCard,
|
||||
};
|
||||
}
|
||||
return {
|
||||
msgtype: "text",
|
||||
text: {
|
||||
content: title + "\n" + msg
|
||||
}
|
||||
content: msg,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert status constant to string
|
||||
* @param {const} status The status constant
|
||||
* @param {string} monitorName Name of monitor
|
||||
* @returns {string} Status
|
||||
*/
|
||||
statusToString(status, monitorName) {
|
||||
switch (status) {
|
||||
case DOWN:
|
||||
return `🔴 [${monitorName}] DOWN`;
|
||||
case UP:
|
||||
return `✅ [${monitorName}] UP`;
|
||||
default:
|
||||
return "Notification";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = WeCom;
|
||||
|
|
|
@ -5,20 +5,20 @@
|
|||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="sendgrid-from-email" class="form-label">{{ $t("From Email") }}</label>
|
||||
<input id="sendgrid-from-email" v-model="$parent.notification.sendgridFromEmail" type="email" class="form-control" required>
|
||||
<input id="sendgrid-from-email" v-model="$parent.notification.sendgridFromEmail" type="text" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="sendgrid-to-email" class="form-label">{{ $t("To Email") }}</label>
|
||||
<input id="sendgrid-to-email" v-model="$parent.notification.sendgridToEmail" type="email" class="form-control" required>
|
||||
<input id="sendgrid-to-email" v-model="$parent.notification.sendgridToEmail" type="text" class="form-control" required>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="sendgrid-cc-email" class="form-label">{{ $t("smtpCC") }}</label>
|
||||
<input id="sendgrid-cc-email" v-model="$parent.notification.sendgridCcEmail" type="email" class="form-control">
|
||||
<input id="sendgrid-cc-email" v-model="$parent.notification.sendgridCcEmail" type="text" class="form-control">
|
||||
<div class="form-text">{{ $t("Separate multiple email addresses with commas") }}</div>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
<label for="sendgrid-bcc-email" class="form-label">{{ $t("smtpBCC") }}</label>
|
||||
<input id="sendgrid-bcc-email" v-model="$parent.notification.sendgridBccEmail" type="email" class="form-control">
|
||||
<input id="sendgrid-bcc-email" v-model="$parent.notification.sendgridBccEmail" type="text" class="form-control">
|
||||
<small class="form-text text-muted">{{ $t("Separate multiple email addresses with commas") }}</small>
|
||||
</div>
|
||||
<div class="mb-3">
|
||||
|
|
Loading…
Reference in a new issue