Browse Source

告警推送++

dev
CODE 1 year ago
parent
commit
7ee75b80cf
  1. 40
      api/app/lib/schedule/alarms_push.js
  2. 1
      api/app/lib/service/clickHouseClient.js

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

@ -1,10 +1,10 @@
const moment = require('moment') const moment = require('moment')
let isDev = false let isDev = false
// isDev = true isDev = true
let proDebug = false let proDebug = false
proDebug = true // proDebug = true
module.exports = function (app, opts) { module.exports = function (app, opts) {
const alarmsPush = app.fs.scheduleInit( const alarmsPush = app.fs.scheduleInit(
@ -102,6 +102,10 @@ module.exports = function (app, opts) {
pLog(`curMinOfYear / ${curMinOfYear}`) pLog(`curMinOfYear / ${curMinOfYear}`)
for (let { dataValues: c } of configListRes) { for (let { dataValues: c } of configListRes) {
if (c.id != 94) {
continue
}
if (c.tacticsParams && c.tactics) { if (c.tacticsParams && c.tactics) {
pLog(`当前运行EM配置:id=${c.id} name=${c.name}`); pLog(`当前运行EM配置:id=${c.id} name=${c.name}`);
// pomsProjectId 是个数组 [] // pomsProjectId 是个数组 []
@ -545,17 +549,17 @@ module.exports = function (app, opts) {
//本地化 //本地化
const dataAlarmsLocal = !c.alarmSubType || dataAlarmSubType_.length ? const dataAlarmsLocal = !c.alarmSubType || dataAlarmSubType_.length ?
await clickHouse.dataAlarm.query(` await clickHouse.dataAlarm.query(`
SELECT * FROM alarms SELECT * FROM alarms
LEFT JOIN sensors LEFT JOIN sensors
AS anxinStation AS anxinStation
ON anxinStation.ID= alarms.SourceId ON anxinStation.ID= alarms.SourceId
AND alarms.SourceTypeId = 2 AND alarms.SourceTypeId = 2
WHERE WHERE
${`State NOT IN (3, 4) AND `} ${`State NOT IN (3, 4) AND `}
StructureId IN (${searchStrucIds.join(',')}) StructureId IN (${searchStrucIds.join(',')})
${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''} ${dataAlarmOption.length ? ' AND ' + dataAlarmOption.join(' AND ') : ''}
ORDER BY StartTime DESC ORDER BY StartTime DESC
`).toPromise() : [] `).toPromise() : []
//合并本地化和安心云的告警 //合并本地化和安心云的告警
dataAlarms = [...dataAlarms, ...dataAlarmsLocal] dataAlarms = [...dataAlarms, ...dataAlarmsLocal]
pLog('合并的告警列表(安心云+本地)', dataAlarms.length) pLog('合并的告警列表(安心云+本地)', dataAlarms.length)
@ -1092,9 +1096,6 @@ module.exports = function (app, opts) {
} }
} }
} }
if (proDebug) {
console.log(`符合条件的策略命中 + 1`, d);
}
dataAlarmG3.push(d) dataAlarmG3.push(d)
} else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) { } else if (d.AlarmGroup == 4 || d.AlarmGroup == 5) {
dataAlarmG45.push(d) dataAlarmG45.push(d)
@ -1166,7 +1167,7 @@ module.exports = function (app, opts) {
pLog('安心云项目结构物id', dataAlarmG1StructureId) pLog('安心云项目结构物id', dataAlarmG1StructureId)
pLog('本地化项目结构物id', dataAlarmStructureId) pLog('本地化项目结构物id', dataAlarmStructureId)
//查询结构物的监测因素(安心云) //查询结构物的监测因素(安心云)
let factorData = dataAlarmStructureId.size ? await clickHouse.anxinyun.query( let factorData = dataAlarmG1StructureId.size ? await clickHouse.anxinyun.query(
` `
SELECT SELECT
t_structure_factor.structure AS structureId, t_structure_factor.structure AS structureId,
@ -1676,7 +1677,7 @@ module.exports = function (app, opts) {
if (isDev) { if (isDev) {
// !开发测试用的数据 // !开发测试用的数据
emails = ['1650192445@qq.com'] emails = ['gao.zhiyuan@free-sun.com.cn']
// emails=['zhao.bin@free-sun.com.cn'] // emails=['zhao.bin@free-sun.com.cn']
// emails = ['wen.lele@free-sun.com.cn'] // emails = ['wen.lele@free-sun.com.cn']
} }
@ -1690,6 +1691,9 @@ module.exports = function (app, opts) {
html: html html: html
}) })
if (isDev) {
continue
}
// //存日志 存动态 socket到前端 // //存日志 存动态 socket到前端
let dataToSave = { let dataToSave = {
time: moment().format(), time: moment().format(),

1
api/app/lib/service/clickHouseClient.js

@ -13,6 +13,7 @@ function factory (app, opts) {
port: port, port: port,
debug: opts.dev, debug: opts.dev,
format: "json", format: "json",
usePost: true,
basicAuth: user && password ? { basicAuth: user && password ? {
username: user, username: user,
password: password, password: password,

Loading…
Cancel
Save