go 钉钉报警

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了go 钉钉报警相关的知识,希望对你有一定的参考价值。

代码

package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io/ioutil"
    "net/http"
)

const webhook_url = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

func dingToInfo(s string) bool {
    content, data := make(map[string]string), make(map[string]interface{})
    content["content"] = s
    data["msgtype"] = "text"
    data["text"] = content
    b, _ := json.Marshal(data)

    resp, err := http.Post(webhook_url,
        "application/json",
        bytes.NewBuffer(b))
    if err != nil {
        fmt.Println(err)
    }
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    fmt.Println(string(body))
    return true
}

func main()  {
    dingToInfo("报警")
}

以上是关于go 钉钉报警的主要内容,如果未能解决你的问题,请参考以下文章

Nagios 钉钉报警

Zabbix 钉钉报警插件

nagios钉钉报警与邮件报警

zabbix教程4-Zabbix实现钉钉报警

Prometheus+Altermanager钉钉报警

zabbix 3.2 配置阿里云钉钉报警