您好,登錄后才能下訂單哦!
package main
import (
"bytes"
"encoding/json"
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/go-xorm/xorm"
"io/ioutil"
"net/http"
"time"
)
var engine *xorm.Engine
const webhook_url = "https://oapi.dingtalk.com/robot/send?access_token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
func dingtoinfo(s string) bool {
content, data := make(map[string]string), make(map[string]interface{})
content["content"] = s
data["msgtype"] = "text"
data["text"] = content
b, _ := json.Marshal(data)
resp, err := http.Post(webhook_url,
"application/json",
bytes.NewBuffer(b))
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
body, _ := ioutil.ReadAll(resp.Body)
fmt.Println(string(body))
return true
}
func recoverName() {
if r := recover(); r != nil {
res := fmt.Sprintf("%s %s", "監(jiān)控程序 報(bào)錯(cuò):", r)
dingtoinfo(res)
}
}
func main() {
defer recoverName()
var err error
engine, err = xorm.NewEngine("mysql", "root:xxxxxxxxxxxxxxx@tcp(127.0.0.1:3306)/new?charset=utf8")
if err != nil {
panic(err.Error())
}
gsql := " select up_time from token where type = 0 ;"
gres, gerr := engine.Query(gsql)
if gerr != nil {
panic(gerr.Error())
}
var data string
for _, v := range gres {
data = string(v["up_time"])
}
loc, _ := time.LoadLocation("Asia/Shanghai")
nowTime := time.Now().In(loc)
tm, _ := time.Parse("2006-01-02 03:04:05", data)
ntm := tm.In(loc)
subM := nowTime.Sub(ntm)
fmt.Println("token更新時(shí)間 與 系統(tǒng)時(shí)間 相差",subM)
subtract := int(subM.Minutes())
if subtract > 20 {
dingtoinfo("異常, 請(qǐng)及時(shí)登錄查看 !!!")
}
}
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。