diff --git a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/ParamDefine.java b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/ParamDefine.java index 38f549f44fa..928ad2266e8 100644 --- a/common/src/main/java/org/apache/hertzbeat/common/entity/manager/ParamDefine.java +++ b/common/src/main/java/org/apache/hertzbeat/common/entity/manager/ParamDefine.java @@ -186,6 +186,13 @@ public class ParamDefine { @LastModifiedDate private LocalDateTime gmtUpdate; + /** + * Depends on which parameters + */ + @Schema(title = "Depends on which parameters", example = "{0, 1}", accessMode = READ_WRITE) + @Convert(converter = JsonStringListAttributeConverter.class) + private List parent; + /** * Parameter option configuration */ diff --git a/manager/src/main/resources/define/app-cisco_switch.yml b/manager/src/main/resources/define/app-cisco_switch.yml index 9d3cc72aba9..04dd6cc417f 100644 --- a/manager/src/main/resources/define/app-cisco_switch.yml +++ b/manager/src/main/resources/define/app-cisco_switch.yml @@ -56,7 +56,7 @@ params: # default value defaultValue: 161 # field-param field key - - field: version + - field: snmpVersion # name-param field display i18n name name: zh-CN: SNMP 版本 @@ -87,6 +87,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp community for v1 v2c' + # dependent parameter values list + parent: [ 0,1 ] # field-param field key - field: username # name-param field display i18n name @@ -101,6 +103,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp username for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: contextName # name-param field display i18n name @@ -115,6 +119,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp contextName for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPassphrase # name-param field display i18n name @@ -129,6 +135,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPasswordEncryption # name-param field display i18n name @@ -145,6 +153,8 @@ params: value: 0 - label: SHA1 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPassphrase # name-param field display i18n name @@ -159,6 +169,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPasswordEncryption # name-param field display i18n name @@ -175,6 +187,8 @@ params: value: 0 - label: AES128 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: timeout # name-param field display i18n name @@ -261,7 +275,7 @@ metrics: # snmp community community: ^_^community^_^ # snmp version - version: ^_^version^_^ + version: ^_^snmpVersion^_^ # snmp operation: get, walk operation: get # metrics oids: metric_name - oid_value @@ -389,7 +403,7 @@ metrics: contextName: ^_^contextName^_^ timeout: ^_^timeout^_^ community: ^_^community^_^ - version: ^_^version^_^ + version: ^_^snmpVersion^_^ operation: walk oids: ifIndex: 1.3.6.1.2.1.2.2.1.1 diff --git a/manager/src/main/resources/define/app-h3c_switch.yml b/manager/src/main/resources/define/app-h3c_switch.yml index ed21729c0c7..cc4d852f48f 100644 --- a/manager/src/main/resources/define/app-h3c_switch.yml +++ b/manager/src/main/resources/define/app-h3c_switch.yml @@ -56,7 +56,7 @@ params: # default value defaultValue: 161 # field-param field key - - field: version + - field: snmpVersion # name-param field display i18n name name: zh-CN: SNMP 版本 @@ -87,6 +87,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp community for v1 v2c' + # dependent parameter values list + parent: [ 0,1 ] # field-param field key - field: username # name-param field display i18n name @@ -101,6 +103,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp username for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: contextName # name-param field display i18n name @@ -115,6 +119,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp contextName for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPassphrase # name-param field display i18n name @@ -129,6 +135,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPasswordEncryption # name-param field display i18n name @@ -145,6 +153,8 @@ params: value: 0 - label: SHA1 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPassphrase # name-param field display i18n name @@ -159,6 +169,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPasswordEncryption # name-param field display i18n name @@ -175,6 +187,8 @@ params: value: 0 - label: AES128 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: timeout # name-param field display i18n name @@ -261,7 +275,7 @@ metrics: # snmp 团体字 community: ^_^community^_^ # snmp version - version: ^_^version^_^ + version: ^_^snmpVersion^_^ # snmp operation: get, walk operation: get # metrics oids: metric_name - oid_value @@ -388,7 +402,7 @@ metrics: contextName: ^_^contextName^_^ timeout: ^_^timeout^_^ community: ^_^community^_^ - version: ^_^version^_^ + version: ^_^snmpVersion^_^ operation: walk oids: ifIndex: 1.3.6.1.2.1.2.2.1.1 diff --git a/manager/src/main/resources/define/app-hpe_switch.yml b/manager/src/main/resources/define/app-hpe_switch.yml index ccf7b67e3e8..19bd6a04a76 100644 --- a/manager/src/main/resources/define/app-hpe_switch.yml +++ b/manager/src/main/resources/define/app-hpe_switch.yml @@ -56,7 +56,7 @@ params: # default value defaultValue: 161 # field-param field key - - field: version + - field: snmpVersion # name-param field display i18n name name: zh-CN: SNMP 版本 @@ -87,6 +87,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp community for v1 v2c' + # dependent parameter values list + parent: [ 0,1 ] # field-param field key - field: username # name-param field display i18n name @@ -101,6 +103,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp username for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: contextName # name-param field display i18n name @@ -115,6 +119,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp contextName for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPassphrase # name-param field display i18n name @@ -129,6 +135,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPasswordEncryption # name-param field display i18n name @@ -145,6 +153,8 @@ params: value: 0 - label: SHA1 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPassphrase # name-param field display i18n name @@ -159,6 +169,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPasswordEncryption # name-param field display i18n name @@ -175,6 +187,8 @@ params: value: 0 - label: AES128 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: timeout # name-param field display i18n name @@ -261,7 +275,7 @@ metrics: # snmp 团体字 community: ^_^community^_^ # snmp version - version: ^_^version^_^ + version: ^_^snmpVersion^_^ # snmp operation: get, walk operation: get # metrics oids: metric_name - oid_value @@ -389,7 +403,7 @@ metrics: contextName: ^_^contextName^_^ timeout: ^_^timeout^_^ community: ^_^community^_^ - version: ^_^version^_^ + version: ^_^snmpVersion^_^ operation: walk oids: ifIndex: 1.3.6.1.2.1.2.2.1.1 diff --git a/manager/src/main/resources/define/app-huawei_switch.yml b/manager/src/main/resources/define/app-huawei_switch.yml index f20f52163dc..812a895620a 100644 --- a/manager/src/main/resources/define/app-huawei_switch.yml +++ b/manager/src/main/resources/define/app-huawei_switch.yml @@ -56,7 +56,7 @@ params: # default value defaultValue: 161 # field-param field key - - field: version + - field: snmpVersion # name-param field display i18n name name: zh-CN: SNMP 版本 @@ -87,6 +87,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp community for v1 v2c' + # dependent parameter values list + parent: [ 0,1 ] # field-param field key - field: username # name-param field display i18n name @@ -101,6 +103,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp username for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: contextName # name-param field display i18n name @@ -115,6 +119,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp contextName for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPassphrase # name-param field display i18n name @@ -129,6 +135,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPasswordEncryption # name-param field display i18n name @@ -145,6 +153,8 @@ params: value: 0 - label: SHA1 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPassphrase # name-param field display i18n name @@ -159,6 +169,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPasswordEncryption # name-param field display i18n name @@ -175,6 +187,8 @@ params: value: 0 - label: AES128 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: timeout # name-param field display i18n name @@ -260,7 +274,7 @@ metrics: # snmp community community: ^_^community^_^ # snmp version - version: ^_^version^_^ + version: ^_^snmpVersion^_^ # snmp operation: get, walk operation: get # metrics oids: metric_name - oid_value @@ -387,7 +401,7 @@ metrics: contextName: ^_^contextName^_^ timeout: ^_^timeout^_^ community: ^_^community^_^ - version: ^_^version^_^ + version: ^_^snmpVersion^_^ operation: walk oids: ifIndex: 1.3.6.1.2.1.2.2.1.1 diff --git a/manager/src/main/resources/define/app-tplink_switch.yml b/manager/src/main/resources/define/app-tplink_switch.yml index 797a3941161..1b16d153a91 100644 --- a/manager/src/main/resources/define/app-tplink_switch.yml +++ b/manager/src/main/resources/define/app-tplink_switch.yml @@ -56,7 +56,7 @@ params: # default value defaultValue: 161 # field-param field key - - field: version + - field: snmpVersion # name-param field display i18n name name: zh-CN: SNMP 版本 @@ -87,6 +87,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp community for v1 v2c' + # dependent parameter values list + parent: [ 0,1 ] # field-param field key - field: username # name-param field display i18n name @@ -101,6 +103,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp username for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: contextName # name-param field display i18n name @@ -115,6 +119,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp contextName for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPassphrase # name-param field display i18n name @@ -129,6 +135,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: authPasswordEncryption # name-param field display i18n name @@ -145,6 +153,8 @@ params: value: 0 - label: SHA1 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPassphrase # name-param field display i18n name @@ -159,6 +169,8 @@ params: required: false # param field input placeholder placeholder: 'Snmp authPassword for v3' + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: privPasswordEncryption # name-param field display i18n name @@ -175,6 +187,8 @@ params: value: 0 - label: AES128 value: 1 + # dependent parameter values list + parent: [ 3 ] # field-param field key - field: timeout # name-param field display i18n name @@ -260,7 +274,7 @@ metrics: # snmp community community: ^_^community^_^ # snmp version - version: ^_^version^_^ + version: ^_^snmpVersion^_^ # snmp operation: get, walk operation: get # metrics oids: metric_name - oid_value @@ -387,7 +401,7 @@ metrics: contextName: ^_^contextName^_^ timeout: ^_^timeout^_^ community: ^_^community^_^ - version: ^_^version^_^ + version: ^_^snmpVersion^_^ operation: walk oids: ifIndex: 1.3.6.1.2.1.2.2.1.1 diff --git a/manager/src/main/resources/define/app-windows.yml b/manager/src/main/resources/define/app-windows.yml index 296e604b55c..cfc86d1999e 100644 --- a/manager/src/main/resources/define/app-windows.yml +++ b/manager/src/main/resources/define/app-windows.yml @@ -56,7 +56,7 @@ params: # default value defaultValue: 161 # field-param field key - - field: version + - field: snmpVersion # name-param field display i18n name name: zh-CN: SNMP 版本 @@ -70,7 +70,7 @@ params: - label: SNMPv1 value: 0 - label: SNMPv2c - value: 1 + value: 3 # field-param field key - field: community # name-param field display i18n name @@ -85,6 +85,8 @@ params: required: true # param field input placeholder placeholder: 'Snmp community for v1 v2c' + # dependent parameter values list + parent: [ 0,1 ] # field-param field key - field: timeout # name-param field display i18n name @@ -181,7 +183,7 @@ metrics: port: ^_^port^_^ timeout: ^_^timeout^_^ community: ^_^community^_^ - version: ^_^version^_^ + version: ^_^snmpVersion^_^ operation: walk oids: hrSWRunIndex: 1.3.6.1.2.1.25.4.2.1.1 diff --git a/web-app/src/app/pojo/Param.ts b/web-app/src/app/pojo/Param.ts index 4b9a856f8bc..1914f3bc8b1 100644 --- a/web-app/src/app/pojo/Param.ts +++ b/web-app/src/app/pojo/Param.ts @@ -22,4 +22,6 @@ export class Param { field!: string; type: number | undefined; paramValue: any; + // 是否显示 + display: boolean = true; } diff --git a/web-app/src/app/pojo/ParamDefine.ts b/web-app/src/app/pojo/ParamDefine.ts index 4e14401cd0c..8940608a7b5 100644 --- a/web-app/src/app/pojo/ParamDefine.ts +++ b/web-app/src/app/pojo/ParamDefine.ts @@ -33,4 +33,6 @@ export class ParamDefine { valueAlias!: string; // 此参数是否隐藏 即默认不显示, 在高级设置区显示 hide: boolean = false; + // 依赖的上级参数列表 + parent: string | undefined; } diff --git a/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.html b/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.html index d2221e90292..85e44bd6f54 100644 --- a/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.html +++ b/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.html @@ -45,141 +45,144 @@ - - {{ paramDefine.name }} - - - - - - {{ paramDefine.name }} - - - - - - {{ paramDefine.name }} - - - + + + {{ paramDefine.name }} + + - - - - - + - {{ paramDefine.name }} - - - - + {{ paramDefine.name }} + + + + - {{ paramDefine.name }} - - - - + {{ paramDefine.name }} + + + + + + + + + - {{ paramDefine.name }} - - - - - - + {{ paramDefine.name }} + + + + - {{ paramDefine.name }} - - - - + {{ paramDefine.name }} + + + + - {{ paramDefine.name }} - - - - - + {{ paramDefine.name }} + + + + + + + + {{ paramDefine.name }} + + + + + + {{ paramDefine.name }} + + + + + + diff --git a/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.ts b/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.ts index abc1ba48d6b..d13a1c9672e 100644 --- a/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.ts +++ b/web-app/src/app/routes/monitor/monitor-edit/monitor-edit.component.ts @@ -164,6 +164,10 @@ export class MonitorEditComponent implements OnInit { this.hostName = define.name; } }); + let paramDefine = this.paramDefines.find(param => param.field === 'snmpVersion'); + if (paramDefine) { + this.onSnmpVersionChanged(this.paramValueMap.get(paramDefine.field)?.paramValue, paramDefine.field); + } } else { console.warn(message.msg); } @@ -201,6 +205,18 @@ export class MonitorEditComponent implements OnInit { } } + onSnmpVersionChanged(snmpVersion: string, field: string) { + // 对不同snmp版本需要的参数进行动态展示 + if (field === 'snmpVersion') { + this.paramDefines.forEach((paramDefine, index) => { + this.params[index].display = true; + if (paramDefine.parent != null && !paramDefine.parent.toString().includes(snmpVersion)) { + this.params[index].display = false; + } + }); + } + } + onSubmit(formGroup: FormGroup) { if (formGroup.invalid) { Object.values(formGroup.controls).forEach(control => { diff --git a/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.html b/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.html index ec349377433..0a0398b1def 100644 --- a/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.html +++ b/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.html @@ -54,141 +54,144 @@ - - {{ paramDefine.name }} - - - - - - {{ paramDefine.name }} - - - - - - {{ paramDefine.name }} - - - + + + {{ paramDefine.name }} + + - - - - - + - {{ paramDefine.name }} - - - - + {{ paramDefine.name }} + + + + - {{ paramDefine.name }} - - - - + {{ paramDefine.name }} + + + + + + + + + - {{ paramDefine.name }} - - - - - - + {{ paramDefine.name }} + + + + - {{ paramDefine.name }} - - - - + {{ paramDefine.name }} + + + + - {{ paramDefine.name }} - - - - - + {{ paramDefine.name }} + + + + + + + + {{ paramDefine.name }} + + + + + + {{ paramDefine.name }} + + + + + + diff --git a/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts b/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts index f3ed5c75623..4d1c01bb94e 100644 --- a/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts +++ b/web-app/src/app/routes/monitor/monitor-new/monitor-new.component.ts @@ -179,6 +179,23 @@ export class MonitorNewComponent implements OnInit { } } + onSnmpVersionChanged(snmpVersion: string, field: string) { + // 对不同snmp版本需要的参数进行动态展示 + if (field === 'snmpVersion') { + this.paramDefines.forEach((paramDefine, index) => { + this.params[index].display = true; + if (paramDefine.parent != undefined && !paramDefine.parent.toString().includes(snmpVersion)) { + this.params[index].display = false; + } + }); + } + this.refreshParams(); + } + + refreshParams() { + this.params = [...this.params]; + } + onSubmit(formGroup: FormGroup) { if (formGroup.invalid) { Object.values(formGroup.controls).forEach(control => {