Browse Source

log sending email error

haiswork 5 years ago
parent
commit
f08364b404
1 changed files with 10 additions and 3 deletions
  1. 10
    3
      service/service.go

+ 10
- 3
service/service.go View File

@@ -2,6 +2,7 @@ package service
2 2
 
3 3
 import (
4 4
 	"fmt"
5
+	"log"
5 6
 	"net/http"
6 7
 	"strings"
7 8
 	"time"
@@ -30,9 +31,12 @@ func monitorStep(urls []string) {
30 31
 		err := monitorURL(url)
31 32
 		if cache.CheckMonitor(url, err) {
32 33
 			if err != nil {
33
-				notice.SendEmailBySMTP("url error", config.C.Notice.Emails, err.Error(), false)
34
+				err = notice.SendEmailBySMTP(url+" timeout", config.C.Notice.Emails, err.Error(), false)
34 35
 			} else {
35
-				notice.SendEmailBySMTP("url return ok", config.C.Notice.Emails, "return ok", false)
36
+				err = notice.SendEmailBySMTP(url+" ok", config.C.Notice.Emails, "ok", false)
37
+			}
38
+			if err != nil {
39
+				log.Printf("send email error:%s,host:%s", err.Error(), config.C.Notice.SMTP.Host)
36 40
 			}
37 41
 		}
38 42
 	}
@@ -50,7 +54,10 @@ func monitorURL(url string) error {
50 54
 	}
51 55
 	useTime := int64(time.Now().Sub(startTime) / time.Millisecond)
52 56
 	if useTime > config.C.Monitor.Timeout {
53
-		return fmt.Errorf("timeout url:%s,millisecond:%d", url, useTime)
57
+		return fmt.Errorf("url:%s timeout:%dms", url, useTime)
58
+	}
59
+	if config.C.App.Debug {
60
+		log.Printf("url:%s use time:%dms\n", url, useTime)
54 61
 	}
55 62
 	return nil
56 63
 }