2019-12-24 17:31:51 +08:00
|
|
|
|
<template>
|
2021-01-18 18:58:57 +08:00
|
|
|
|
<div class="right-box right-box-alert-config" v-clickoutside="{obj:editAlertRule,func:clickOutside}">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!-- begin--顶部按钮-->
|
2020-10-15 14:27:46 +08:00
|
|
|
|
<div class="right-box-top-btns right-box-form-delete">
|
2020-12-08 21:53:37 +08:00
|
|
|
|
<button @click="del" class="nz-btn nz-btn-size-normal nz-btn-size-alien" id="alert-box-del" type="button" v-has="'rule_delete'" v-if="alertRule.id">
|
2020-09-10 17:00:32 +08:00
|
|
|
|
<span class="right-box-top-btn-icon"><i class="nz-icon nz-icon-delete"></i></span>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<span class="right-box-top-btn-txt">{{$t('overall.delete')}}</span>
|
|
|
|
|
|
</button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<!-- end--顶部按钮-->
|
2019-12-24 17:31:51 +08:00
|
|
|
|
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!-- begin--标题-->
|
|
|
|
|
|
<div class="right-box-title">{{editAlertRule.id ? $t("alert.config.editAlertConfig") + " ID:" + editAlertRule.id : $t("alert.config.createAlertConfig")}}</div>
|
|
|
|
|
|
<!-- end--标题-->
|
2019-12-24 17:31:51 +08:00
|
|
|
|
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!-- begin--表单-->
|
2020-12-14 20:25:24 +08:00
|
|
|
|
<div class="right-box-form-box">
|
2021-02-09 15:14:19 +08:00
|
|
|
|
<el-form class="right-box-form right-box-form-left" :model="editAlertRule" label-position = "top" label-width="120px" :rules="rules" ref="alertRuleForm">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!--alertName-->
|
|
|
|
|
|
<el-form-item :label='$t("alert.config.name")' prop="alertName">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-input placeholder="" maxlength="64" show-word-limit v-model="editAlertRule.alertName" size="small" id="alert-box-input-name"></el-input>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
</el-form-item>
|
2021-03-19 11:12:09 +08:00
|
|
|
|
<el-form-item style="width: calc(100% - 15px);margin-left: 15px" :label='$t("alert.config.expr")' prop="expr">
|
2020-10-15 14:27:46 +08:00
|
|
|
|
<promql-input
|
|
|
|
|
|
ref="promql"
|
|
|
|
|
|
:expression-list.sync="expressions"
|
|
|
|
|
|
:index="0"
|
|
|
|
|
|
:styleType="2"
|
2021-02-25 15:06:15 +08:00
|
|
|
|
:required="true"
|
|
|
|
|
|
@change="metricChange"
|
2021-03-19 11:12:09 +08:00
|
|
|
|
:plugins="['metric-selector','metric-input']"
|
2021-02-04 11:21:00 +08:00
|
|
|
|
id="alert-box-input-promql"
|
2020-10-15 14:27:46 +08:00
|
|
|
|
></promql-input>
|
2021-02-25 15:06:15 +08:00
|
|
|
|
</el-form-item>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!--threshold-->
|
2021-02-09 15:14:19 +08:00
|
|
|
|
<el-form-item :label="$t('alert.config.threshold')" prop="threshold" style="display: inline-block;">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-input type="text" placeholder="" v-model="editAlertRule.threshold" size="small" id="alert-box-input-threshold">
|
2021-02-25 09:50:14 +08:00
|
|
|
|
<el-select popper-class="config-dropdown threshold-dropdown" v-model="editAlertRule.operator" placeholder="" size="small" id="alert-box-input-operator" slot="prepend" class="input-with-select">
|
2021-02-23 16:21:49 +08:00
|
|
|
|
<el-option :id="'operator-'+item.key" v-for="item in operators" :key="item.value" :label="item.label" :value="item.value"></el-option>
|
|
|
|
|
|
</el-select>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!--unit-->
|
|
|
|
|
|
<el-form-item :label="$t('alert.config.unit')" prop="unit">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-cascader filterable placeholder="" popper-class="no-style-class unit-popper-class" size="small" style="width: 100%" id="alert-box-input-unit"
|
2020-07-24 19:22:52 +08:00
|
|
|
|
:options="unitOptions"
|
|
|
|
|
|
:props="{ expandTrigger: 'click',emitPath:false }"
|
|
|
|
|
|
:show-all-levels="false"
|
|
|
|
|
|
v-model="editAlertRule.unit"
|
|
|
|
|
|
>
|
|
|
|
|
|
</el-cascader>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!--last-->
|
|
|
|
|
|
<el-form-item :label="$t('alert.config.for')" prop="last">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-input type="text" placeholder="" v-model.number="editAlertRule.last" size="small" id="alert-box-input-last">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<template slot="append">{{$t('alert.config.second')}}</template>
|
|
|
|
|
|
</el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!--severity-->
|
|
|
|
|
|
<el-form-item :label="$t('alert.severity')" prop="severity">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-select popper-class="config-dropdown" v-model="editAlertRule.severity" placeholder="" size="small" id="alert-box-input-severity">
|
2020-07-31 20:57:04 +08:00
|
|
|
|
<el-option :id="'alert-severity-'+item.value" v-for="item in $CONSTANTS.alertMessage.severityData" :key="item.value" :label="item.label" :value="item.value">
|
|
|
|
|
|
<template v-if="!item.isEdit">{{item.label}}</template>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<span class="config-dropdown-label-input" v-if="item.isEdit" @click.stop>
|
2020-07-31 20:57:04 +08:00
|
|
|
|
<el-input type="text" v-model="item.value" size="mini"></el-input>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
2020-11-12 09:54:42 +08:00
|
|
|
|
<div class="rule-severity-remark">
|
|
|
|
|
|
<i class="nz-icon nz-icon-info-normal"></i>
|
|
|
|
|
|
<div>
|
|
|
|
|
|
<p>{{$t('alert.P1Rule')}}</p>
|
|
|
|
|
|
<p>{{$t('alert.P2Rule')}}</p>
|
|
|
|
|
|
<p>{{$t('alert.P3Rule')}}</p>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!--receiver-->
|
|
|
|
|
|
<el-form-item :label="$t('config.account.receiver')" prop="receiver">
|
|
|
|
|
|
<el-select
|
2021-02-04 11:21:00 +08:00
|
|
|
|
id="alert-box-input-receiver"
|
2020-07-24 19:22:52 +08:00
|
|
|
|
v-model.trim="editAlertRule.receiverShow"
|
|
|
|
|
|
placeholder=""
|
|
|
|
|
|
multiple
|
|
|
|
|
|
filterable
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
value-key="userId"
|
|
|
|
|
|
popper-class="no-style-class"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-option
|
|
|
|
|
|
v-for="item in userData"
|
|
|
|
|
|
:key="item.userId"
|
|
|
|
|
|
:label="item.username"
|
|
|
|
|
|
:value="item.userId">
|
|
|
|
|
|
</el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!--summary-->
|
|
|
|
|
|
<el-form-item :label="$t('alert.summary')" prop="summary">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-input maxlength="512" rows="3" type="textarea" show-word-limit placeholder="" v-model="editAlertRule.summary" size="small" id="alert-box-input-summary"></el-input>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<!--description-->
|
|
|
|
|
|
<el-form-item :label="$t('alert.description')" prop="description">
|
2021-02-04 11:21:00 +08:00
|
|
|
|
<el-input maxlength="512" rows="4" show-word-limit type="textarea" placeholder="" v-model="editAlertRule.description" size="small" id="alert-box-input-description"></el-input>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
2020-12-14 20:25:24 +08:00
|
|
|
|
</div>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!-- end--表单-->
|
2020-01-16 18:11:15 +08:00
|
|
|
|
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<!--底部按钮-->
|
|
|
|
|
|
<div class="right-box-bottom-btns">
|
2021-01-18 18:58:57 +08:00
|
|
|
|
<button v-cancel="{obj:editAlertRule,func:esc}" id="alert-box-esc" class="nz-btn nz-btn-size-normal-new nz-btn-style-light-new">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<span>{{$t('overall.cancel')}}</span>
|
|
|
|
|
|
</button>
|
2021-01-21 17:29:29 +08:00
|
|
|
|
<button :class="{'nz-btn-disabled':prevent_opt.save}" :disabled="prevent_opt.save" @click="save" class="nz-btn nz-btn-size-normal-new nz-btn-style-normal-new" id="alert-box-save">
|
2020-07-24 19:22:52 +08:00
|
|
|
|
<span>{{$t('overall.save')}}</span>
|
|
|
|
|
|
</button>
|
2019-12-24 17:31:51 +08:00
|
|
|
|
</div>
|
2020-07-24 19:22:52 +08:00
|
|
|
|
</div>
|
2019-12-24 17:31:51 +08:00
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
2021-03-19 18:52:19 +08:00
|
|
|
|
import chartDataFormat from '../../charts/chartDataFormat'
|
|
|
|
|
|
import promqlInput from '../../page/dashboard/explore/promqlInput'
|
|
|
|
|
|
import { nzNumber } from '../js/validate'
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'alertConfigBox',
|
|
|
|
|
|
props: {
|
|
|
|
|
|
alertRule: Object
|
|
|
|
|
|
},
|
|
|
|
|
|
components: {
|
|
|
|
|
|
'promql-input': promqlInput
|
|
|
|
|
|
},
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
promqlCount: 1,
|
|
|
|
|
|
promqlKeys: [0],
|
|
|
|
|
|
expressions: [''],
|
|
|
|
|
|
legends: [''],
|
2020-07-03 11:45:54 +08:00
|
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
|
editAlertRule: {},
|
|
|
|
|
|
rules: {
|
|
|
|
|
|
alertName: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
|
],
|
|
|
|
|
|
expr: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
|
|
|
|
|
|
],
|
|
|
|
|
|
last: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
|
|
|
|
|
|
{ type: 'number', message: this.$t('validate.number') }
|
|
|
|
|
|
],
|
|
|
|
|
|
severity: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'change' }
|
|
|
|
|
|
],
|
|
|
|
|
|
summary: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
|
],
|
|
|
|
|
|
operator: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
|
|
|
|
|
],
|
|
|
|
|
|
unit: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' }
|
2020-06-04 19:14:04 +08:00
|
|
|
|
],
|
2021-03-19 18:52:19 +08:00
|
|
|
|
threshold: [
|
|
|
|
|
|
{ required: true, message: this.$t('validate.required'), trigger: 'blur' },
|
|
|
|
|
|
{ validator: nzNumber, trigger: 'blur' }
|
|
|
|
|
|
]
|
|
|
|
|
|
},
|
|
|
|
|
|
operators: [
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '==',
|
|
|
|
|
|
value: '=='
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '!=',
|
|
|
|
|
|
value: '!='
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '>',
|
|
|
|
|
|
value: '>'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '<',
|
|
|
|
|
|
value: '<'
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '>=',
|
|
|
|
|
|
value: '>='
|
|
|
|
|
|
},
|
|
|
|
|
|
{
|
|
|
|
|
|
label: '<=',
|
|
|
|
|
|
value: '<='
|
|
|
|
|
|
}
|
|
|
|
|
|
],
|
|
|
|
|
|
unitOptions: chartDataFormat.unitOptions(),
|
2020-07-31 20:57:04 +08:00
|
|
|
|
|
2021-03-19 18:52:19 +08:00
|
|
|
|
userData: []
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
clickOutside () {
|
|
|
|
|
|
this.esc(false)
|
2019-12-24 17:31:51 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
esc (refresh) {
|
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
|
this.$emit('close', refresh)
|
|
|
|
|
|
},
|
|
|
|
|
|
save () {
|
|
|
|
|
|
if (this.prevent_opt.save) { return } ;
|
|
|
|
|
|
this.prevent_opt.save = true
|
|
|
|
|
|
this.editAlertRule.expr = this.expressions[0]
|
|
|
|
|
|
this.$refs.alertRuleForm.validate((valid) => {
|
|
|
|
|
|
if (valid) {
|
|
|
|
|
|
this.editAlertRule.receiver = this.editAlertRule.receiverShow.join(',')
|
|
|
|
|
|
if (this.editAlertRule.id) {
|
|
|
|
|
|
this.$put('alert/rule', this.editAlertRule).then(response => {
|
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
|
this.esc(true)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2020-01-02 18:10:24 +08:00
|
|
|
|
} else {
|
2021-03-19 18:52:19 +08:00
|
|
|
|
this.$post('alert/rule', this.editAlertRule).then(response => {
|
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
this.$message({ duration: 1000, type: 'success', message: this.$t('tip.saveSuccess') })
|
|
|
|
|
|
this.esc(true)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.msg)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2020-01-02 18:10:24 +08:00
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
|
return false
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
del () {
|
|
|
|
|
|
if (this.prevent_opt.save) { return } ;
|
|
|
|
|
|
this.prevent_opt.save = true
|
|
|
|
|
|
this.$confirm(this.$t('tip.confirmDelete'), {
|
|
|
|
|
|
confirmButtonText: this.$t('tip.yes'),
|
|
|
|
|
|
cancelButtonText: this.$t('tip.no'),
|
|
|
|
|
|
type: 'warning'
|
|
|
|
|
|
}).then(() => {
|
|
|
|
|
|
this.$delete('alert/rule?ids=' + this.editAlertRule.id).then(response => {
|
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
|
if (response.code === 200) {
|
|
|
|
|
|
this.$message({ type: 'success', message: this.$t('tip.deleteSuccess') })
|
|
|
|
|
|
this.esc(true)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(response.msg)
|
2020-05-06 18:07:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
this.prevent_opt.save = false
|
|
|
|
|
|
})
|
2019-12-24 17:31:51 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
getUserList () {
|
|
|
|
|
|
this.$get('sys/user/list', { pageNo: 1, pageSize: -1 }).then(response => {
|
|
|
|
|
|
if (response.code == 200) {
|
|
|
|
|
|
this.userData = response.data.list
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
2019-12-24 17:31:51 +08:00
|
|
|
|
},
|
2021-03-19 18:52:19 +08:00
|
|
|
|
metricChange (val) {
|
|
|
|
|
|
this.editAlertRule.expr = val
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
mounted () {
|
|
|
|
|
|
this.getUserList()
|
|
|
|
|
|
},
|
|
|
|
|
|
watch: {
|
|
|
|
|
|
alertRule: {
|
|
|
|
|
|
deep: true,
|
|
|
|
|
|
immediate: true,
|
|
|
|
|
|
handler (n, o) {
|
|
|
|
|
|
this.editAlertRule = JSON.parse(JSON.stringify(n))
|
|
|
|
|
|
if (this.editAlertRule.id) {
|
|
|
|
|
|
this.expressions = [this.editAlertRule.expr]
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.expressions.forEach((ex, index) => {
|
|
|
|
|
|
if (ex) {
|
|
|
|
|
|
this.$refs.promql.metricChange(ex)
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
})
|
2019-12-24 17:31:51 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-03-19 18:52:19 +08:00
|
|
|
|
}
|
2019-12-24 17:31:51 +08:00
|
|
|
|
</script>
|
2020-06-04 19:14:04 +08:00
|
|
|
|
<style>
|
|
|
|
|
|
.unit-popper-class{
|
|
|
|
|
|
z-index: 2052 !important;
|
|
|
|
|
|
}
|
2021-02-23 16:21:49 +08:00
|
|
|
|
.input-with-select{
|
|
|
|
|
|
width: 70px !important;
|
|
|
|
|
|
}
|
|
|
|
|
|
.input-with-select #alert-box-input-operator{
|
|
|
|
|
|
padding: 0;
|
|
|
|
|
|
text-align: center;
|
|
|
|
|
|
border-top:1px solid #d0d4dC;
|
|
|
|
|
|
border-bottom:1px solid #d0d4dC;
|
|
|
|
|
|
border-radius: 4px 0 0 4px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.input-with-select #alert-box-input-operator + .el-input__suffix{
|
|
|
|
|
|
display: none;
|
|
|
|
|
|
}
|
2020-06-04 19:14:04 +08:00
|
|
|
|
</style>
|
2020-11-12 09:54:42 +08:00
|
|
|
|
<style scoped>
|
|
|
|
|
|
.rule-severity-remark{
|
|
|
|
|
|
display: inline-flex;
|
2020-11-16 10:40:53 +08:00
|
|
|
|
justify-content: left;
|
2020-11-12 09:54:42 +08:00
|
|
|
|
justify-items: center;
|
|
|
|
|
|
align-items: center;
|
2021-02-09 15:14:19 +08:00
|
|
|
|
width: calc(100% - 46px);
|
2020-11-12 09:54:42 +08:00
|
|
|
|
padding: 10px 15px;
|
2020-11-16 10:40:53 +08:00
|
|
|
|
background: #F6F6F6;
|
|
|
|
|
|
color: #999999;
|
2020-11-12 09:54:42 +08:00
|
|
|
|
margin-top: -13px;
|
|
|
|
|
|
margin-bottom: 18px;
|
2021-02-09 15:14:19 +08:00
|
|
|
|
margin-left: 15px;
|
2020-11-12 09:54:42 +08:00
|
|
|
|
font-size: 14px;
|
|
|
|
|
|
}
|
|
|
|
|
|
.rule-severity-remark .nz-icon-info-normal{
|
|
|
|
|
|
margin-right: 10px;
|
|
|
|
|
|
}
|
2021-03-19 11:12:09 +08:00
|
|
|
|
/deep/ .metric-selector-title{
|
|
|
|
|
|
margin-left: 0 !important;
|
|
|
|
|
|
}
|
2020-11-12 09:54:42 +08:00
|
|
|
|
</style>
|