(text, WebhookUrl, logsign string, contentType string)
| 13 | ) |
| 14 | |
| 15 | func PostToWebhook(text, WebhookUrl, logsign string, contentType string) string { |
| 16 | logs.Info(logsign, "[Webhook]", text) |
| 17 | JsonMsg := bytes.NewReader([]byte(text)) |
| 18 | var tr *http.Transport |
| 19 | if proxyUrl := beego.AppConfig.String("proxy"); proxyUrl != "" { |
| 20 | proxy := func(_ *http.Request) (*url.URL, error) { |
| 21 | return url.Parse(proxyUrl) |
| 22 | } |
| 23 | tr = &http.Transport{ |
| 24 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| 25 | Proxy: proxy, |
| 26 | } |
| 27 | } else { |
| 28 | tr = &http.Transport{ |
| 29 | TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, |
| 30 | } |
| 31 | } |
| 32 | client := &http.Client{Transport: tr} |
| 33 | if contentType == "" { |
| 34 | contentType = "application/json" |
| 35 | } |
| 36 | res, err := client.Post(WebhookUrl, contentType, JsonMsg) |
| 37 | if err != nil { |
| 38 | logs.Error(logsign, "[Webhook]", err.Error()) |
| 39 | } |
| 40 | |
| 41 | result, err := ioutil.ReadAll(res.Body) |
| 42 | if err != nil { |
| 43 | logs.Error(logsign, "[Webhook]", err.Error()) |
| 44 | } |
| 45 | defer res.Body.Close() |
| 46 | models.AlertToCounter.WithLabelValues("webhook").Add(1) |
| 47 | ChartsJson.Webhook += 1 |
| 48 | logs.Info(logsign, "[Webhook]", string(result)) |
| 49 | return string(result) |
| 50 | } |
no test coverage detected