Newer
Older
import {Component, EventEmitter, OnInit, Output, ViewChild} from '@angular/core';
import {FormBuilder, FormControl, FormGroup, Validator, Validators} from '@angular/forms';
import {OverAllService} from '../../overAll/overAll.service';
import {BasicKeyComponent} from '../basic-key/basic-key.component';
import {NewTypeComponent} from '../new-type/new-type.component';
import {NzMessageService} from 'ng-zorro-antd';
@Component({
selector: 'smart-discovery',
templateUrl: './discovery.component.html',
styles: []
})
export class DiscoveryComponent implements OnInit {
@ViewChild('basicKey') basicKey: BasicKeyComponent;
@ViewChild('newType') newType: NewTypeComponent;
@Output() done = new EventEmitter<any>();
nzSize = 'large';
hostId; //主机ID
itemId; //监控项id
valueMapList = [];
validateForm: FormGroup;
checkList; //监测点分类
interval; //间隔时长
constructor(private overAllSer: OverAllService, private fb: FormBuilder,
private message: NzMessageService) {
}
ngOnInit() {
this.initForm();
}
initForm() {
this.validateForm = this.fb.group({
hostid: [this.hostId],
name: [null, [Validators.required]],
type: [null, [Validators.required]],
key_: [null, [Validators.required]],
snmp_oid: ['interfaces.ifTable.ifEntry.ifInOctets.1'],
snmp_community: ['public'],
port: [this.hostId],
delay: [null, [Validators.required]],
description: [null],
});
}
//新增
showAddModal(hostId,title) {
this.title = title;
this.isVisiable = true;
this.hostId = hostId;
}
//编辑
(res) => {
const data = res.data[0];
data.type += '';
data.value_type += '';
this.validateForm.patchValue(data);
}
);
}
//添加
handleCheckOk() {
for (let i in this.validateForm.controls) {
this.validateForm.controls[i].markAsDirty();
this.validateForm.controls[i].updateValueAndValidity();
}
if (this.validateForm.invalid) {
this.message.error('请输入必填信息');
return false;
}
if (this.title == '添加自动发现') {
this.create();
}
if (this.title == '编辑自动发现') {
this.update();
}
}
create() {
this.overAllSer.createLldrule(this.validateForm.value).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.success('创建自动发现成功');
this.done.emit();
this.isVisiable = false;
} else {
this.message.error(res.errMsg);
}
},
(err) => {
this.message.error('系统错误');
}
);
}
//修改监控项
update() {
this.validateForm.addControl('itemid', new FormControl(this.itemId));
this.overAllSer.updateLldrule(this.validateForm.value).subscribe(
(res) => {
if (res.errCode == 10000) {
this.message.success('修改自动发现成功');
this.done.emit();
this.isVisiable = false;
} else {
this.message.error(res.errMsg);
}
},
(err) => {
this.message.error('系统错误');
}
);
}
handleCheckCancel(): void {
this.isVisiable = false;
this.initForm();
}