From 7837182d532dcc022ca2ffafa9289640ac942195 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 26 Oct 2024 13:05:05 -0500 Subject: [PATCH] more http options Signed-off-by: Jeff Carr --- Makefile | 12 ++++++++++++ event.go | 1 - http.go | 38 +++++++++++++++++++++++++++++++++++++- main.go | 2 +- 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"