more http options

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2024-10-26 13:05:05 -05:00
parent 2e8281d067
commit 7837182d53
4 changed files with 50 additions and 3 deletions

View File

@ -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

View File

@ -84,7 +84,6 @@ func findDroplet(name string) *pb.Droplet {
return nil
}
func Start(name string) (bool, string) {
var result string

38
http.go
View File

@ -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
}

View File

@ -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"