Newer
Older
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {AlarmService} from '../../alarm/alarm.service';
import {FindUserComponent} from '../../alarm/modal/find-user/find-user.component';
import {NzFormatEmitEvent, NzMessageService, NzTreeComponent, NzTreeNode} from 'ng-zorro-antd';
import {OverAllService} from '../../overAll/overAll.service';
import {SelectPersonComponent} from '../select-person/select-person.component';
import {WorkService} from '../../work/work.service';
selector: 'smart-alarm-modal',
templateUrl: './alarm-modal.component.html',
border: 1px solid #dadada;
height: 200px;
overflow: auto;
margin-top: 10px;
@ViewChild('smartSelectPerson') smartSelectPerson: SelectPersonComponent;
constructor(private alarmSer: AlarmService, private message: NzMessageService,
private overAllSer: OverAllService, private workSer: WorkService,) {
warn: 0,
serious: 0,
mediaTypeIds: [],
def_longdata: '问题 {TRIGGER.NAME} 开始于: {EVENT.TIME} {EVENT.DATE}\n' +
'主机: {HOST.NAME}\n' +
'问题 {TRIGGER.NAME} 恢复于: {EVENT.TIME} {EVENT.DATE} \n' +
'主机: {HOST.NAME}\n' +
sendInfos: null,
event: {
eventTypeId: null, //事件分类id
operators: null, //事件负责人
title: null, //事件标题
//获取事件分类
getEventType() {
const data = {
type: 0
};
this.workSer.findParamsByType(data).subscribe(
(res) => {
this.eventTypeList = res.data;
}
);
}
this.overAllSer.findGroup().subscribe(
(res) => {
if (res.errCode == 10000) {
const dataSet = res.data;
dataSet.forEach(res => {
res.title = res.name;
res.key = res.groupid;
});
this.nodeList = dataSet;
this.toNode(dataSet);
} else {
this.message.info(res.errMsg);
}
}
);
}
this.alarmSer.alertGroupFind().subscribe(
(res) => {
if (res.errCode == 10000) {
this.groupList = res.data;
}
}
);
}
toNode(data) {
this.nodes = data.map(res => {
return new NzTreeNode(res);
});
}
//下级
mouseAction(name: string, event: NzFormatEmitEvent) {
const index = <any>event.node.key - 1;
const data = {
'groupids': [event.node.origin.groupid],
'hostExtend': {
'superiorHostid': null
}
};
this.overAllSer.findDetail(data).subscribe(
(res) => {
if (res.data) {
const dataSet = res.data;
dataSet.forEach(e => {
e.title = e.name;
e.key = e.hostid;
e.isLeaf = true;
});
event.node.addChildren(dataSet);
} else {
event.node.addChildren([]);
this.message.info('该分组下无资源');
}
}
);
setTimeout(_ => {
}, 1000);
}
//选择树节点
selectCheckTree(node) {
if (node.isChecked) {
this.selectTreeList.push(node.origin.hostid);
//获取发送方式
getSendFun() {
this.alarmSer.mediaTypeFind({}).subscribe(
(res) => {
if (res.errCode == 10000) {
this.sendOption = res.data;
}
}
);
}
//获取发送对象 zabbix
getZabbixObj() {
this.alarmSer.zUserFind({}).subscribe(
(res) => {
if (res.errCode == 10000) {
this.objList = res.data;
}
}
);
this.validateForm.name = data.name;
this.validateForm.alertGroupId = data.alertGroupId;
this.validateForm.serious = data.serious;
this.validateForm.warn = data.warn;
this.validateForm.event.title = data.event.title;
this.validateForm.event.eventTypeId = data.event.eventTypeId;
this.operatorList = data.event.operators.map(e => {
const d = {
username: e.username,
userId: e.userId
};
return d;
});
}
//发送方式回显
if (data.sendInfos && data.sendInfos.length > 0) {
this.sendInfoList = data.sendInfos.map(e => {
const d = {
mediaType: e.mediaType,
receiver: e.receiver
};
return d;
});
}
//恢复信息
if (data.r_longdata) {
this.selectModal = true;
}
//
this.selectTreeList = data.hostIds;
this.nodeList.forEach(e => {
if (data.hostIds.includes(e.key)) {
e.checked = true;
selectPerson() {
this.smartSelectPerson.showModal('选择事件负责人', null);
const arr = [];
e.forEach(res => {
const data = {
username: res.name,
userId: res.id
};
arr.push(data);
});
this.operatorList = arr;
}
this.validateForm.warn = this.validateForm.warn == true ? 1 : 0;
this.validateForm.serious = this.validateForm.serious == true ? 1 : 0;
warn: this.validateForm.warn,
serious: this.validateForm.serious,
mediaTypeIds: optionArr,
sendInfos: this.sendInfoList,
def_longdata: this.validateForm.def_longdata,
r_longdata: this.validateForm.r_longdata,
r_shortdata: this.validateForm.r_shortdata,
hostIds: this.selectTreeList,
if(this.isEvent == "1"){
data.event = {
eventTypeId: this.validateForm.event.eventTypeId, //事件分类id
operators: this.operatorList, //事件负责人
title: this.validateForm.event.title, //事件标题
}
}
this.create(data);
}
if (this.title == '编辑告警') {
this.update(data);
}
check() {
if (!this.validateForm.name) {
this.message.error('请输入告警名称');
if (this.sendInfoList.length == 0) {
this.message.error('请选择发送对象');
if (!this.validateForm.alertGroupId) {
this.message.error('请选择告警分组');
if (!this.validateForm.def_longdata) {
this.message.error('请输入发送信息');
if (this.isEvent == '1') {
if (!this.validateForm.event.title) {
this.message.error('请输入事件标题');
if (!this.validateForm.event.eventTypeId) {
this.message.error('请选择事件分类');
if (this.operatorList.length == 0) {
this.message.error('请选择事件负责人');
data.actionid = this.actionid;
this.alarmSer.actionUpdate(data).subscribe(
(res) => {