summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus32015-05-05 22:41:27 +0200
committerHorus32015-05-05 22:41:27 +0200
commitf71b90582c713e528fb731ded8ded8d8b599c031 (patch)
tree97f8a51ecae187477672e4e7f46ed84444447fd5
parent39ae1e288e94871ea7fe41976080afdb503950bc (diff)
downloadstatuspage-master.tar.gz
Fixed IndexOutOfBonds runtime panic.HEADmaster
-rw-r--r--app/email.go8
-rw-r--r--app/fetch.go16
-rw-r--r--app/test.go2
3 files changed, 18 insertions, 8 deletions
diff --git a/app/email.go b/app/email.go
index b497bf7..c92fed0 100644
--- a/app/email.go
+++ b/app/email.go
@@ -8,7 +8,7 @@ import (
"os"
)
-func SendEmail(u []User, h []Host) {
+func SendEmail(u []User, h []Host, name string) {
log.Println("Sending E-Mail")
if len(u) == 0 {
return
@@ -18,11 +18,11 @@ func SendEmail(u []User, h []Host) {
}
log.Println("Sending E-Mail - Checked")
adresses := getEmails(u)
- h = getHosts(h)
+ //h = getHosts(h)
e := &email.Email{
To: adresses,
From: "StatusPage <" + os.Getenv("STATUS_HTTP_ADRESS") + ">",
- Subject: "Host is down (" + h[0].Host + ")",
+ Subject: "Host is down (" + name + ")",
HTML: getBody(h),
}
err := e.Send(os.Getenv("STATUS_HTTP_MAILER"), smtp.PlainAuth("", os.Getenv("STATUS_HTTP_ADRESS"), os.Getenv("STATUS_HTTP_PASSWORD"), os.Getenv("STATUS_HTTP_MAILER")))
@@ -40,7 +40,7 @@ func getEmails(u []User) []string {
func getHosts(hosts []Host) []Host {
var h []Host
for k, _ := range hosts {
- if !hosts[k].Monitored {
+ if hosts[k].Class == "danger" {
h = append(h, hosts[k])
}
}
diff --git a/app/fetch.go b/app/fetch.go
index fc457f7..799fb58 100644
--- a/app/fetch.go
+++ b/app/fetch.go
@@ -16,6 +16,7 @@ func healthCheck() {
func CheckPages(h []Host) []Host {
wentWrong := false
+ hostName := ""
for k, v := range h {
if !h[k].Monitored {
@@ -26,9 +27,11 @@ func CheckPages(h []Host) []Host {
h[k].Status = "Error"
h[k].StatusCode = 0
h[k].Success = false
- h[k].Monitored = false
+ //h[k].Monitored = false
h[k].Reason = fmt.Sprintf("%v", err)
h[k].Class = "danger"
+ hostName = h[k].Host
+ wentWrong = true
} else {
h[k].Status = resp.Status
h[k].StatusCode = int64(resp.StatusCode)
@@ -40,6 +43,8 @@ func CheckPages(h []Host) []Host {
h[k].Success = false
h[k].Class = "danger"
h[k].Monitored = true
+ wentWrong = true
+ hostName = h[k].Host
}
h[k].Reason = ""
}
@@ -48,13 +53,14 @@ func CheckPages(h []Host) []Host {
if wentWrong {
u := []User{}
Db.Find(&u)
- SendEmail(u, h)
+ SendEmail(u, h, hostName)
}
return h
}
func CheckAllPages(h []Host) []Host {
wentWrong := false
+ hostName := ""
for k, v := range h {
if resp, _, err := HttpGet(v.Url); err != nil {
@@ -65,6 +71,7 @@ func CheckAllPages(h []Host) []Host {
h[k].Reason = fmt.Sprintf("%v", err)
h[k].Class = "danger"
wentWrong = true
+ hostName = h[k].Host
} else {
h[k].Status = resp.Status
h[k].StatusCode = int64(resp.StatusCode)
@@ -74,6 +81,9 @@ func CheckAllPages(h []Host) []Host {
} else {
h[k].Success = false
h[k].Class = "danger"
+ h[k].Monitored = true
+ wentWrong = true
+ hostName = h[k].Host
}
h[k].Reason = ""
}
@@ -82,7 +92,7 @@ func CheckAllPages(h []Host) []Host {
if wentWrong {
u := []User{}
Db.Find(&u)
- SendEmail(u, h)
+ SendEmail(u, h, hostName)
}
return h
}
diff --git a/app/test.go b/app/test.go
index a323b31..210e7f4 100644
--- a/app/test.go
+++ b/app/test.go
@@ -39,7 +39,7 @@ func testMail() {
h := []Host{}
Db.Find(&u)
Db.Find(&h)
- SendEmail(u, h)
+ SendEmail(u, h, "Test")
}
func t() {