From 7dbdb88bed4e5cc0bfcea8e8a38862ed2ed0cbeb Mon Sep 17 00:00:00 2001 From: wuqun Date: Wed, 2 Nov 2022 10:37:58 +0800 Subject: [PATCH] =?UTF-8?q?(*)=E6=8E=A8=E9=80=81[=E9=80=9A=E7=9F=A5]?= =?UTF-8?q?=E5=88=B0=E5=89=8D=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/schedule/alarms_push.js | 28 +++++++++++++++---- api/app/lib/utils/alarmHandle.js | 25 ++++++++++++++++- .../sections/control/containers/control.jsx | 2 ++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/api/app/lib/schedule/alarms_push.js b/api/app/lib/schedule/alarms_push.js index a436aef..c6a1a37 100644 --- a/api/app/lib/schedule/alarms_push.js +++ b/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); } } } diff --git a/api/app/lib/utils/alarmHandle.js b/api/app/lib/utils/alarmHandle.js index 43c311c..c3b8a67 100644 --- a/api/app/lib/utils/alarmHandle.js +++ b/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//推送通知 } } \ No newline at end of file diff --git a/web/client/src/sections/control/containers/control.jsx b/web/client/src/sections/control/containers/control.jsx index 78f4867..b7410c2 100644 --- a/web/client/src/sections/control/containers/control.jsx +++ b/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 () => {