Browse Source

(*)告警异常类型修改

dev
wuqun 2 years ago
parent
commit
7aada774cd
  1. 5
      api/app/lib/controllers/alarm/app.js
  2. 2
      api/app/lib/controllers/alarm/video.js
  3. 18
      api/app/lib/service/kafka.js
  4. 2
      api/app/lib/utils/alarmHandle.js

5
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 = {

2
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
}

18
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: '自动恢复'
}

2
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//告警类型
})

Loading…
Cancel
Save