mirror of
https://github.com/TeaOSLab/EdgeAdmin.git
synced 2025-11-06 23:00:25 +08:00
IP阈值动作增加WebHook
This commit is contained in:
@@ -103,7 +103,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
}
|
||||
|
||||
// IP地址阈值
|
||||
// IP地址阈值项目
|
||||
ipAddrThresholdItemsJSON, err := json.Marshal(nodeconfigs.FindAllIPAddressThresholdItems())
|
||||
if err != nil {
|
||||
logs.Println("ComponentsAction marshal ip addr threshold items failed: " + err.Error())
|
||||
@@ -113,6 +113,16 @@ func (this *ComponentsAction) RunGet(params struct{}) {
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
}
|
||||
|
||||
// IP地址阈值动作
|
||||
ipAddrThresholdActionsJSON, err := json.Marshal(nodeconfigs.FindAllIPAddressThresholdActions())
|
||||
if err != nil {
|
||||
logs.Println("ComponentsAction marshal ip addr threshold actions failed: " + err.Error())
|
||||
} else {
|
||||
buffer.WriteString("window.IP_ADDR_THRESHOLD_ACTIONS = ")
|
||||
buffer.Write(ipAddrThresholdActionsJSON)
|
||||
buffer.Write([]byte{'\n', '\n'})
|
||||
}
|
||||
|
||||
componentsData = buffer.Bytes()
|
||||
|
||||
// ETag
|
||||
|
||||
@@ -55,31 +55,11 @@ Vue.component("node-ip-address-thresholds-box", {
|
||||
"code": "gte"
|
||||
}
|
||||
],
|
||||
allActions: [
|
||||
{
|
||||
"name": "上线",
|
||||
"code": "up",
|
||||
"description": "上线当前IP。"
|
||||
},
|
||||
{
|
||||
"name": "下线",
|
||||
"code": "down",
|
||||
"description": "下线当前IP。"
|
||||
},
|
||||
{
|
||||
"name": "通知",
|
||||
"code": "notify",
|
||||
"description": "发送已达到阈值通知。"
|
||||
},
|
||||
{
|
||||
"name": "切换",
|
||||
"code": "switch",
|
||||
"description": "在DNS中记录中将IP切换到指定的备用IP。"
|
||||
},
|
||||
],
|
||||
allActions: window.IP_ADDR_THRESHOLD_ACTIONS,
|
||||
|
||||
actionCode: "up",
|
||||
actionBackupIPs: ""
|
||||
actionBackupIPs: "",
|
||||
actionWebHookURL: ""
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -262,6 +242,7 @@ Vue.component("node-ip-address-thresholds-box", {
|
||||
this.isAddingAction = false
|
||||
this.actionCode = "up"
|
||||
this.actionBackupIPs = ""
|
||||
this.actionWebHookURL = ""
|
||||
},
|
||||
confirmAction: function () {
|
||||
this.doConfirmAction(false)
|
||||
@@ -310,6 +291,20 @@ Vue.component("node-ip-address-thresholds-box", {
|
||||
return
|
||||
}
|
||||
break
|
||||
case "webHook":
|
||||
if (this.actionWebHookURL.length ==0) {
|
||||
teaweb.warn("请输入WebHook URL", function () {
|
||||
that.$refs.webHookURL.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
if (!this.actionWebHookURL.match(/^(http|https):\/\//i)) {
|
||||
teaweb.warn("URL开头必须是http://或者https://", function () {
|
||||
that.$refs.webHookURL.focus()
|
||||
})
|
||||
return
|
||||
}
|
||||
options["url"] = this.actionWebHookURL
|
||||
}
|
||||
|
||||
this.addingThreshold.actions.push({
|
||||
@@ -348,6 +343,7 @@ Vue.component("node-ip-address-thresholds-box", {
|
||||
->
|
||||
<span v-for="(action, actionIndex) in threshold.actions">{{actionName(action.action)}}
|
||||
<span v-if="action.action == 'switch'">到{{action.options.ips.join(", ")}}</span>
|
||||
<span v-if="action.action == 'webHook'" class="small grey">({{action.options.url}})</span>
|
||||
<span v-if="actionIndex != threshold.actions.length - 1" style="font-style: italic">AND </span></span>
|
||||
|
||||
<a href="" title="修改" @click.prevent="update(index)"><i class="icon pencil small"></i></a>
|
||||
@@ -439,6 +435,7 @@ Vue.component("node-ip-address-thresholds-box", {
|
||||
<div v-for="(action, index) in addingThreshold.actions" class="ui label basic small" style="margin-bottom: 0.5em">
|
||||
{{actionName(action.action)}}
|
||||
<span v-if="action.action == 'switch'">到{{action.options.ips.join(", ")}}</span>
|
||||
<span v-if="action.action == 'webHook'" class="small grey">({{action.options.url}})</span>
|
||||
<a href="" title="删除" @click.prevent="removeAction(index)"><i class="icon remove small"></i></a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -455,6 +452,8 @@ Vue.component("node-ip-address-thresholds-box", {
|
||||
<p class="comment" v-for="action in allActions" v-if="action.code == actionCode">{{action.description}}</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- 切换 -->
|
||||
<tr v-if="actionCode == 'switch'">
|
||||
<td>备用IP *</td>
|
||||
<td>
|
||||
@@ -462,6 +461,15 @@ Vue.component("node-ip-address-thresholds-box", {
|
||||
<p class="comment">每行一个备用IP。</p>
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<!-- WebHook -->
|
||||
<tr v-if="actionCode == 'webHook'">
|
||||
<td>URL *</td>
|
||||
<td>
|
||||
<input type="text" maxlength="1000" placeholder="https://..." v-model="actionWebHookURL" ref="webHookURL" @keyup.enter="confirmAction()" @keypress.enter.prevent="1"/>
|
||||
<p class="comment">完整的URL,比如<code-label>https://example.com/webhook/api</code-label>,系统会在触发阈值的时候通过GET调用此URL。</p>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
<div style="margin-top: 0.8em">
|
||||
<button class="ui button tiny" type="button" @click.prevent="confirmAction">确定</button>
|
||||
|
||||
@@ -41,23 +41,7 @@ Vue.component("node-ip-address-thresholds-view", {
|
||||
"code": "gte"
|
||||
}
|
||||
],
|
||||
allActions: [
|
||||
{
|
||||
"name": "上线",
|
||||
"code": "up",
|
||||
"description": "上线当前IP。"
|
||||
},
|
||||
{
|
||||
"name": "下线",
|
||||
"code": "down",
|
||||
"description": "下线当前IP。"
|
||||
},
|
||||
{
|
||||
"name": "通知",
|
||||
"code": "notify",
|
||||
"description": "发送已达到阈值通知。"
|
||||
}
|
||||
]
|
||||
allActions: window.IP_ADDR_THRESHOLD_ACTIONS
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@@ -123,6 +107,7 @@ Vue.component("node-ip-address-thresholds-view", {
|
||||
->
|
||||
<span v-for="(action, actionIndex) in threshold.actions">{{actionName(action.action)}}
|
||||
<span v-if="action.action == 'switch'">到{{action.options.ips.join(", ")}}</span>
|
||||
<span v-if="action.action == 'webHook'" class="small grey">({{action.options.url}})</span>
|
||||
<span v-if="actionIndex != threshold.actions.length - 1" style="font-style: italic">AND </span></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user