Newer
Older
import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {OverAllService} from '../../overAll/overAll.service';
import {FormBuilder} from '@angular/forms';
import {NzMessageService} from 'ng-zorro-antd';
@Component({
selector: 'smart-threshold',
templateUrl: './threshold.component.html',
styles: []
})
export class ThresholdComponent implements OnInit {
@Output() done = new EventEmitter<any>();
isVisiable = false;
title;
itemId; //监控项ID
hostName; //主机name
itemObj; //监控项对象
triggerConditionId;
triggerFaultConditionId;
triggerObj = {
constructor(private overAllSer: OverAllService, private fb: FormBuilder,
private message: NzMessageService) {
}
this.isOkLoading = false;
this.conditionExpression = '';
this.faultConditionExpression = '';
this.title = title;
this.itemId = itemId;
this.isVisiable = true;
this.hostName = hostName;
this.title = title;
this.itemId = itemId;
this.isVisiable = true;
this.hostName = hostName;
item.triggers.forEach((value) => {
if (value.priority == 1) { //告警
this.triggerObj.condition = value;
this.conditionExpression = value.expression;
this.triggerConditionId = value.id;
if (value.priority == 2) { //严重
this.triggerObj.faultCondition = value;
this.faultConditionExpression = value.expression;
this.triggerFaultConditionId = value.id;
}
})
if (!this.triggerObj.condition && this.conditionExpression) { //告警触发器创建
const res = {
itemName: this.itemObj.name,
condition: this.conditionExpression,
itemid: this.itemId
};
this.overAllSer.createTrigger(res).subscribe(
(response) => {
if (response.errCode == 10000) {
this.message.success('创建告警阈值成功');
this.initForm();
this.done.emit();
this.isVisiable = false;
} else {
this.message.error(response.errMsg);
}
this.isOkLoading = false;
}
);
if (this.triggerObj.condition) { //告警触发器更新
this.triggerObj.condition.expression = this.conditionExpression;
this.overAllSer.updateTrigger(this.triggerObj.condition).subscribe(res => {
if (res.errCode == 10000) {
this.message.success('更新告警阈值成功');
});
}
if (!this.triggerObj.faultCondition && this.faultConditionExpression) { //严重触发器创建
const res = {
itemName: this.itemObj.name,
faultCondition: this.faultConditionExpression,
itemid: this.itemId
};
this.overAllSer.createTrigger(res).subscribe(
(response) => {
if (response.errCode == 10000) {
this.message.success('创建严重阈值成功');
this.initForm();
this.done.emit();
this.isVisiable = false;
} else {
this.message.error(response.errMsg);
}
if (this.triggerObj.faultCondition) { //严重触发器更新
this.triggerObj.faultCondition.expression = this.faultConditionExpression;
this.overAllSer.updateTrigger(this.triggerObj.faultCondition).subscribe(res => {
this.initForm();
this.done.emit();
this.isVisiable = false;
}
this.isOkLoading = false;
});
}