巴林闲侠
2 years ago
13 changed files with 239 additions and 91 deletions
@ -0,0 +1,49 @@ |
|||
'use strict'; |
|||
|
|||
const moment = require('moment') |
|||
|
|||
async function alarmConfirmLog(ctx, confirmPost, content) { |
|||
try { |
|||
const { models } = ctx.fs.dc; |
|||
//存日志
|
|||
let logDatas = []; |
|||
confirmPost.map(cp => { |
|||
let { pepUserId, projectCorrelationIds, alarmInfo } = cp; |
|||
projectCorrelationIds.map(id => { |
|||
logDatas.push({ |
|||
pepUserId, |
|||
projectCorrelationId: id, |
|||
alarmInfo,//包含告警id,type,source
|
|||
confirmTime: moment().format(), |
|||
confirmContent: content |
|||
}) |
|||
}) |
|||
}) |
|||
let rslt = await models.AlarmConfirmLog.bulkCreate(logDatas, { returning: true }); |
|||
|
|||
//存最新动态
|
|||
let dynamics = rslt.map(r => { |
|||
return { |
|||
time: r.confirmTime, |
|||
alarmConfirmId: r.id, |
|||
projectCorrelationId: r.projectCorrelationId, |
|||
type: 4//告警确认
|
|||
} |
|||
}) |
|||
await models.LatestDynamicList.bulkCreate(dynamics); |
|||
|
|||
//TODO 消息推送到前端
|
|||
|
|||
|
|||
} catch (error) { |
|||
ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); |
|||
ctx.status = 400; |
|||
ctx.body = { |
|||
message: typeof error == 'string' ? error : undefined |
|||
} |
|||
} |
|||
} |
|||
|
|||
module.exports = { |
|||
alarmConfirmLog |
|||
}; |
@ -0,0 +1,22 @@ |
|||
|
|||
|
|||
create table alarm_confirm_log |
|||
( |
|||
id serial not null, |
|||
pep_user_id int null, |
|||
project_correlation_id int not null, |
|||
alarm_info json not null, |
|||
confirm_time timestamp not null, |
|||
confirm_content varchar not null |
|||
); |
|||
|
|||
comment on table alarm_confirm_log is '告警确认日志表'; |
|||
|
|||
create unique index alarm_confirm_log_id_uindex |
|||
on alarm_confirm_log (id); |
|||
|
|||
alter table alarm_confirm_log |
|||
add constraint alarm_confirm_log_pk |
|||
primary key (id); |
|||
|
|||
|
@ -0,0 +1,27 @@ |
|||
|
|||
|
|||
create table if not exists email_send_log |
|||
( |
|||
id serial not null |
|||
constraint email_send_log_pk |
|||
primary key, |
|||
time timestamp not null, |
|||
push_config_id integer not null, |
|||
tactics varchar(32), |
|||
tactics_params jsonb, |
|||
project_correlation_id integer not null, |
|||
to_pep_user_ids integer[] not null |
|||
); |
|||
|
|||
comment on table email_send_log is 'EM推送日志'; |
|||
|
|||
alter table email_send_log owner to postgres; |
|||
|
|||
create unique index if not exists email_send_log_id_uindex |
|||
on email_send_log (id); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,23 @@ |
|||
|
|||
|
|||
create table alarm_appear_record |
|||
( |
|||
id serial not null, |
|||
project_correlation_id int not null, |
|||
alarm_info json not null, |
|||
time timestamp, |
|||
type varchar null |
|||
); |
|||
|
|||
comment on table alarm_appear_record is '告警出现记录到日志'; |
|||
|
|||
create unique index alarm_appear_record_id_uindex |
|||
on alarm_appear_record (id); |
|||
|
|||
alter table alarm_appear_record |
|||
add constraint alarm_appear_record_pk |
|||
primary key (id); |
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,28 @@ |
|||
|
|||
|
|||
create table latest_dynamic_list |
|||
( |
|||
id serial not null, |
|||
time timestamp not null, |
|||
project_correlation_id int not null, |
|||
alarm_appear_id int, |
|||
email_send_id int, |
|||
alarm_confirm_id int, |
|||
type int |
|||
); |
|||
|
|||
comment on table latest_dynamic_list is '最新动态表'; |
|||
comment on column latest_dynamic_list.type is '1:发现,2:通知,3:处置,4:确认'; |
|||
|
|||
create unique index latest_dynamic_list_id_uindex |
|||
on latest_dynamic_list (id); |
|||
|
|||
alter table latest_dynamic_list |
|||
add constraint latest_dynamic_list_pk |
|||
primary key (id); |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
@ -0,0 +1,22 @@ |
|||
|
|||
|
|||
create table alarm_handle_statistics |
|||
( |
|||
id serial not null, |
|||
time timestamp not null, |
|||
project_correlation_id int, |
|||
day1 float, |
|||
day3 float, |
|||
day7 float, |
|||
day15 float, |
|||
day30 float, |
|||
day30m float |
|||
); |
|||
|
|||
create unique index alarm_handle_statistics_id_uindex |
|||
on alarm_handle_statistics (id); |
|||
|
|||
alter table alarm_handle_statistics |
|||
add constraint alarm_handle_statistics_pk |
|||
primary key (id); |
|||
|
Loading…
Reference in new issue