|
|
@ -1,4 +1,5 @@ |
|
|
|
'use strict'; |
|
|
|
const moment = require('moment') |
|
|
|
|
|
|
|
module.exports = function (app, opts) { |
|
|
|
const { models } = app.fs.dc |
|
|
@ -43,7 +44,8 @@ module.exports = function (app, opts) { |
|
|
|
alarmGroup//告警类型
|
|
|
|
}) |
|
|
|
}) |
|
|
|
app.socket.emit('alarmSendSocket', { type: 'alarmAppear', sendData }) |
|
|
|
//app.socket.emit('alarmSendSocket', { type: 'alarmAppear', sendData })
|
|
|
|
await socketThrottle('appear', sendData); |
|
|
|
} catch (err) { |
|
|
|
console.log(`告警(发现)推送失败, error: ${err}`); |
|
|
|
} |
|
|
@ -74,7 +76,8 @@ module.exports = function (app, opts) { |
|
|
|
isAuto//是否为自动恢复,自动恢复时user为null
|
|
|
|
}) |
|
|
|
}) |
|
|
|
app.socket.emit('alarmSendSocket', { type: 'alarmConfirm', sendData })//小飞(处理人) 确认并关闭了A项目(项目) DTU设备(告警源) 状态异常(异常类型)的问题
|
|
|
|
//app.socket.emit('alarmSendSocket', { type: 'alarmConfirm', sendData })//小飞(处理人) 确认并关闭了A项目(项目) DTU设备(告警源) 状态异常(异常类型)的问题
|
|
|
|
await socketThrottle('confirm', sendData); |
|
|
|
} catch (err) { |
|
|
|
console.log(`告警(确认)推送失败, error: ${err}`); |
|
|
|
} |
|
|
@ -110,20 +113,55 @@ module.exports = function (app, opts) { |
|
|
|
let pepPId = projects.find(p => p.id == projectCorrelationId).pepProjectId; |
|
|
|
|
|
|
|
//需要 策略名称 处理人 项目 策略和参数 时间
|
|
|
|
let sendData = { |
|
|
|
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 }) |
|
|
|
//app.socket.emit('alarmSendSocket', { type: 'alarmNotice', sendData })
|
|
|
|
await socketThrottle('notice', sendData); |
|
|
|
} catch (err) { |
|
|
|
console.log(`推送通知失败, error: ${err}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
async function socketThrottle(type, dataList) { |
|
|
|
try { |
|
|
|
if (!msgSendObj.time || moment() > moment(msgSendObj.time).add(1, 'minute')) {//首次 || 跟上次时间间隔大于1分钟 直接发送
|
|
|
|
msgSendObj.dataMap[type] = dataList; |
|
|
|
app.socket.emit('alarmSendSocket', { msgDataMap: msgSendObj.dataMap });//发送到前端
|
|
|
|
|
|
|
|
msgSendObj.time = moment().format();//记录本次发送时间
|
|
|
|
msgSendObj.dataMap = { appear: [], confirm: [], notice: [] } |
|
|
|
msgSendObj.toSend = false |
|
|
|
} else {//放进队列
|
|
|
|
msgSendObj.dataMap[type] = msgSendObj.dataMap[type].concat(dataList); |
|
|
|
msgSendObj.toSend = true;//有待发送
|
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
console.log(`推送节流失败, error: ${err}`); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
//全局变量
|
|
|
|
let msgSendObj = { |
|
|
|
time: null, |
|
|
|
dataMap: { appear: [], confirm: [], notice: [] }, |
|
|
|
toSend: false//有待发送
|
|
|
|
} |
|
|
|
setInterval(async () => { |
|
|
|
if (msgSendObj.toSend) {//有待发送
|
|
|
|
app.socket.emit('alarmSendSocket', { msgDataMap: msgSendObj.dataMap })//发送到前端
|
|
|
|
|
|
|
|
msgSendObj.time = moment().format() |
|
|
|
msgSendObj.dataMap = { appear: [], confirm: [], notice: [] } |
|
|
|
msgSendObj.toSend = false |
|
|
|
} |
|
|
|
}, 60 * 1000)//1分钟
|
|
|
|
|
|
|
|
return { |
|
|
|
sendAppearToWeb,//推送告警发现
|
|
|
|
sendConfirmToWeb,//推送告警确认
|
|
|
|