sending a machine protobuf
This commit is contained in:
parent
141d3024fd
commit
7dd5d6d2b1
26
http.go
26
http.go
|
@ -32,6 +32,24 @@ func okHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
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 route == "/status" {
|
||||||
if hostname == "" {
|
if hostname == "" {
|
||||||
// ignore junk
|
// 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("Unmarshal worked with msg len", len(msg), "from", hostname)
|
||||||
log.Info(hostname, "has", packs.Len(), "packages installed")
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
main.go
2
main.go
|
@ -20,6 +20,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.wit.com/dev/alexflint/arg"
|
"go.wit.com/dev/alexflint/arg"
|
||||||
|
"go.wit.com/lib/protobuf/zoopb"
|
||||||
"go.wit.com/log"
|
"go.wit.com/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,6 +47,7 @@ func main() {
|
||||||
me = new(stuff)
|
me = new(stuff)
|
||||||
me.hostname, _ = os.Hostname()
|
me.hostname, _ = os.Hostname()
|
||||||
me.pollDelay = 10 * time.Second
|
me.pollDelay = 10 * time.Second
|
||||||
|
me.machines = new(zoopb.Machines)
|
||||||
|
|
||||||
go NewWatchdog()
|
go NewWatchdog()
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,11 @@ var me *stuff
|
||||||
|
|
||||||
// this app's variables
|
// this app's variables
|
||||||
type stuff struct {
|
type stuff struct {
|
||||||
hostname string // my hostname to send to zookeeper
|
hostname string // my fqdn dns zookeeper hostname
|
||||||
zookeeper string // the dns name for the zookeeper
|
|
||||||
pollDelay time.Duration // how often to report our status
|
pollDelay time.Duration // how often to report our status
|
||||||
dog *time.Ticker // the watchdog timer
|
dog *time.Ticker // the watchdog timer
|
||||||
dogchan chan bool
|
dogchan chan bool // can kill the watchdog
|
||||||
distro string // debian,redhat,gentoo,macos,wincrap
|
distro string // debian,redhat,gentoo,macos,wincrap
|
||||||
packages *zoopb.Packages // installed packages and versions
|
packages *zoopb.Packages // installed packages and versions
|
||||||
|
machines *zoopb.Machines // every machine that has reported itself to the zookeeper
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ func NewWatchdog() {
|
||||||
fmt.Println("Done!")
|
fmt.Println("Done!")
|
||||||
return
|
return
|
||||||
case t := <-me.dog.C:
|
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.pollHypervisor()
|
||||||
// h.Scan()
|
// h.Scan()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue