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
a072b588
authored
Jun 08, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
接入钉钉群消息已ç以及短信发送
parent
7a6ecd69
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
5 deletions
conf/config.ini
go.mod
pkg/common/function.go
pkg/message/dingding.go
test/test.go
conf/config.ini
View file @
a072b588
[web]
port
=
9000
[message]
api_domain
=
http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str
=
fh6y5t4rr351d2c3bryi
[database]
user_name
=
root
password
=
root
...
...
go.mod
View file @
a072b588
...
...
@@ -8,8 +8,10 @@ require (
github.com/golang/protobuf v1.4.2
github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect
github.com/imroc/req v0.3.0
github.com/jinzhu/gorm v1.9.12
github.com/micro/go-micro/v2 v2.5.0
github.com/prometheus/common v0.6.0
github.com/smartystreets/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect
...
...
pkg/common/function.go
0 → 100644
View file @
a072b588
package
common
import
(
"crypto/md5"
"encoding/hex"
)
// Md5 md5()
func
Md5
(
str
string
)
string
{
hash
:=
md5
.
New
()
hash
.
Write
([]
byte
(
str
))
return
hex
.
EncodeToString
(
hash
.
Sum
(
nil
))
}
\ No newline at end of file
pkg/message/dingding.go
0 → 100644
View file @
a072b588
package
message
import
(
"encoding/json"
"fmt"
"github.com/imroc/req"
"github.com/prometheus/common/log"
"net/http"
"net/url"
"search_server/pkg/common"
"search_server/pkg/config"
"strconv"
"time"
)
//发送钉钉消息的包
type
DingDingRequest
struct
{
MsgType
string
`json:"msgtype"`
Text
map
[
string
]
string
`json:"text"`
IsAtAll
bool
`json:"isAtAll"`
}
//普通发短信
func
SendMessage
(
mobile
int64
,
keyWord
string
,
content
map
[
string
]
interface
{})
{
//es连接告警的keyword是 es_connect_monitor
if
mobile
!=
0
{
timeNow
:=
time
.
Now
()
.
Unix
()
requestContent
,
_
:=
json
.
Marshal
(
content
)
requestTel
,
_
:=
json
.
Marshal
([]
int64
{
mobile
})
apiDomain
:=
config
.
Get
(
"message.api_domain"
)
.
String
()
apiMd5Str
:=
config
.
Get
(
"message.api_md5_str"
)
.
String
()
resp
,
err
:=
http
.
PostForm
(
apiDomain
,
url
.
Values
{
"data"
:
{
string
(
requestContent
)},
"touser"
:
{
string
(
requestTel
)},
"keyword"
:
{
keyWord
},
"k1"
:
{
strconv
.
FormatInt
(
timeNow
,
10
)},
"k2"
:
{
common
.
Md5
(
common
.
Md5
(
strconv
.
FormatInt
(
timeNow
,
10
))
+
apiMd5Str
)},
"is_ignore"
:
{},
})
if
err
!=
nil
{
fmt
.
Print
(
err
)
}
defer
resp
.
Body
.
Close
()
}
}
func
SendDingdingMessage
(
content
string
)
{
var
(
requestData
DingDingRequest
apiUrl
,
token
string
//resp *req.Resp
err
error
)
//todo: 需要配置一个搜索服务的专属警告
content
=
"仓储同步告警 : "
+
content
requestData
.
MsgType
=
"text"
requestData
.
Text
=
map
[
string
]
string
{
"content"
:
content
,
}
req
.
Debug
=
false
requestData
.
IsAtAll
=
false
token
=
"3c048caba514a5252aa8bdbb3e10994def6409a2f0d5212e5626c1a071152ec3"
apiUrl
=
"https://api.ichunt.com/public/dingtalkrobot?access_token="
+
token
params
:=
req
.
BodyJSON
(
requestData
)
_
,
err
=
req
.
Post
(
apiUrl
,
params
)
if
err
!=
nil
{
log
.
Error
(
err
)
}
}
test/test.go
View file @
a072b588
...
...
@@ -2,11 +2,9 @@ package main
import
(
"flag"
"fmt"
"gopkg.in/mgo.v2/bson"
"log"
"search_server/boot"
"search_server/pkg/m
ongo
"
"search_server/pkg/m
essage
"
)
func
main
()
{
...
...
@@ -16,7 +14,6 @@ func main() {
if
err
:=
boot
.
Boot
(
path
);
err
!=
nil
{
log
.
Println
(
err
)
}
count
,
_
:=
mongo
.
GetDB
()
.
C
(
"lie_configs"
)
.
Find
(
bson
.
M
{})
.
Count
()
fmt
.
Println
(
count
)
message
.
SendMessage
(
18825159814
,
"es_connect_monitor"
,
map
[
string
]
interface
{}{
"ip"
:
"127.0.0.1"
})
}
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