diff --git a/nezha-fronted/src/components/common/rightBox/alertRuleBox.vue b/nezha-fronted/src/components/common/rightBox/alertRuleBox.vue index 037df0912..8b37c941e 100644 --- a/nezha-fronted/src/components/common/rightBox/alertRuleBox.vue +++ b/nezha-fronted/src/components/common/rightBox/alertRuleBox.vue @@ -23,6 +23,7 @@ class="right-box__select" popper-class="right-box-select-dropdown prevent-clickoutside" size="small" + :disabled="showTypeSelect" @change="selectAlertRuleMetric"> - - - - - - - - - - - + + + + + + + + + + + + + + - + @@ -72,7 +76,7 @@ - + { + if (this.MetricsType === 3) { + const Oid = /^(\d{1,9}\.){0,}[\d]+$/ + if (Oid.test(value)) { + callback() + } else { + callback(new Error(this.$t('overall.oid'))) + } + } + } return { promqlCount: 1, promqlKeys: [0], @@ -194,16 +208,23 @@ export default { { value: 'Logs', label: this.$t('overall.logs') + }, + { + value: 'SNMP trap', + label: 'SNMP trap' } ], showMetrics: true, + showSnmpTrap: true, + showTypeSelect: false, editAlertRule: {}, rules: { name: [ { required: true, message: this.$t('validate.required'), trigger: 'blur' } ], expr: [ - { required: true, message: this.$t('validate.required'), trigger: 'change' } + { required: true, message: this.$t('validate.required'), trigger: 'change' }, + { validator: nzOid, trigger: 'blur' } ], last: [ { required: true, message: this.$t('validate.required'), trigger: 'blur' }, @@ -271,7 +292,9 @@ export default { save () { if (this.prevent_opt.save) { return } ; this.prevent_opt.save = true - this.editAlertRule.expr = this.expressions[0] + if (this.MetricsType !== 3) { + this.editAlertRule.expr = this.expressions[0] + } const params = { ...this.editAlertRule, method: this.editAlertRule.method.join(','), @@ -369,13 +392,29 @@ export default { }, selectAlertRuleMetric (val) { if (val === 'Metrics') { + // showMetrics 为 true 时,展示 Metrics this.showMetrics = true + // showSnmpTrap 为 true 时,展示 Expression,Threshold,Unit + this.showSnmpTrap = true + // type = 1 this.MetricsType = 1 + // 移除from表单的 expr 验证 + this.$refs.alertRuleForm.clearValidate('expr') } else if (val === 'Logs') { + // showMetrics 为 false 时,展示 Logs label this.showMetrics = false + // showSnmpTrap 为 true 时,展示Expression,Threshold,Unit + this.showSnmpTrap = true + // type = 2 this.MetricsType = 2 + // 移除from表单的 expr 验证 + this.$refs.alertRuleForm.clearValidate('expr') + } else if (val === 'SNMP trap') { + // showSnmpTrap 为 false 时,展示 OID + this.showSnmpTrap = false + // type = 3 + this.MetricsType = 3 } - this.$refs.promql.expressionList[0] = '' } }, mounted () { @@ -389,17 +428,32 @@ export default { immediate: true, handler (n, o) { this.isEdit = true - console.log(n.type) this.editAlertRule = JSON.parse(JSON.stringify(n)) if (this.editAlertRule.id || this.editAlertRule.name) { + this.expressions = [this.editAlertRule.expr] + // 当 edit 时禁用 type下拉框 + this.showTypeSelect = true if (n.type === 1) { this.fromData.status = 'Metrics' + // showMetrics 为 true 时,展示 Metrics this.showMetrics = true + // showSnmpTrap 为 true 时,展示Expression,Threshold,Unit + this.showSnmpTrap = true + this.MetricsType = 1 } else if (n.type === 2) { this.fromData.status = 'Logs' + // showMetrics 为 false 时,展示 Logs label this.showMetrics = false + // showSnmpTrap 为 true 时,展示Expression,Threshold,Unit + this.showSnmpTrap = true + this.MetricsType = 2 + } else if (n.type === 3) { + this.fromData.status = 'SNMP trap' + // showSnmpTrap 为 false 时,展示 OID + this.showSnmpTrap = false + this.MetricsType = 3 + return } - this.expressions = [this.editAlertRule.expr] this.$nextTick(() => { this.expressions.forEach((ex, index) => { if (ex) { diff --git a/nezha-fronted/src/components/common/table/alert/alertRuleTable.vue b/nezha-fronted/src/components/common/table/alert/alertRuleTable.vue index c377b8e41..da1366b2a 100644 --- a/nezha-fronted/src/components/common/table/alert/alertRuleTable.vue +++ b/nezha-fronted/src/components/common/table/alert/alertRuleTable.vue @@ -49,7 +49,7 @@ {{ $t('project.metrics.metrics') }} {{ $t('overall.logs') }} - SNMP TRAP + SNMP trap - {{formatThreshold(scope.row[item.prop], scope.row.unit)}} diff --git a/nezha-fronted/src/components/common/table/asset/assetTable.vue b/nezha-fronted/src/components/common/table/asset/assetTable.vue index 8724bd4fa..1acbe1953 100644 --- a/nezha-fronted/src/components/common/table/asset/assetTable.vue +++ b/nezha-fronted/src/components/common/table/asset/assetTable.vue @@ -84,13 +84,14 @@ - 正常 + + {{ $t('overall.normal') }} - 不正常 + {{ $t('overall.unusual') }} - 认证失败 + {{ $t('overall.AuthenticationFailed') }} -