summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-10-26 13:05:05 -0500
committerJeff Carr <[email protected]>2024-10-26 13:05:05 -0500
commit7837182d532dcc022ca2ffafa9289640ac942195 (patch)
treeb7486b5d06ca9ced34215a1275be3b4c209b9bc3
parent2e8281d0678d5f201e18aec33aa4e39fa3587230 (diff)
more http options
Signed-off-by: Jeff Carr <[email protected]>
-rw-r--r--Makefile12
-rw-r--r--event.go1
-rw-r--r--http.go38
-rw-r--r--main.go2
4 files changed, 50 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index aee6b54..b268238 100644
--- a/Makefile
+++ b/Makefile
@@ -74,3 +74,15 @@ git-clone:
go-clone --recursive --go-src --no-work go.wit.com/apps/virtigo
go-clone --recursive --go-src --no-work go.wit.com/apps/gowebd
go-clone --recursive --go-src --no-work go.wit.com/lib/daemons/virtigod
+
+http-uptime:
+ curl --silent http://localhost:8080/uptime
+
+http-droplets:
+ curl --silent http://localhost:8080/droplets
+
+http-missing:
+ curl --silent http://localhost:8080/missing
+
+http-dumplibvirtxml:
+ curl --silent http://localhost:8080//dumplibvirtxml
diff --git a/event.go b/event.go
index fb8dc3b..261c48b 100644
--- a/event.go
+++ b/event.go
@@ -84,7 +84,6 @@ func findDroplet(name string) *pb.Droplet {
return nil
}
-
func Start(name string) (bool, string) {
var result string
diff --git a/http.go b/http.go
index abf7983..cb3f35a 100644
--- a/http.go
+++ b/http.go
@@ -7,6 +7,7 @@ import (
"go.wit.com/lib/virtigoxml"
"go.wit.com/log"
+ pb "go.wit.com/lib/protobuf/virtbuf"
)
// remove '?' part and trailing '/'
@@ -22,7 +23,42 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
// is the cluster running what it should?
if tmp == "/droplets" {
for _, d := range me.cluster.Droplets {
- fmt.Fprintln(w, "", d.Hostname, "(", d.StartState, "vs", d.CurrentState, ")")
+ var msg string
+ if d.StartState == pb.DropletState_ON {
+ msg = "(should be on)"
+ }
+ switch d.CurrentState {
+ case pb.DropletState_ON:
+ fmt.Fprintln(w, d.Hostname, "ON")
+ case pb.DropletState_OFF:
+ fmt.Fprintln(w, d.Hostname, msg)
+ default:
+ fmt.Fprintln(w, d.Hostname, "? state:", d.CurrentState, msg)
+ }
+ }
+ return
+ }
+
+ // show only what droplets should be running but are missing
+ if tmp == "/missing" {
+ var count int
+ var missing int
+ for _, d := range me.cluster.Droplets {
+ if d.StartState != pb.DropletState_ON {
+ continue
+ }
+ count += 1
+ if d.CurrentState == pb.DropletState_ON {
+ continue
+ }
+ missing += 1
+ fmt.Fprintln(w, d.Hostname, "current state:", d.CurrentState)
+ }
+ if missing == 0 {
+ fmt.Fprintln(w, "all", count, "droplets set to run are running")
+ } else {
+ fmt.Fprintln(w, missing, "droplets missing")
+ fmt.Fprintln(w, count, "droplets should be running")
}
return
}
diff --git a/main.go b/main.go
index bc11bdf..c484e8a 100644
--- a/main.go
+++ b/main.go
@@ -65,7 +65,7 @@ func main() {
*/
for i, d := range me.cluster.Droplets {
- d.CurrentState = pb.DropletState_UNKNOWN
+ d.CurrentState = pb.DropletState_OFF
log.Info(i, "droplet", d.Hostname)
}
hmm := "pihole.wit.com"