summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHorus_Arch2015-02-20 20:40:51 +0100
committerHorus_Arch2015-02-20 20:40:51 +0100
commita8d9e02831d4b01e47f24a30144b5522c03b2b8c (patch)
treef396994bbe050d14db73048572481d63f175d750
parentffe1b892b4c01c40215a1b8b5697fc35b81186b5 (diff)
downloadstatuspage-a8d9e02831d4b01e47f24a30144b5522c03b2b8c.tar.gz
Config for ip and port. Health check updates now database and redis cache.
-rw-r--r--app/Makefile6
-rw-r--r--app/db.go1
-rw-r--r--app/fetch.go29
-rw-r--r--app/main.go6
-rw-r--r--app/struct.go12
-rw-r--r--app/test.go6
-rwxr-xr-xhooks/pre-commit1
7 files changed, 44 insertions, 17 deletions
diff --git a/app/Makefile b/app/Makefile
index 41a813f..49e8b5d 100644
--- a/app/Makefile
+++ b/app/Makefile
@@ -13,6 +13,12 @@ endif
ifndef STATUS_REDIS_PORT
export STATUS_REDIS_PORT:=6379
endif
+ifndef STATUS_HTTP_IP
+ export STATUS_HTTP_IP:=127.0.0.1
+endif
+ifndef STATUS_HTTP_PORT
+ export STATUS_HTTP_PORT:=8080
+endif
IMPORT_FILE:=import.go
diff --git a/app/db.go b/app/db.go
index 3df24b6..a4e35cb 100644
--- a/app/db.go
+++ b/app/db.go
@@ -25,4 +25,5 @@ func InitDB() {
Db.Model(&u).AddUniqueIndex("idx_user_name", "name")
Db.Model(&u).AddUniqueIndex("idx_user_email", "email")
+ Db.Model(&h).AddUniqueIndex("idx_host_url", "url")
}
diff --git a/app/fetch.go b/app/fetch.go
index 82bbb7d..898329d 100644
--- a/app/fetch.go
+++ b/app/fetch.go
@@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
+ "strconv"
// "time"
"log"
)
@@ -31,24 +32,32 @@ func healthCheck() {
defer c.Close()
for k, v := range h {
+ if resp, _, err := HttpGet(v.Url); err != nil {
+ fmt.Printf("Error! %v \n", err)
+
+ } else {
+ // fmt.Println("Health check: Okay! ", resp.Status)
+
+ h[k].Status = resp.Status
+ h[k].StatusCode = int64(resp.StatusCode)
+ h[k].Success = true
+ Db.Debug().Save(&h[k])
+ }
+
// save struct in redis as serialized json
// TODO
- j, err := json.Marshal(v)
+ 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+string(k), j)
+ //c.Do("SET", cache_prefix+strconv.Itoa(k), j)
+ //c.Do("SET", k, j)
- fmt.Println("Json: ", j)
+ // fmt.Printf("Id: %v, Url: %v \n", v.Id, v.Url)
- fmt.Printf("Id: %v, Url: %v \n", v.Id, v.Url)
-
- if resp, _, err := HttpGet(v.Url); err != nil {
- fmt.Printf("Error! %v \n", err)
- } else {
- fmt.Println("Health check: Okay! ", resp.Status)
- }
}
+
}
diff --git a/app/main.go b/app/main.go
index 35a162a..72be13c 100644
--- a/app/main.go
+++ b/app/main.go
@@ -6,6 +6,7 @@ import (
"github.com/robfig/cron"
"html/template"
"net/http"
+ "os"
)
var decoder = schema.NewDecoder()
@@ -17,6 +18,7 @@ var c = cron.New()
func main() {
run()
InitDB()
+ insertHost()
r := mux.NewRouter()
r.HandleFunc("/", IndexHandler)
@@ -28,5 +30,7 @@ func main() {
r.HandleFunc("/new", PrintNewJobHandler).Methods("GET")
r.HandleFunc("/jobs", ShowJobHandler)
http.Handle("/", r)
- http.ListenAndServe(":8080", nil)
+ ip := os.Getenv("STATUS_HTTP_IP")
+ port := os.Getenv("STATUS_HTTP_PORT")
+ http.ListenAndServe(ip+":"+port, nil)
}
diff --git a/app/struct.go b/app/struct.go
index 15c238f..d7135aa 100644
--- a/app/struct.go
+++ b/app/struct.go
@@ -7,17 +7,17 @@ import (
/* Maybe worth saving uptime history? */
type Host struct {
- Id int64
- UserId int64
- Url string
- Protocoll string // e.g. http
- Monitored bool // disable monitoring on error
+ Id int64
+ UserId int64
+ Url string
+ // Protocoll string // e.g. http
+ Monitored bool // disable monitoring on error
Private bool
Status string
StatusCode int64
+ Success bool
/*
Date time.Time
- Success bool
Include string // Website must include this string
Except string // Website must not include this string
Reason string // Include, Exclude, Connection failure
diff --git a/app/test.go b/app/test.go
new file mode 100644
index 0000000..0b56fae
--- /dev/null
+++ b/app/test.go
@@ -0,0 +1,6 @@
+package main
+
+func insertHost() {
+ h := Host{Url: "https://mx.iamfabulous.de/", Monitored: true, Private: false}
+ Db.Create(&h)
+}
diff --git a/hooks/pre-commit b/hooks/pre-commit
index f304329..402ec09 100755
--- a/hooks/pre-commit
+++ b/hooks/pre-commit
@@ -4,5 +4,6 @@ if [ -f $GIT_DIR/../app/Makefile ]; then
cd "$GIT_DIR/../app"
make clean || exit 0
else
+ echo "No Makefile found." 1>&2
exit 1
fi