sending a machine protobuf

This commit is contained in:
Jeff Carr 2024-11-15 20:59:42 -06:00
parent 0700306530
commit 706b0418bf
4 changed files with 41 additions and 2 deletions

View File

@ -52,6 +52,10 @@ func main() {
// what OS? // what OS?
me.distro = initDistro() me.distro = initDistro()
// init my machine protobuf
me.machine = new(zoopb.Machine)
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()

37
send.go
View File

@ -15,7 +15,7 @@ func send() {
func pingStatus() error { func pingStatus() error {
var url string var url string
url = urlbase + "/status?hostname=stuff" url = urlbase + "/status?hostname=" + me.hostname
msg, err := me.packages.Marshal() msg, err := me.packages.Marshal()
if err != nil { if err != nil {
log.Info("proto.Marshal() failed:", err) log.Info("proto.Marshal() failed:", err)
@ -31,7 +31,40 @@ func pingStatus() error {
test := strings.TrimSpace(string(body)) test := strings.TrimSpace(string(body))
// log.Info("virtigo returned body:", test) // log.Info("virtigo returned body:", test)
for _, line := range strings.Split(test, "\n") { 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 return nil
} }

View File

@ -15,5 +15,6 @@ type stuff struct {
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
distro string // debian,redhat,gentoo,macos,wincrap 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
} }

View File

@ -34,6 +34,7 @@ func NewWatchdog() {
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t) log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
updatePackages() updatePackages()
pingStatus() pingStatus()
sendMachine()
// h.pollHypervisor() // h.pollHypervisor()
// h.Scan() // h.Scan()
} }