Browse Source

批量确认数据告警

dev
巴林闲侠 2 years ago
parent
commit
2418f6a550
  1. 40
      api/app/lib/controllers/alarm/data.js

40
api/app/lib/controllers/alarm/data.js

@ -241,7 +241,7 @@ function confirm (opts) {
*/ */
const alarmRes = await clickHouse.dataAlarm.query(` const alarmRes = await clickHouse.dataAlarm.query(`
SELECT * FROM alarms WHERE AlarmId = '${alarmId}' SELECT * FROM alarms WHERE AlarmId IN (${alarmId.split(',').map(a => `'${a}'`).join(',')})
`).toPromise(); `).toPromise();
if (!alarmRes.length) { if (!alarmRes.length) {
@ -252,23 +252,27 @@ function confirm (opts) {
if ([3, 4].some(s => s == corAlarm.State)) { if ([3, 4].some(s => s == corAlarm.State)) {
throw '告警信息已确认' throw '告警信息已确认'
} }
const message = { for (let corAlarm of alarmRes) {
messageMode: "AlarmManElimination", if ([3, 4].some(s => s == corAlarm.State)) {
sourceId: corAlarm.SourceId, continue
alarmTypeCode: corAlarm.AlarmTypeCode, }
sponsor: opts.anxinCloud.confirmAlarmAnxinUserId, const message = {
content: content, messageMode: "AlarmManElimination",
time: moment().toISOString() sourceId: corAlarm.SourceId,
}; alarmTypeCode: corAlarm.AlarmTypeCode,
sponsor: opts.anxinCloud.confirmAlarmAnxinUserId,
const payloads = [{ content: content,
topic: `${opts.kafka.topicPrefix}_alarm`, time: moment().toISOString()
messages: [JSON.stringify(message)], };
partition: 0
}]; const payloads = [{
topic: `${opts.kafka.topicPrefix}_alarm`,
await kfkSendAsync(payloads) messages: [JSON.stringify(message)],
partition: 0
}];
await kfkSendAsync(payloads)
}
ctx.status = 204; ctx.status = 204;
} catch (error) { } catch (error) {
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`);

Loading…
Cancel
Save