Commit d6377de9 authored by Node- 门 忠鑫's avatar Node- 门 忠鑫

# 添加切换文件缓存通知

parent 4665c7c9
package file_cache package file_cache
import ( import (
"encoding/json"
"git.quantgroup.cn/DevOps/enoch/service/log" "git.quantgroup.cn/DevOps/enoch/service/log"
"net/http"
"strings"
"sync" "sync"
"time" "time"
) )
...@@ -22,6 +25,7 @@ func (s *switcher) turnOn() { ...@@ -22,6 +25,7 @@ func (s *switcher) turnOn() {
s.state = true s.state = true
s.origin = time.Now().Unix() s.origin = time.Now().Unix()
create() create()
senderDingDing()
} }
} }
...@@ -48,9 +52,16 @@ func (s *switcher) status() bool { ...@@ -48,9 +52,16 @@ func (s *switcher) status() bool {
} }
var cacheSwitcher *switcher var cacheSwitcher *switcher
var alterMsg string
const (
url = "https://oapi.dingtalk.com/robot/send?access_token=9ffab8e4ae5f94e0fbf84aa91c9cb474d9e3d5bd0bb3c2daffe4cdfe0c2cbbc7"
contentType = "application/json;charset=utf-8"
)
func init() { func init() {
cacheSwitcher = &switcher{} cacheSwitcher = &switcher{}
alterMsg = buildDingDingMsg()
} }
func Enabled() bool { func Enabled() bool {
...@@ -60,3 +71,33 @@ func Enabled() bool { ...@@ -60,3 +71,33 @@ func Enabled() bool {
func OpenCache() { func OpenCache() {
cacheSwitcher.turnOn() cacheSwitcher.turnOn()
} }
func senderDingDing() {
_, err := http.Post(url, contentType, strings.NewReader(alterMsg))
if err != nil {
logger.Error.Println(err)
}
}
func buildDingDingMsg() string {
msg := dingDingMsg{
MsgType: "text",
Text: text{
Content: "influxdb 写超时,已启用文件缓存",
},
}
msgStr, err := json.Marshal(msg)
if nil != err {
logger.Error.Println("无法序列化ding ding msg", err)
}
return string(msgStr)
}
type dingDingMsg struct {
MsgType string
Text text
}
type text struct {
Content string
}
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 to comment