Skip to content

Commit 430821e

Browse files
committed
警报问题修复
1 parent 24807fc commit 430821e

File tree

2 files changed

+61
-55
lines changed

2 files changed

+61
-55
lines changed

alarm/index.js

Lines changed: 60 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,61 @@
11
const sendEmail = require('../util_cus/sendEmail');
2-
const dingDing = require('../alarm/dingding')
3-
const weiXin = require('../alarm/weixin')
4-
const feiSHu = require('../alarm/feishu')
5-
const Utils = require('../util/utils')
6-
const AccountConfig = require('../config/AccountConfig')
7-
const { accountInfo } = AccountConfig
8-
const AlarmNames = require('./alarmName')
9-
10-
const alarmCallback = (project, rule, users) => {
11-
const { projectName, projectType, chooseHook } = project
12-
const {type, happenCount, compareType, limitValue} = rule
13-
const compareStr = compareType === "up" ? ">=" : "<"
14-
const projectHook = chooseHook ? JSON.parse(chooseHook) : {value: "", name: "", webHook: ""}
15-
/**生成警报配置 */
16-
// 添加用户手机号
17-
users.forEach((user) => {
18-
dingDing.config.at.atMobiles.push(user.phone)
19-
weiXin.config.text.mentioned_mobile_list.push(user.phone)
20-
})
21-
// 生成警报内容
22-
const contentStr = type + "警报!" +
23-
"您的" + projectType + "项目【" + projectName + "】发出警报:" +
24-
type + "数量 " + compareStr + " " + limitValue + " 已经发生" + happenCount + "次了,请及时处理。"
25-
dingDing.config.text.content = contentStr
26-
weiXin.config.text.content = contentStr
27-
feiSHu.config.content.text = contentStr
28-
switch(projectHook.value) {
29-
case "dingding":
30-
// 1. 通知钉钉机器人
31-
Utils.postJson(projectHook.webHook, dingDing.config) // 钉钉机器人
32-
break
33-
case "weixin":
34-
// 2. 通知微信机器人
35-
Utils.postJson(projectHook.webHook, weiXin.config) // 微信机器人
36-
break
37-
case "feishu":
38-
// 3. 通知飞书机器人
39-
Utils.postJson(projectHook.webHook, feiSHu.config) // 飞书机器人
40-
break
41-
default:
42-
break
43-
}
44-
45-
// 4. 发送邮件通知
46-
if (users && users.length && accountInfo.emailUser && accountInfo.emailPassword) {
47-
users.forEach((user) => {
48-
const email = user.emailName
49-
sendEmail(email, AlarmNames[type] + "警报!", contentStr, accountInfo.emailUser, accountInfo.emailPassword)
50-
})
51-
}
52-
}
53-
module.exports = {
54-
alarmCallback
55-
}
2+
const dingDing = require('../alarm/dingding')
3+
const weiXin = require('../alarm/weixin')
4+
const feiSHu = require('../alarm/feishu')
5+
const Utils = require('../util/utils')
6+
const AccountConfig = require('../config/AccountConfig')
7+
const { accountInfo } = AccountConfig
8+
const AlarmNames = require('./alarmName')
9+
10+
const alarmCallback = (project, rule, users) => {
11+
const { projectName, projectType, chooseHook } = project
12+
const {type, happenCount, compareType, limitValue} = rule
13+
const compareStr = compareType === "up" ? ">=" : "<"
14+
const projectHook = JSON.parse(chooseHook)
15+
/**生成警报配置 */
16+
// 添加用户手机号
17+
users.forEach((user) => {
18+
const dingMobiles = dingDing.config.at.atMobiles
19+
const weiXinMobiles = weiXin.config.text.mentioned_mobile_list
20+
if (dingMobiles.indexOf(user.phone) === -1) {
21+
dingMobiles.push(user.phone)
22+
}
23+
if (weiXinMobiles.indexOf(user.phone) === -1) {
24+
weiXinMobiles.push(user.phone)
25+
}
26+
// dingDing.config.at.atMobiles.push(user.phone)
27+
// weiXin.config.text.mentioned_mobile_list.push(user.phone)
28+
})
29+
// 生成警报内容
30+
const contentStr = type + "警报!" +
31+
"您的" + projectType + "项目【" + projectName + "】发出警报:" +
32+
type + "数量 " + compareStr + " " + limitValue + " 已经发生" + happenCount + "次了,请及时处理。"
33+
dingDing.config.text.content = contentStr
34+
weiXin.config.text.content = contentStr
35+
feiSHu.config.content.text = contentStr
36+
switch(projectHook.value) {
37+
case "dingding":
38+
// 1. 通知钉钉机器人
39+
Utils.postJson(projectHook.webHook, dingDing.config) // 钉钉机器人
40+
break
41+
case "weixin":
42+
// 2. 通知微信机器人
43+
Utils.postJson(projectHook.webHook, weiXin.config) // 微信机器人
44+
break
45+
case "feishu":
46+
// 3. 通知飞书机器人
47+
Utils.postJson(projectHook.webHook, feiSHu.config) // 飞书机器人
48+
break
49+
}
50+
51+
// 4. 发送邮件通知
52+
if (users && users.length && accountInfo.emailUser && accountInfo.emailPassword) {
53+
users.forEach((user) => {
54+
const email = user.emailName
55+
sendEmail(email, AlarmNames[type] + "警报!", contentStr, accountInfo.emailUser, accountInfo.emailPassword)
56+
})
57+
}
58+
}
59+
module.exports = {
60+
alarmCallback
61+
}

controllers/controllers.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)