From 8193bf18abbef3ffb00d22820899096db19ba428 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Fri, 15 Nov 2024 21:05:03 -0600 Subject: [PATCH] move to just sending machine --- apt.go | 12 ++++++------ main.go | 3 ++- send.go | 2 +- structs.go | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/apt.go b/apt.go index 9f88164..de38135 100644 --- a/apt.go +++ b/apt.go @@ -21,21 +21,21 @@ func initPackages() { new1 := new(zoopb.Package) new1.Name = pkg new1.Version = version - if me.packages.Append(new1) { + if me.machine.Packages.Append(new1) { // log.Info("added", new1.Name, "ok") } else { log.Info("added", new1.Name, "failed") } } - log.Info(me.hostname, "has distro", me.distro, "with", me.packages.Len(), "packages installed") + log.Info(me.hostname, "has distro", me.distro, "with", me.machine.Packages.Len(), "packages installed") } func addNew(name string, version string) bool { new1 := new(zoopb.Package) new1.Name = name new1.Version = version - return me.packages.Append(new1) + return me.machine.Packages.Append(new1) } func updatePackages() { @@ -49,20 +49,20 @@ func updatePackages() { var newCounter, changeCounter int // Print the installed packages and their versions for pkg, version := range newP { - found := me.packages.FindByName(pkg) + found := me.machine.Packages.FindByName(pkg) if found == nil { log.Info("adding new", pkg, version) addNew(pkg, version) newCounter += 1 } else { found.Version = version - if me.packages.Update(found) { + if me.machine.Packages.Update(found) { changeCounter += 1 } } } - footer := fmt.Sprintf("%s has distro %s with %d packages installed", me.hostname, me.distro, me.packages.Len()) + footer := fmt.Sprintf("%s has distro %s with %d packages installed", me.hostname, me.distro, me.machine.Packages.Len()) if changeCounter != 0 { footer += fmt.Sprintf(" (%d changed)", changeCounter) } diff --git a/main.go b/main.go index f08acf7..d60f1e0 100644 --- a/main.go +++ b/main.go @@ -54,10 +54,11 @@ func main() { // init my machine protobuf me.machine = new(zoopb.Machine) + me.machine.Packages = new(zoopb.Packages) me.machine.Hostname = me.hostname // init the installed package list - me.packages = new(zoopb.Packages) + // me.packages = new(zoopb.Packages) initPackages() go NewWatchdog() diff --git a/send.go b/send.go index cf75f5a..b71adf8 100644 --- a/send.go +++ b/send.go @@ -16,7 +16,7 @@ func send() { func pingStatus() error { var url string url = urlbase + "/status?hostname=" + me.hostname - msg, err := me.packages.Marshal() + msg, err := me.machine.Packages.Marshal() if err != nil { log.Info("proto.Marshal() failed:", err) return err diff --git a/structs.go b/structs.go index 757a0bd..3f5294a 100644 --- a/structs.go +++ b/structs.go @@ -16,5 +16,5 @@ type stuff struct { 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 + // packages *zoopb.Packages // installed packages and versions }