summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-15 20:59:42 -0600
committerJeff Carr <[email protected]>2024-11-15 20:59:42 -0600
commit706b0418bf68a09ff7b78a1646c280a53be68c97 (patch)
tree6b0dc5c3c10f9360860730f86b76cbd6d4f78836
parent0700306530e9d88420c326c9899ddc098b2fb450 (diff)
sending a machine protobuf
-rw-r--r--main.go4
-rw-r--r--send.go37
-rw-r--r--structs.go1
-rw-r--r--watchdog.go1
4 files changed, 41 insertions, 2 deletions
diff --git a/main.go b/main.go
index db3e42a..f08acf7 100644
--- a/main.go
+++ b/main.go
@@ -52,6 +52,10 @@ func main() {
// what OS?
me.distro = initDistro()
+ // init my machine protobuf
+ me.machine = new(zoopb.Machine)
+ me.machine.Hostname = me.hostname
+
// init the installed package list
me.packages = new(zoopb.Packages)
initPackages()
diff --git a/send.go b/send.go
index c861c4e..cf75f5a 100644
--- a/send.go
+++ b/send.go
@@ -15,7 +15,7 @@ func send() {
func pingStatus() error {
var url string
- url = urlbase + "/status?hostname=stuff"
+ url = urlbase + "/status?hostname=" + me.hostname
msg, err := me.packages.Marshal()
if err != nil {
log.Info("proto.Marshal() failed:", err)
@@ -31,7 +31,40 @@ func pingStatus() error {
test := strings.TrimSpace(string(body))
// log.Info("virtigo returned body:", test)
for _, line := range strings.Split(test, "\n") {
- log.Info("GOT:", line)
+ switch line {
+ case "upgrade":
+ log.Info("should upgrade now")
+ default:
+ log.Info("GOT:", line)
+ }
+ }
+ return nil
+}
+
+func sendMachine() error {
+ var url string
+ url = urlbase + "/machine"
+ msg, err := me.machine.Marshal()
+ if err != nil {
+ log.Info("proto.Marshal() failed:", err)
+ return err
+ }
+ log.Info("proto Marshal len =", len(msg))
+ body, err := httpPost(url, msg)
+ if err != nil {
+ log.Info("httpPost() failed:", err)
+ return err
+ }
+
+ test := strings.TrimSpace(string(body))
+ // log.Info("virtigo returned body:", test)
+ for _, line := range strings.Split(test, "\n") {
+ switch line {
+ case "upgrade":
+ log.Info("machine upgrade now")
+ default:
+ log.Info("GOT:", line)
+ }
}
return nil
}
diff --git a/structs.go b/structs.go
index a5b726f..757a0bd 100644
--- a/structs.go
+++ b/structs.go
@@ -15,5 +15,6 @@ type stuff struct {
pollDelay time.Duration // how often to report our status
dog *time.Ticker // the watchdog timer
distro string // debian,redhat,gentoo,macos,wincrap
+ machine *zoopb.Machine // my protobuf
packages *zoopb.Packages // installed packages and versions
}
diff --git a/watchdog.go b/watchdog.go
index 75ac1cb..14faea8 100644
--- a/watchdog.go
+++ b/watchdog.go
@@ -34,6 +34,7 @@ func NewWatchdog() {
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
updatePackages()
pingStatus()
+ sendMachine()
// h.pollHypervisor()
// h.Scan()
}