From 0d05ad85f2ef5a07aa609a92b07782dd78dd1cb9 Mon Sep 17 00:00:00 2001 From: Ulric Qin Date: Wed, 12 Oct 2022 18:29:59 +0800 Subject: [PATCH] callback_add callback_del --- src/webapi/router/router_alert_rule.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/webapi/router/router_alert_rule.go b/src/webapi/router/router_alert_rule.go index 2940b729..5fd13f2e 100644 --- a/src/webapi/router/router_alert_rule.go +++ b/src/webapi/router/router_alert_rule.go @@ -181,6 +181,7 @@ func alertRulePutByService(c *gin.Context) { type alertRuleFieldForm struct { Ids []int64 `json:"ids"` Fields map[string]interface{} `json:"fields"` + Action string `json:"action"` } // update one field: cluster note severity disabled prom_eval_interval prom_for_duration notify_channels notify_groups notify_recovered notify_repeat_step callbacks runbook_url append_tags @@ -203,6 +204,23 @@ func alertRulePutFields(c *gin.Context) { continue } + if f.Action == "callback_add" { + // 增加一个 callback 地址 + if callbacks, has := f.Fields["callbacks"]; has { + callback := callbacks.(string) + if !strings.Contains(ar.Callbacks, callback) { + f.Fields["callbacks"] = ar.Callbacks + " " + callback + } + } + } + + if f.Action == "callback_del" { + // 删除一个 callback 地址 + if callbacks, has := f.Fields["callbacks"]; has { + f.Fields["callbacks"] = strings.ReplaceAll(ar.Callbacks, callbacks.(string), "") + } + } + ginx.Dangerous(ar.UpdateFieldsMap(f.Fields)) }