|
@@ -28,12 +28,18 @@ func Task() {
|
|
|
port := qu.IntAll(m["port"])
|
|
|
mail := qu.ObjToString(m["mail"])
|
|
|
timing := qu.ObjToString(m["timing"])
|
|
|
+ stype := qu.IntAll(m["stype"])
|
|
|
|
|
|
now := time.Now().Unix()
|
|
|
t := TimeDis(timing)
|
|
|
if t > 0 && (now-qu.Int64All(m["checktime"]) >= t) {
|
|
|
- udpNode(ip, name, mail, port, now)
|
|
|
- Mgo.UpdateById("app_list", m["_id"], bson.M{"$set": bson.M{"checktime": now}})
|
|
|
+ if stype == 1 {
|
|
|
+ udpNode(ip, name, mail, port, now)
|
|
|
+ Mgo.UpdateById("app_list", m["_id"], bson.M{"$set": bson.M{"checktime": now}})
|
|
|
+ } else {
|
|
|
+ tcpWork(name, fmt.Sprintf("%s:%d", ip, port), mail, time.Now().Unix())
|
|
|
+ Mgo.UpdateById("app_list", m["_id"], bson.M{"$set": bson.M{"checktime": now}})
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -105,3 +111,30 @@ func MailWork() {
|
|
|
time.Sleep(60 * time.Second)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func tcpWork(name, address, to string, timestamp int64) {
|
|
|
+ jkmail, _ := Sysconfig["jkmail"].(map[string]interface{})
|
|
|
+ netry := 0
|
|
|
+ for {
|
|
|
+ conn, err := net.DialTimeout("tcp", address, 5*time.Second)
|
|
|
+ if err != nil {
|
|
|
+ netry++
|
|
|
+ if netry == 3 {
|
|
|
+ t := fmt.Sprintf("剑鱼维护平台异常监控通知--%s", name)
|
|
|
+ b := fmt.Sprintf("服务:%s,ip-port:%s,监控通信未成功,检测异常时间%s,请负责人检查服务并处理。",
|
|
|
+ name, address, qu.FormatDateByInt64(×tamp, qu.Date_Time_Layout))
|
|
|
+ res, err1 := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", qu.ObjToString(jkmail["api"]), to, t, b))
|
|
|
+ if err1 == nil {
|
|
|
+ defer res.Body.Close()
|
|
|
+ read, _ := io.ReadAll(res.Body)
|
|
|
+ qu.Debug("send mail ...", name, to, string(read))
|
|
|
+ }
|
|
|
+ break
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ _ = conn.Close()
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+}
|