Commit d2b9b9b3 by huangchengyi

1.0

parent 76bdf054
......@@ -52,11 +52,13 @@ func AnalyzeSearchError(ctx *gin.Context,code int, ip, errMsg, file, line, metho
unitSupplierLogCode := config.Cfg.Section("UNIT_SUPPLIER_LOG_CODE").KeysHash()
if unitSupplierLogCode[codeStr] == "" {
if !strings.Contains(strings.ToUpper(errMsg), "SOAP-ERROR") {
go func() {
//推送到钉钉
result, err := message.DingDingPush(errMsg)
if err != nil || result.Errcode != 0 {
logger.Error("%s", err, result)
}
}()
}
} else {
redisCon := gredis.Conn("search_w")
......
......@@ -6,6 +6,7 @@ import (
"github.com/tidwall/gjson"
"search_server/pkg/config"
"strings"
"time"
)
//发送钉钉消息的包
......@@ -20,8 +21,36 @@ type DingDingResponse struct {
Errmsg string `json:"errmsg"`
}
//直接发送,服务器不存在ip要异步推送
func DingDingPush(content string) (result DingDingResponse, err error) {
accessToken := config.Get("DINGDING.SEARCH_API_MONITOR").String()
webhook := "http://api.ichunt.com/public/dingtalkrobot?access_token=" + accessToken
data := make(map[string]interface{})
data["msgtype"] = "text"
data["text"] = map[string]string{
"content": content,
}
req.Debug = false
dataStrByte, _ := json.Marshal(data)
dataStr := string(dataStrByte)
dataStr = strings.Replace(dataStr, "\\", "\\\\", -1)
params := req.BodyJSON(dataStr)
req.SetTimeout(2 * time.Second) //2秒超时
resp, err := req.Post(webhook, params, req.Header{
"Content-Type": "application/json",
"charset": "UTF-8",
})
if resp == nil {
return
}
result.Errcode = int(gjson.Get(resp.String(), "errcode").Int())
result.Errmsg = gjson.Get(resp.String(), "errmsg").String()
return
}
//直接发送,服务器存在ip情况
func DingDingIpPush(content string) (result DingDingResponse, err error) {
accessToken := config.Get("DINGDING.SEARCH_API_MONITOR").String()
webhook := "https://oapi.dingtalk.com/robot/send?access_token=" + accessToken
data := make(map[string]interface{})
data["msgtype"] = "text"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment