sending a machine protobuf

This commit is contained in:
Jeff Carr 2024-11-15 20:59:23 -06:00
parent 141d3024fd
commit 7dd5d6d2b1
4 changed files with 34 additions and 6 deletions

26
http.go
View File

@ -32,6 +32,24 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
return
}
if route == "/machine" {
var m *zoopb.Machine
m = new(zoopb.Machine)
if err := m.Unmarshal(msg); err != nil {
log.Info("proto.Unmarshal() failed on wire message len", len(msg), "from", hostname)
return
}
if m.Packages == nil {
log.Info("Unmarshal worked with msg len", len(msg), "from", m.Hostname)
log.Info(m.Hostname, "sent machine")
} else {
log.Info("Unmarshal worked with msg len", len(msg), "from", m.Hostname)
log.Info(m.Hostname, "has", m.Packages.Len(), "packages installed")
}
return
}
if route == "/status" {
if hostname == "" {
// ignore junk
@ -47,6 +65,14 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
log.Info("Unmarshal worked with msg len", len(msg), "from", hostname)
log.Info(hostname, "has", packs.Len(), "packages installed")
fmt.Fprintln(w, "upgrade")
m := me.machines.FindByName(hostname)
if m == nil {
log.Info("did not find", hostname)
} else {
log.Info("found", hostname)
}
return
}

View File

@ -20,6 +20,7 @@ import (
"time"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/protobuf/zoopb"
"go.wit.com/log"
)
@ -46,6 +47,7 @@ func main() {
me = new(stuff)
me.hostname, _ = os.Hostname()
me.pollDelay = 10 * time.Second
me.machines = new(zoopb.Machines)
go NewWatchdog()

View File

@ -10,11 +10,11 @@ var me *stuff
// this app's variables
type stuff struct {
hostname string // my hostname to send to zookeeper
zookeeper string // the dns name for the zookeeper
pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer
dogchan chan bool
hostname string // my fqdn dns zookeeper hostname
pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer
dogchan chan bool // can kill the watchdog
distro string // debian,redhat,gentoo,macos,wincrap
packages *zoopb.Packages // installed packages and versions
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
}

View File

@ -39,7 +39,7 @@ func NewWatchdog() {
fmt.Println("Done!")
return
case t := <-me.dog.C:
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
log.Info("zookeeper Watchdog() ticked", me.hostname, "Current time: ", t)
// h.pollHypervisor()
// h.Scan()
}