diff --git a/api/app/lib/controllers/alarm/app.js b/api/app/lib/controllers/alarm/app.js index 508bf03..f49cf9c 100644 --- a/api/app/lib/controllers/alarm/app.js +++ b/api/app/lib/controllers/alarm/app.js @@ -201,7 +201,7 @@ async function apiError(ctx) { await models.AppAlarm.create(storageData) //存告警记录 - //let constTypes = { 'element': "元素异常", 'apiError': "接口报错 ", 'timeout': "加载超时" } + let constTypes = { 'element': "元素异常", 'apiError': "接口报错 ", 'timeout': "加载超时" } let belongsTo = await models.ProjectApp.findOne({ where: { id: projectAppId @@ -222,10 +222,9 @@ async function apiError(ctx) { let pId = belongsTo.projectCorrelation.dataValues.id;//归属项目 let data = { projectCorrelationId: pId, - alarmInfo: { messageMode: 'AlarmGeneration', sourceName: appName.name, content: alarmContent, type },//AlarmGeneration代表告警首次产生 + alarmInfo: { messageMode: 'AlarmGeneration', sourceName: appName.name, content: alarmContent, type: constTypes[type] },//AlarmGeneration代表告警首次产生 time: now, type: '应用异常' - //type: constTypes[type] } let r = await models.AlarmAppearRecord.create(data, { returning: true }); let dynamic = { diff --git a/api/app/lib/controllers/alarm/video.js b/api/app/lib/controllers/alarm/video.js index e8ab1b0..efc5c14 100644 --- a/api/app/lib/controllers/alarm/video.js +++ b/api/app/lib/controllers/alarm/video.js @@ -324,7 +324,7 @@ async function alarmAdded(ctx) { let datas = projects.map(d => {//需要 项目,告警源,异常类型,时间 return { projectCorrelationId: d, - alarmInfo: { messageMode: 'AlarmGeneration', sourceName: belongToStruct[0].name, status_id, content: description },//AlarmGeneration代表告警首次产生 + alarmInfo: { messageMode: 'AlarmGeneration', sourceName: belongToStruct[0].name, status_id, type: description },//AlarmGeneration代表告警首次产生 time: create_time, type: description } diff --git a/api/app/lib/service/kafka.js b/api/app/lib/service/kafka.js index 491c5a7..adf393d 100644 --- a/api/app/lib/service/kafka.js +++ b/api/app/lib/service/kafka.js @@ -111,17 +111,23 @@ module.exports = async function factory(app, opts) { let exist = structs.find(s => s.strucId == structureId); if (exist) { let alarm_group = await clickHouse.anxinyun.query( - `SELECT alarm_group FROM t_alarm_code WHERE code='${alarmCode}'`).toPromise(); - - let type = alarm_group.length ? constAlarmGroups[alarm_group[0].alarm_group] : null//告警类型 - + `SELECT alarm_group, alarm_group_unit FROM t_alarm_code WHERE code='${alarmCode}'`).toPromise(); + + let type = null, alarmGroup = null;//告警类型 异常类型 + if (alarm_group) { + type = constAlarmGroups[alarm_group[0].alarm_group];//告警类型 + let gId = alarm_group[0].alarm_group_unit; + let alarm_group_unit = await clickHouse.anxinyun.query( + `SELECT name FROM t_alarm_group_unit WHERE id=${gId}`).toPromise(); + alarmGroup = alarm_group_unit.length ? alarm_group_unit[0].name : null//异常类型 + } let projects = exist.pomsProject.filter(d => !d.del).map(p => p.id); if (messageMode == 'AlarmGeneration') {//告警产生--------------------------------------------------1 let datas = projects.map(d => {//需要 项目,告警源,异常类型,时间 return { projectCorrelationId: d, - alarmInfo: { messageMode, sourceName, alarmTypeCode, alarmCode, content }, + alarmInfo: { messageMode, sourceName, alarmTypeCode, alarmCode, content, type: alarmGroup }, time: time, type//告警类型 } @@ -148,7 +154,7 @@ module.exports = async function factory(app, opts) { return { pepUserId: null, projectCorrelationId: d, - alarmInfo: { source: sourceName, type },//包含告警id,type,source + alarmInfo: { source: sourceName, type: alarmGroup },//包含告警id,type,source confirmTime: time, confirmContent: '自动恢复' } diff --git a/api/app/lib/utils/alarmHandle.js b/api/app/lib/utils/alarmHandle.js index a3120cc..f31e9a0 100644 --- a/api/app/lib/utils/alarmHandle.js +++ b/api/app/lib/utils/alarmHandle.js @@ -39,7 +39,7 @@ module.exports = function (app, opts) { projectCorrelationId: ld.projectCorrelationId, project: projects.find(p => p.id == ld.projectCorrelationId).name || pepProjects.find(pp => pp.id == pepPId).project_name,//前者为自定义项目名称 source: ld.alarmInfo.sourceName, - type: ld.type, + type: ld.alarmInfo.type,//异常类型 time: ld.time, alarmGroup//告警类型 })