package controller import ( "github.com/gin-gonic/gin" "github.com/prometheus/alertmanager/notify/webhook" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/bean/entity" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/client" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/common/conf" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/pkg/beagle/resp" "gitlab.wodcloud.com/smart-operation/so-operation-api/src/service" "go.uber.org/zap" ) // AlertWebhook 回调 func AlertWebhook(c *gin.Context) { var req webhook.Message conf.Logger.Info("------>webhook.start------>") if err := c.ShouldBind(&req); err != nil { SendJsonResponse(c, resp.InvalidParam.TranslateError(err), nil) return } conf.Logger.Info("------>webhook.Message------>", zap.Any("message", req)) svc := service.AlertWebhookSvc{User: entity.SystemUserInfo{ Name: "prometheus", SystemAccount: "prometheus", OrganizationId: "", State: 1, }} db, err := client.GetDbClient() if err != nil { SendJsonResponse(c, resp.DbConnectError.WithError(err), nil) return } err = svc.AlertWebhook(db.NewSession(), req) if err != nil { SendJsonResponse(c, resp.FAIL.WithError(err), nil) return } SendJsonResponse(c, resp.OK, req) }