MCPcopy Create free account
hub / github.com/feiyu563/PrometheusAlert / PostToWebhook

Function PostToWebhook

controllers/webhook.go:15–50  ·  view source on GitHub ↗
(text, WebhookUrl, logsign string, contentType string)

Source from the content-addressed store, hash-verified

13)
14
15func 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}

Callers 1

Calls 2

stringFunction · 0.85
PostMethod · 0.80

Tested by

no test coverage detected