Commit d2b9b9b3 by huangchengyi

1.0

parent 76bdf054
...@@ -52,11 +52,13 @@ func AnalyzeSearchError(ctx *gin.Context,code int, ip, errMsg, file, line, metho ...@@ -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() unitSupplierLogCode := config.Cfg.Section("UNIT_SUPPLIER_LOG_CODE").KeysHash()
if unitSupplierLogCode[codeStr] == "" { if unitSupplierLogCode[codeStr] == "" {
if !strings.Contains(strings.ToUpper(errMsg), "SOAP-ERROR") { if !strings.Contains(strings.ToUpper(errMsg), "SOAP-ERROR") {
//推送到钉钉 go func() {
result, err := message.DingDingPush(errMsg) //推送到钉钉
if err != nil || result.Errcode != 0 { result, err := message.DingDingPush(errMsg)
logger.Error("%s", err, result) if err != nil || result.Errcode != 0 {
} logger.Error("%s", err, result)
}
}()
} }
} else { } else {
redisCon := gredis.Conn("search_w") redisCon := gredis.Conn("search_w")
......
...@@ -6,6 +6,7 @@ import ( ...@@ -6,6 +6,7 @@ import (
"github.com/tidwall/gjson" "github.com/tidwall/gjson"
"search_server/pkg/config" "search_server/pkg/config"
"strings" "strings"
"time"
) )
//发送钉钉消息的包 //发送钉钉消息的包
...@@ -20,8 +21,36 @@ type DingDingResponse struct { ...@@ -20,8 +21,36 @@ type DingDingResponse struct {
Errmsg string `json:"errmsg"` Errmsg string `json:"errmsg"`
} }
//直接发送,服务器不存在ip要异步推送
func DingDingPush(content string) (result DingDingResponse, err error) { func DingDingPush(content string) (result DingDingResponse, err error) {
accessToken := config.Get("DINGDING.SEARCH_API_MONITOR").String() 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 webhook := "https://oapi.dingtalk.com/robot/send?access_token=" + accessToken
data := make(map[string]interface{}) data := make(map[string]interface{})
data["msgtype"] = "text" 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