Browse Source

邮件发送

fengweiqiang 5 years ago
parent
commit
34d9b79a8b

+ 8 - 6
udp_ocr_conter/config.json

@@ -19,11 +19,11 @@
   "pernum": 5,
   "time_consuming_limit": 60,
   "accumulated_task_lowlimit": 1000,
-  "swa":119,
-  "swb":112,
-  "xwa":114,
-  "xwb":117,
-  "gdts": 113,
+  "swa":19,
+  "swb":12,
+  "xwa":14,
+  "xwb":17,
+  "gdts": 13,
   "esconfig": {
     "available": true,
     "AccessID": "LTAIkuomMLAjIlGH",
@@ -36,5 +36,7 @@
         "vswitchid": "vsw-2ze1n1k3mo3fv2irsfdps"
       }
     ]
-  }
+  },
+  "tomail": "zhangjinkun@topnet.net.cn,chenmingzhu@topnet.net.cn,zhaolongyue@topnet.net.cn",
+  "api": "http://10.171.112.160:19281/_send/_mail"
 }

+ 6 - 1
udp_ocr_conter/main.go

@@ -315,7 +315,7 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 			go config.Udpclient.WriteUdp([]byte(`{"id":"`+newId.(bson.ObjectId).Hex()+`","permission":"ocr_task"}`), mu.OP_TYPE_DATA, ra)                    //分发任务
 			//if config.IsRun {
 			//	tmpdatas := mongodb.Find("ocr_task", bson.M{"isrun":"stop"}, `{"_id":1}`, nil, false, -1, -1)
-				totmp := make(map[string]string)
+				totmp := make(map[string]interface{})
 				totmp["stype"] = "fujian"
 				totmp["lteid"] = qu.ObjToString(tmp[qu.ObjToString(config.EidField)])
 				//if tmpdatas == nil || len(*tmpdatas) == 0{
@@ -327,6 +327,11 @@ func processUdpMsg(act byte, data []byte, ra *net.UDPAddr) {
 				//		mongodb.Save("ocr_flie_over",totmp)
 				//	}
 				//}
+				tmpSumNum := mongodb.Count("bidding", bson.M{"_id": bson.M{
+					"$gte": bson.ObjectIdHex(qu.ObjToString(tmp[qu.ObjToString("start")])),
+					"$lte": bson.ObjectIdHex(eid),
+				}})
+				totmp["count"] = tmpSumNum
 				tobyte, _ := json.Marshal(totmp)
 				mongodb.Save("ocr_flie_over",string(tobyte))
 			//go config.Udpclient.WriteUdp(tobyte, mu.OP_TYPE_DATA, &net.UDPAddr{

+ 7 - 1
udp_ocr_conter/src/config/config.go

@@ -13,14 +13,17 @@ var Udpclient mu.UdpClient //udp对象
 var Sysconfig map[string]interface{}
 var MgoIP, MgoDB, MgoC, MgoFileFiled, SidField, EidField string
 var Sys sync.RWMutex
-var Isjjr bool//节假日
+var Isjjr bool //节假日
 //var IsRun bool = true
+var tomail, api string
 
 func init() {
 	util.ReadConfig(&Sysconfig)
 	MgoIP = util.ObjToString(Sysconfig["mongodb_ip"])
 	MgoDB = util.ObjToString(Sysconfig["mongodb_db"])
 	MgoC = util.ObjToString(Sysconfig["mongodb_c"])
+	tomail = util.ObjToString(Sysconfig["tomail"])
+	api = util.ObjToString(Sysconfig["api"])
 	SidField = util.ObjToString(Sysconfig["json_sidfiled"])
 	EidField = util.ObjToString(Sysconfig["json_eidfiled"])
 	MgoFileFiled = util.ObjToStringDef(Sysconfig["mongodb_filefiled"], "projectinfo")
@@ -32,4 +35,7 @@ func init() {
 
 	Udpclient = mu.UdpClient{Local: Sysconfig["udpip"].(string) + ":" + Sysconfig["udpport"].(string), BufSize: 1024}
 
+	go func() {
+		SendEmail()
+	}()
 }

+ 75 - 0
udp_ocr_conter/src/config/send_email.go

@@ -0,0 +1,75 @@
+// main
+package config
+
+import (
+	"fmt"
+	"gopkg.in/mgo.v2/bson"
+	"io/ioutil"
+	"log"
+	"net"
+	"net/http"
+	"qfw/util"
+	"qfw/util/mongodb"
+	"time"
+)
+
+func SendEmail() {
+	sleeptime := 10
+	for {
+		b := check()
+		if b {
+			sleeptime = 60
+		} else {
+			sleeptime = 10
+		}
+		time.Sleep(time.Duration(sleeptime) * time.Minute)
+	}
+	lock := make(chan bool)
+	<-lock
+}
+
+func check() bool {
+	send := false
+	mongodb.Count("qfw", "")
+	taskArr := mongodb.Find("ocr_task", bson.M{"isrun": bson.M{
+		"$ne": "stop",
+	}}, `{_id:1}`, nil, false, -1, -1)
+	taskNum := len(*taskArr)
+	if taskNum == 0 {
+		return false
+	}
+	var sumNum int = 0
+	for _, v := range *taskArr {
+		sumNum += mongodb.Count("bidding", bson.M{"_id": bson.M{
+			"$gte": bson.ObjectIdHex(util.ObjToString(v["start"])),
+			"$lte": bson.ObjectIdHex(util.ObjToString(v[util.ObjToString(EidField)])),
+		}})
+	}
+	var content = ""
+	if sumNum > 10000 {
+		content = "附件识别积累任务超过1W条,当前积累"+fmt.Sprint(sumNum)
+	}
+
+	if len(content) > 0 {
+		sendMail(content)
+		send = true
+	}
+	return send
+}
+
+func sendMail(content string) {
+	res, err := http.Get(fmt.Sprintf("%s?to=%s&title=%s&body=%s", api, tomail, "udp_ocr_conter", "附件识别检测异常:"+content))
+	defer res.Body.Close()
+	if err == nil {
+		read, err := ioutil.ReadAll(res.Body)
+		log.Println("邮件发送:", string(read), err)
+	}
+}
+
+func netStatus(addr string) bool {
+	_, err := net.DialTimeout("tcp", addr, time.Second*3)
+	if err != nil {
+		return false
+	}
+	return true
+}