diff --git a/controllers/WebAlertRouter.go b/controllers/WebAlertRouter.go index 8f7ae551..a69ed8ef 100644 --- a/controllers/WebAlertRouter.go +++ b/controllers/WebAlertRouter.go @@ -3,8 +3,10 @@ package controllers import ( "PrometheusAlert/models" "encoding/json" - "github.com/astaxie/beego/logs" + "io" "strconv" + + "github.com/astaxie/beego/logs" ) // router @@ -68,9 +70,15 @@ func (c *MainController) AddRouter() { return } WebAlertRouterJson := AlertRouterJson{} - logsign := "[" + LogsSign() + "]" - logs.Info(logsign, string(c.Ctx.Input.RequestBody)) - json.Unmarshal(c.Ctx.Input.RequestBody, &WebAlertRouterJson) + + body, _ := io.ReadAll(c.Ctx.Request.Body) + logsign := "[" + LogsSign() + ",]" + logs.Info(logsign, string(body)) + err := json.Unmarshal(body, &WebAlertRouterJson) + if err != nil { + logs.Error(err) + return + } rules, err := json.Marshal(WebAlertRouterJson.Rules) if WebAlertRouterJson.RouterId == "" { tpl_id_int, _ := strconv.Atoi(WebAlertRouterJson.RouterTplId) diff --git a/views/alertrouter_add.html b/views/alertrouter_add.html index b43a2fed..ef586908 100644 --- a/views/alertrouter_add.html +++ b/views/alertrouter_add.html @@ -314,7 +314,6 @@
} function savetpl(){ - var uname=document.getElementById("rules"); if (uname.value.length==0){ alert('路由规则不能为空'); @@ -351,6 +350,7 @@ var json_data = JSON.stringify(alert_router_json_str); $.ajax({ + contentType: 'application/json', type: "POST", dataType: "json", url: '{{ urlfor "MainController.AddRouter"}}', diff --git a/views/alertrouter_edit.html b/views/alertrouter_edit.html index 8305ef40..a519a16b 100644 --- a/views/alertrouter_edit.html +++ b/views/alertrouter_edit.html @@ -346,6 +346,7 @@ var json_data = JSON.stringify(alert_router_json_str); $.ajax({ + contentType: "application/json", type: "POST", dataType: "json", url: '{{ urlfor "MainController.AddRouter"}}',