Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d2b9b9b3
authored
Oct 28, 2020
by
huangchengyi
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
1.0
parent
76bdf054
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
5 deletions
pkg/common/log_report.go
pkg/message/dingding.go
pkg/common/log_report.go
View file @
d2b9b9b3
...
...
@@ -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"
)
{
//推送到钉钉
result
,
err
:=
message
.
DingDingPush
(
errMsg
)
if
err
!=
nil
||
result
.
Errcode
!=
0
{
logger
.
Error
(
"%s"
,
err
,
result
)
}
go
func
()
{
//推送到钉钉
result
,
err
:=
message
.
DingDingPush
(
errMsg
)
if
err
!=
nil
||
result
.
Errcode
!=
0
{
logger
.
Error
(
"%s"
,
err
,
result
)
}
}()
}
}
else
{
redisCon
:=
gredis
.
Conn
(
"search_w"
)
...
...
pkg/message/dingding.go
View file @
d2b9b9b3
...
...
@@ -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"
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment