summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-15 20:59:23 -0600
committerJeff Carr <[email protected]>2024-11-15 20:59:23 -0600
commit7dd5d6d2b165a91993fb532429189a481eebc366 (patch)
tree211bee013fb95cc0da8320bfeddb944250416066
parent141d3024fd4a32d5485e873308ae6414c4867a28 (diff)
sending a machine protobuf
-rw-r--r--http.go26
-rw-r--r--main.go2
-rw-r--r--structs.go10
-rw-r--r--watchdog.go2
4 files changed, 34 insertions, 6 deletions
diff --git a/http.go b/http.go
index af3d16f..6f40f0a 100644
--- a/http.go
+++ b/http.go
@@ -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
}
diff --git a/main.go b/main.go
index f540f6f..1eb6adc 100644
--- a/main.go
+++ b/main.go
@@ -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()
diff --git a/structs.go b/structs.go
index ba67457..20ed0f5 100644
--- a/structs.go
+++ b/structs.go
@@ -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
}
diff --git a/watchdog.go b/watchdog.go
index e685b7b..6c90492 100644
--- a/watchdog.go
+++ b/watchdog.go
@@ -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()
}