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>();
title;
isVisiable = false;
isInterface = true;
nzSize = 'large';
hostId; //主机ID
itemId; //监控项id
interfaceList: any[];
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],
status: [null],
});
}
//新增
showAddModal(hostId,title) {
this.title = title;
this.isVisiable = true;
this.hostId = hostId;
//主机接口
this.overAllSer.findInterface(this.hostId).subscribe(
(res) => {
this.interfaceList = res.data;
}
);
}
//编辑
(res) => {
const data = res.data[0];
data.type += '';
data.interfaceid += '';
data.value_type += '';
this.validateForm.patchValue(data);
}
);
//主机接口
this.overAllSer.findInterface(this.hostId).subscribe(
(res) => {
this.interfaceList = res.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;
}
let d = this.validateForm.value.status == true ? 1 : 0;
this.validateForm.patchValue({
status:d
})
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
this.validateForm.value.hostid = this.hostId;
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();
}