summaryrefslogtreecommitdiff
path: root/app/fetch.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/fetch.go')
-rw-r--r--app/fetch.go38
1 files changed, 30 insertions, 8 deletions
diff --git a/app/fetch.go b/app/fetch.go
index 898329d..c8b0376 100644
--- a/app/fetch.go
+++ b/app/fetch.go
@@ -3,7 +3,7 @@ package main
import (
"encoding/json"
"fmt"
- "strconv"
+ // "strconv"
// "time"
"log"
)
@@ -26,14 +26,26 @@ const (
func healthCheck() {
h := []Host{}
db := Db
+ //db.Where("monitored = ?", true).Find(&h)
db.Find(&h)
c := pool.Get()
defer c.Close()
for k, v := range h {
+ if !h[k].Monitored {
+ continue
+ }
+
if resp, _, err := HttpGet(v.Url); err != nil {
- fmt.Printf("Error! %v \n", err)
+ //fmt.Println(err)
+
+ h[k].Status = "Error"
+ h[k].StatusCode = 0
+ h[k].Success = false
+ h[k].Monitored = false
+ h[k].Reason = fmt.Sprintf("%v", err)
+ Db.Debug().Save(&h[k])
} else {
// fmt.Println("Health check: Okay! ", resp.Status)
@@ -41,17 +53,20 @@ func healthCheck() {
h[k].Status = resp.Status
h[k].StatusCode = int64(resp.StatusCode)
h[k].Success = true
+ h[k].Reason = ""
Db.Debug().Save(&h[k])
}
// save struct in redis as serialized json
// TODO
- j, err := json.Marshal(h[k])
- if err != nil {
- log.Println("Error: ", err)
- continue
- }
- c.Do("SET", cache_prefix+strconv.Itoa(k), j)
+ /*
+ j, err := json.Marshal(h[k])
+ if err != nil {
+ log.Println("Error: ", err)
+ continue
+ }
+ c.Do("SET", cache_prefix+strconv.Itoa(k), j)
+ */
//c.Do("SET", cache_prefix+strconv.Itoa(k), j)
//c.Do("SET", k, j)
@@ -60,4 +75,11 @@ func healthCheck() {
}
+ js, err := json.Marshal(h)
+
+ if err != nil {
+ log.Fatal(err)
+ } else {
+ c.Do("SET", cache_prefix+"database", js)
+ }
}