Browse Source

(*)推送[通知]到前端

dev
wuqun 2 years ago
parent
commit
7dbdb88bed
  1. 28
      api/app/lib/schedule/alarms_push.js
  2. 25
      api/app/lib/utils/alarmHandle.js
  3. 2
      web/client/src/sections/control/containers/control.jsx

28
api/app/lib/schedule/alarms_push.js

@ -12,7 +12,7 @@ module.exports = function (app, opts) {
const { models, ORM: sequelize } = app.fs.dc
const { clickHouse } = app.fs
const { database: anxinyun } = clickHouse.anxinyun.opts.config
const { pushBySms, pushByEmail } = app.fs.utils
const { pushBySms, pushByEmail, sendNoticeToWeb } = app.fs.utils
const curMinOfYear = moment().diff(moment().startOf('year'), 'minutes')
const configListRes = await models.AlarmPushConfig.findAll({
where: {
@ -674,14 +674,14 @@ module.exports = function (app, opts) {
const receiverRes =
c.receiverPepUserId.length ?
await clickHouse.pepEmis.query(`
SELECT id, email FROM user WHERE id IN (${c.receiverPepUserId.join(',')},-1)
SELECT id, name, email FROM user WHERE id IN (${c.receiverPepUserId.join(',')},-1)
`).toPromise()
: []
let receiverId = []
const emails = receiverRes.reduce((arr, r) => {
if (r.email) {
arr.push(r.email)
receiverId.push(r.id)
receiverId.push({ id: r.id, name: r.name })
}
return arr
}, [])
@ -692,14 +692,30 @@ module.exports = function (app, opts) {
text: '',
html: html
})
await models.EmailSendLog.create({
//存日志 存动态 socket到前端
let dataToSave = {
time: moment().format(),
pushConfigId: c.id,
cfgName: c.name,//策略名称
tactics: c.tactics,
tacticsParams: c.tacticsParams,
projectCorrelationId: pomsProjectId,
toPepUserIds: receiverId
})
toPepUserIds: receiverId.map(r => r.id)
}
let r = await models.EmailSendLog.create(dataToSave, { returning: true })
let dynamic = {
time: r.dataValues.time,
emailSendId: r.dataValues.id,
projectCorrelationId: r.dataValues.projectCorrelationId,
type: 2//通知
}
await models.LatestDynamicList.create(dynamic);
//消息推送到前端
await sendNoticeToWeb(receiverId, dataToSave);
}
}
}

25
api/app/lib/utils/alarmHandle.js

@ -102,8 +102,31 @@ module.exports = function (app, opts) {
}
}
async function sendNoticeToWeb(pepUsers, data) {
try {
let { cfgName, tactics, tacticsParams, projectCorrelationId, time } = data;
//项目信息
let { projects, pepProjects } = await getProjectsInfo([data]);
let pepPId = projects.find(p => p.id == projectCorrelationId).pepProjectId;
//需要 策略名称 处理人 项目 策略和参数 时间
let sendData = {
pushConfig: { cfgName, tactics, tacticsParams },//策略信息
pepUsers,
projectCorrelationId: projectCorrelationId,
project: projects.find(p => p.id == projectCorrelationId).name || pepProjects.find(pp => pp.id == pepPId).project_name,//前者为自定义项目名称
time
}
app.socket.emit('alarmSendSocket', { type: 'alarmNotice', sendData })
} catch (err) {
console.log(`推送通知失败, error: ${err}`);
}
}
return {
sendAppearToWeb,//推送告警发现
sendConfirmToWeb//推送告警确认
sendConfirmToWeb,//推送告警确认
sendNoticeToWeb//推送通知
}
}

2
web/client/src/sections/control/containers/control.jsx

@ -57,6 +57,8 @@ const Control = (props) => {
} else if (msg.type == "alarmConfirm") {//
} else if (msg.type == "alarmNotice") {//
}
});
return () => {

Loading…
Cancel
Save