move to just sending machine

This commit is contained in:
Jeff Carr 2024-11-15 21:05:03 -06:00
parent 706b0418bf
commit 8193bf18ab
4 changed files with 10 additions and 9 deletions

12
apt.go
View File

@ -21,21 +21,21 @@ func initPackages() {
new1 := new(zoopb.Package) new1 := new(zoopb.Package)
new1.Name = pkg new1.Name = pkg
new1.Version = version new1.Version = version
if me.packages.Append(new1) { if me.machine.Packages.Append(new1) {
// log.Info("added", new1.Name, "ok") // log.Info("added", new1.Name, "ok")
} else { } else {
log.Info("added", new1.Name, "failed") 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 { func addNew(name string, version string) bool {
new1 := new(zoopb.Package) new1 := new(zoopb.Package)
new1.Name = name new1.Name = name
new1.Version = version new1.Version = version
return me.packages.Append(new1) return me.machine.Packages.Append(new1)
} }
func updatePackages() { func updatePackages() {
@ -49,20 +49,20 @@ func updatePackages() {
var newCounter, changeCounter int var newCounter, changeCounter int
// Print the installed packages and their versions // Print the installed packages and their versions
for pkg, version := range newP { for pkg, version := range newP {
found := me.packages.FindByName(pkg) found := me.machine.Packages.FindByName(pkg)
if found == nil { if found == nil {
log.Info("adding new", pkg, version) log.Info("adding new", pkg, version)
addNew(pkg, version) addNew(pkg, version)
newCounter += 1 newCounter += 1
} else { } else {
found.Version = version found.Version = version
if me.packages.Update(found) { if me.machine.Packages.Update(found) {
changeCounter += 1 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 { if changeCounter != 0 {
footer += fmt.Sprintf(" (%d changed)", changeCounter) footer += fmt.Sprintf(" (%d changed)", changeCounter)
} }

View File

@ -54,10 +54,11 @@ func main() {
// init my machine protobuf // init my machine protobuf
me.machine = new(zoopb.Machine) me.machine = new(zoopb.Machine)
me.machine.Packages = new(zoopb.Packages)
me.machine.Hostname = me.hostname me.machine.Hostname = me.hostname
// init the installed package list // init the installed package list
me.packages = new(zoopb.Packages) // me.packages = new(zoopb.Packages)
initPackages() initPackages()
go NewWatchdog() go NewWatchdog()

View File

@ -16,7 +16,7 @@ func send() {
func pingStatus() error { func pingStatus() error {
var url string var url string
url = urlbase + "/status?hostname=" + me.hostname url = urlbase + "/status?hostname=" + me.hostname
msg, err := me.packages.Marshal() msg, err := me.machine.Packages.Marshal()
if err != nil { if err != nil {
log.Info("proto.Marshal() failed:", err) log.Info("proto.Marshal() failed:", err)
return err return err

View File

@ -16,5 +16,5 @@ type stuff struct {
dog *time.Ticker // the watchdog timer dog *time.Ticker // the watchdog timer
distro string // debian,redhat,gentoo,macos,wincrap distro string // debian,redhat,gentoo,macos,wincrap
machine *zoopb.Machine // my protobuf machine *zoopb.Machine // my protobuf
packages *zoopb.Packages // installed packages and versions // packages *zoopb.Packages // installed packages and versions
} }