Commit a072b588 by mushishixian

接入钉钉群消息已ç以及短信发送

parent 7a6ecd69
[web] [web]
port = 9000 port = 9000
[message]
api_domain = http://api.ichunt.com/msg/sendMessageByAuto
api_md5_str = fh6y5t4rr351d2c3bryi
[database] [database]
user_name = root user_name = root
password = root password = root
......
...@@ -8,8 +8,10 @@ require ( ...@@ -8,8 +8,10 @@ require (
github.com/golang/protobuf v1.4.2 github.com/golang/protobuf v1.4.2
github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible github.com/gomodule/redigo v2.0.1-0.20180401191855-9352ab68be13+incompatible
github.com/gopherjs/gopherjs v0.0.0-20181103185306-d547d1d9531e // indirect 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/jinzhu/gorm v1.9.12
github.com/micro/go-micro/v2 v2.5.0 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/assertions v0.0.0-20190116191733-b6c0e53d7304 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/stretchr/testify v1.5.1 // indirect github.com/stretchr/testify v1.5.1 // indirect
......
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
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)
}
}
...@@ -2,11 +2,9 @@ package main ...@@ -2,11 +2,9 @@ package main
import ( import (
"flag" "flag"
"fmt"
"gopkg.in/mgo.v2/bson"
"log" "log"
"search_server/boot" "search_server/boot"
"search_server/pkg/mongo" "search_server/pkg/message"
) )
func main() { func main() {
...@@ -16,7 +14,6 @@ func main() { ...@@ -16,7 +14,6 @@ func main() {
if err := boot.Boot(path); err != nil { if err := boot.Boot(path); err != nil {
log.Println(err) log.Println(err)
} }
count, _ := mongo.GetDB().C("lie_configs").Find(bson.M{}).Count() message.SendMessage(18825159814, "es_connect_monitor", map[string]interface{}{"ip": "127.0.0.1"})
fmt.Println(count)
} }
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