// 节点IP阈值 Vue.component("node-ip-address-thresholds-box", { props: ["v-thresholds"], data: function () { let thresholds = this.vThresholds if (thresholds == null) { thresholds = [] } else { thresholds.forEach(function (v) { if (v.items == null) { v.items = [] } if (v.actions == null) { v.actions = [] } }) } return { editingIndex: -1, thresholds: thresholds, addingThreshold: { items: [], actions: [] }, isAdding: false, isAddingItem: false, isAddingAction: false, itemCode: "avgRequests", itemReportGroups: [], itemOperator: "lte", itemValue: "", itemDuration: 5, allItems: [ { "name": "平均请求数", "code": "avgRequests", "description": "在单位时间内接收到的平均请求数。", "unit": "个" }, { "name": "平均下行流量", "code": "avgTrafficOut", "description": "在单位时间内发送的下行流量。", "unit": "M" }, { "name": "平均上行流量", "code": "avgTrafficIn", "description": "在单位时间内接收的上行流量。", "unit": "M" }, { "name": "连通性", "code": "connectivity", "description": "通过区域监控得到的连通性数值,取值在0和100之间。", "unit": "%" }, ], allOperators: [ { "name": "小于等于", "code": "lte" }, { "name": "大于", "code": "gt" }, { "name": "不等于", "code": "neq" }, { "name": "小于", "code": "lt" }, { "name": "大于等于", "code": "gte" } ], allActions: [ { "name": "上线", "code": "up", "description": "上线当前IP。" }, { "name": "下线", "code": "down", "description": "下线当前IP。" }, { "name": "通知", "code": "notify", "description": "发送已达到阈值通知。" } ], actionCode: "up" } }, methods: { add: function () { this.isAdding = !this.isAdding }, cancel: function () { this.isAdding = false this.editingIndex = -1 this.addingThreshold = { items: [], actions: [] } }, confirm: function () { if (this.addingThreshold.items.length == 0) { teaweb.warn("需要至少添加一个阈值") return } if (this.addingThreshold.actions.length == 0) { teaweb.warn("需要至少添加一个动作") return } if (this.editingIndex >= 0) { this.thresholds[this.editingIndex].items = this.addingThreshold.items this.thresholds[this.editingIndex].actions = this.addingThreshold.actions } else { this.thresholds.push({ items: this.addingThreshold.items, actions: this.addingThreshold.actions }) } // 还原 this.cancel() }, remove: function (index) { this.cancel() this.thresholds.$remove(index) }, update: function (index) { this.editingIndex = index this.addingThreshold = { items: this.thresholds[index].items.$copy(), actions: this.thresholds[index].actions.$copy() } this.isAdding = true }, addItem: function () { this.isAddingItem = !this.isAddingItem let that = this setTimeout(function () { that.$refs.itemValue.focus() }, 100) }, cancelItem: function () { this.isAddingItem = false this.itemCode = "avgRequests" this.itmeOperator = "lte" this.itemValue = "" this.itemDuration = "1" this.itemReportGroups = [] }, confirmItem: function () { if (this.itemDuration.length == 0) { let that = this teaweb.warn("请输入统计周期", function () { that.$refs.itemDuration.focus() }) return } let itemDuration = parseInt(this.itemDuration) if (isNaN(itemDuration) || itemDuration <= 0) { teaweb.warn("请输入正确的统计周期", function () { that.$refs.itemDuration.focus() }) return } if (this.itemValue.length == 0) { let that = this teaweb.warn("请输入对比值", function () { that.$refs.itemValue.focus() }) return } let itemValue = parseFloat(this.itemValue) if (isNaN(itemValue)) { teaweb.warn("请输入正确的对比值", function () { that.$refs.itemValue.focus() }) return } let options = {} switch (this.itemCode) { case "connectivity": // 连通性校验 if (itemValue > 100) { let that = this teaweb.warn("连通性对比值不能超过100", function () { that.$refs.itemValue.focus() }) return } options["groups"] = this.itemReportGroups break } // 添加 this.addingThreshold.items.push({ item: this.itemCode, operator: this.itemOperator, value: itemValue, duration: itemDuration, durationUnit: "minute", options: options }) // 还原 this.cancelItem() }, removeItem: function (index) { this.cancelItem() this.addingThreshold.items.$remove(index) }, changeReportGroups: function (groups) { this.itemReportGroups = groups }, itemName: function (item) { let result = "" this.allItems.forEach(function (v) { if (v.code == item) { result = v.name } }) return result }, itemUnitName: function (itemCode) { let result = "" this.allItems.forEach(function (v) { if (v.code == itemCode) { result = v.unit } }) return result }, itemDurationUnitName: function (unit) { switch (unit) { case "minute": return "分钟" case "second": return "秒" case "hour": return "小时" case "day": return "天" } return unit }, itemOperatorName: function (operator) { let result = "" this.allOperators.forEach(function (v) { if (v.code == operator) { result = v.name } }) return result }, addAction: function () { this.isAddingAction = !this.isAddingAction }, cancelAction: function () { this.isAddingAction = false this.actionCode = "up" }, confirmAction: function () { // 是否已存在 let exists = false let that = this this.addingThreshold.actions.forEach(function (v) { if (v.action == that.actionCode) { exists = true } }) if (exists) { teaweb.warn("此动作已经添加过了,无需重复添加") return } this.addingThreshold.actions.push({ action: this.actionCode, options: {} }) // 还原 this.cancelAction() }, removeAction: function (index) { this.cancelAction() this.addingThreshold.actions.$remove(index) }, actionName: function (actionCode) { let result = "" this.allActions.forEach(function (v) { if (v.code == actionCode) { result = v.name } }) return result } }, template: `
| 阈值 | 动作 |
|---|---|
|
|
|