Skip to content

Commit

Permalink
警报问题修复
Browse files Browse the repository at this point in the history
  • Loading branch information
a826604005 committed Mar 26, 2022
1 parent 24807fc commit 430821e
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 55 deletions.
114 changes: 60 additions & 54 deletions alarm/index.js
Original file line number Diff line number Diff line change
@@ -1,55 +1,61 @@
const sendEmail = require('../util_cus/sendEmail');
const dingDing = require('../alarm/dingding')
const weiXin = require('../alarm/weixin')
const feiSHu = require('../alarm/feishu')
const Utils = require('../util/utils')
const AccountConfig = require('../config/AccountConfig')
const { accountInfo } = AccountConfig
const AlarmNames = require('./alarmName')

const alarmCallback = (project, rule, users) => {
const { projectName, projectType, chooseHook } = project
const {type, happenCount, compareType, limitValue} = rule
const compareStr = compareType === "up" ? ">=" : "<"
const projectHook = chooseHook ? JSON.parse(chooseHook) : {value: "", name: "", webHook: ""}
/**生成警报配置 */
// 添加用户手机号
users.forEach((user) => {
dingDing.config.at.atMobiles.push(user.phone)
weiXin.config.text.mentioned_mobile_list.push(user.phone)
})
// 生成警报内容
const contentStr = type + "警报!" +
"您的" + projectType + "项目【" + projectName + "】发出警报:" +
type + "数量 " + compareStr + " " + limitValue + " 已经发生" + happenCount + "次了,请及时处理。"
dingDing.config.text.content = contentStr
weiXin.config.text.content = contentStr
feiSHu.config.content.text = contentStr
switch(projectHook.value) {
case "dingding":
// 1. 通知钉钉机器人
Utils.postJson(projectHook.webHook, dingDing.config) // 钉钉机器人
break
case "weixin":
// 2. 通知微信机器人
Utils.postJson(projectHook.webHook, weiXin.config) // 微信机器人
break
case "feishu":
// 3. 通知飞书机器人
Utils.postJson(projectHook.webHook, feiSHu.config) // 飞书机器人
break
default:
break
}

// 4. 发送邮件通知
if (users && users.length && accountInfo.emailUser && accountInfo.emailPassword) {
users.forEach((user) => {
const email = user.emailName
sendEmail(email, AlarmNames[type] + "警报!", contentStr, accountInfo.emailUser, accountInfo.emailPassword)
})
}
}
module.exports = {
alarmCallback
}
const dingDing = require('../alarm/dingding')
const weiXin = require('../alarm/weixin')
const feiSHu = require('../alarm/feishu')
const Utils = require('../util/utils')
const AccountConfig = require('../config/AccountConfig')
const { accountInfo } = AccountConfig
const AlarmNames = require('./alarmName')

const alarmCallback = (project, rule, users) => {
const { projectName, projectType, chooseHook } = project
const {type, happenCount, compareType, limitValue} = rule
const compareStr = compareType === "up" ? ">=" : "<"
const projectHook = JSON.parse(chooseHook)
/**生成警报配置 */
// 添加用户手机号
users.forEach((user) => {
const dingMobiles = dingDing.config.at.atMobiles
const weiXinMobiles = weiXin.config.text.mentioned_mobile_list
if (dingMobiles.indexOf(user.phone) === -1) {
dingMobiles.push(user.phone)
}
if (weiXinMobiles.indexOf(user.phone) === -1) {
weiXinMobiles.push(user.phone)
}
// dingDing.config.at.atMobiles.push(user.phone)
// weiXin.config.text.mentioned_mobile_list.push(user.phone)
})
// 生成警报内容
const contentStr = type + "警报!" +
"您的" + projectType + "项目【" + projectName + "】发出警报:" +
type + "数量 " + compareStr + " " + limitValue + " 已经发生" + happenCount + "次了,请及时处理。"
dingDing.config.text.content = contentStr
weiXin.config.text.content = contentStr
feiSHu.config.content.text = contentStr
switch(projectHook.value) {
case "dingding":
// 1. 通知钉钉机器人
Utils.postJson(projectHook.webHook, dingDing.config) // 钉钉机器人
break
case "weixin":
// 2. 通知微信机器人
Utils.postJson(projectHook.webHook, weiXin.config) // 微信机器人
break
case "feishu":
// 3. 通知飞书机器人
Utils.postJson(projectHook.webHook, feiSHu.config) // 飞书机器人
break
}

// 4. 发送邮件通知
if (users && users.length && accountInfo.emailUser && accountInfo.emailPassword) {
users.forEach((user) => {
const email = user.emailName
sendEmail(email, AlarmNames[type] + "警报!", contentStr, accountInfo.emailUser, accountInfo.emailPassword)
})
}
}
module.exports = {
alarmCallback
}
2 changes: 1 addition & 1 deletion controllers/controllers.js

Large diffs are not rendered by default.

0 comments on commit 430821e

Please sign in to comment.