summaryrefslogtreecommitdiff
path: root/app/fetch.go
diff options
context:
space:
mode:
Diffstat (limited to 'app/fetch.go')
-rw-r--r--app/fetch.go65
1 files changed, 9 insertions, 56 deletions
diff --git a/app/fetch.go b/app/fetch.go
index a3d3ae7..3ddd97b 100644
--- a/app/fetch.go
+++ b/app/fetch.go
@@ -1,85 +1,38 @@
package main
import (
- "encoding/json"
"fmt"
- // "strconv"
- // "time"
- "log"
-)
-
-func jobRun() {
- c := c
- c.AddFunc("@every 10s", healthCheck)
- c.Start()
- jobs := c.Entries()
-
- for _, i := range jobs {
- fmt.Printf("Job: %v, Schedule: %v; Next %v; Prev %v \n", i.Job, i.Schedule, i.Next, i.Prev)
- }
-}
-
-const (
- cache_prefix = "status_"
)
func healthCheck() {
h := []Host{}
- db := Db
- //db.Where("monitored = ?", true).Find(&h)
- db.Find(&h)
+ Db.Find(&h)
+ h = CheckPage(h)
+ CacheHosts(cache_prefix+"database", h)
+ for k, _ := range h {
+ Db.Debug().Save(&h[k])
+ }
+}
- c := pool.Get()
- defer c.Close()
+func CheckPage(h []Host) []Host {
for k, v := range h {
if !h[k].Monitored {
continue
}
-
if resp, _, err := HttpGet(v.Url); err != nil {
- //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)
-
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)
- */
-
- //c.Do("SET", cache_prefix+strconv.Itoa(k), j)
- //c.Do("SET", k, j)
-
- // fmt.Printf("Id: %v, Url: %v \n", v.Id, v.Url)
-
}
- js, err := json.Marshal(h)
-
- if err != nil {
- log.Fatal(err)
- } else {
- c.Do("SET", cache_prefix+"database", js)
- }
+ return h
}