connects to zookeeper
This commit is contained in:
parent
9e4045f35e
commit
1e9ee55a8e
14
Makefile
14
Makefile
|
@ -1,3 +1,5 @@
|
||||||
|
.PHONY: build
|
||||||
|
|
||||||
VERSION = $(shell git describe --tags)
|
VERSION = $(shell git describe --tags)
|
||||||
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||||
|
|
||||||
|
@ -5,11 +7,17 @@ BUILDTIME = $(shell date +%Y.%m.%d_%H%M)
|
||||||
# REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi)
|
# REDOMOD = $(shell if [ -e go.mod ]; then echo go.mod; else echo no go mod; fi)
|
||||||
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
|
REDOMOD = $(shell if [ -e go.sum ]; then echo go.sum exists; else GO111MODULE= go mod init; GO111MODULE= go mod tidy; fi)
|
||||||
|
|
||||||
all:
|
all: build
|
||||||
|
./zood --version
|
||||||
|
./zood
|
||||||
|
|
||||||
|
build:
|
||||||
GO111MODULE=off go build \
|
GO111MODULE=off go build \
|
||||||
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
#./zood
|
|
||||||
./zood --version
|
install:
|
||||||
|
GO111MODULE=off go install \
|
||||||
|
-ldflags "-X main.VERSION=${VERSION} -X main.BUILDTIME=${BUILDTIME} -X gui.GUIVERSION=${VERSION}"
|
||||||
|
|
||||||
# this is for release builds using the go.mod files
|
# this is for release builds using the go.mod files
|
||||||
release-build:
|
release-build:
|
||||||
|
|
41
apt.go
41
apt.go
|
@ -30,3 +30,44 @@ func initPackages() {
|
||||||
|
|
||||||
log.Info(me.hostname, "has distro", me.distro, "with", me.packages.Len(), "packages installed")
|
log.Info(me.hostname, "has distro", me.distro, "with", me.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)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updatePackages() {
|
||||||
|
// Get the list of installed packages for the detected distro
|
||||||
|
newP, err := getPackageList(me.distro)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("Error:", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var newCounter, changeCounter int
|
||||||
|
// Print the installed packages and their versions
|
||||||
|
for pkg, version := range newP {
|
||||||
|
found := me.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) {
|
||||||
|
changeCounter += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
footer := fmt.Sprintf("%s has distro %s with %d packages installed", me.hostname, me.distro, me.packages.Len())
|
||||||
|
if changeCounter != 0 {
|
||||||
|
footer += fmt.Sprintf(" (%d changed)", changeCounter)
|
||||||
|
}
|
||||||
|
if newCounter != 0 {
|
||||||
|
footer += fmt.Sprintf(" (%d new)", newCounter)
|
||||||
|
}
|
||||||
|
log.Info(footer)
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"os/user"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
func httpPost(url string, data []byte) ([]byte, error) {
|
||||||
|
var err error
|
||||||
|
var req *http.Request
|
||||||
|
|
||||||
|
// data := []byte("some junk")
|
||||||
|
// url := "https://go.wit.com/register/"
|
||||||
|
|
||||||
|
req, err = http.NewRequest(http.MethodPost, url, bytes.NewBuffer(data))
|
||||||
|
|
||||||
|
usr, _ := user.Current()
|
||||||
|
req.Header.Set("author", usr.Username)
|
||||||
|
hostname, _ := os.Hostname()
|
||||||
|
req.Header.Set("hostname", hostname)
|
||||||
|
|
||||||
|
client := &http.Client{}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return []byte("client.Do(req) error"), err
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return body, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// test := strings.TrimSpace(string(body))
|
||||||
|
// log.Info("go.wit.com returned body:", test)
|
||||||
|
// if test == "OK" {
|
||||||
|
// return body, nil
|
||||||
|
// }
|
||||||
|
|
||||||
|
return body, nil
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright 2024 WIT.COM Inc Licensed GPL 3.0
|
||||||
|
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"go.wit.com/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var urlbase string = "http://localhost:8080"
|
||||||
|
|
||||||
|
func send() {
|
||||||
|
}
|
||||||
|
|
||||||
|
func pingStatus() error {
|
||||||
|
var url string
|
||||||
|
url = urlbase + "/status"
|
||||||
|
body, err := httpPost(url, nil)
|
||||||
|
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") {
|
||||||
|
log.Info("GOT:", line)
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
|
@ -32,6 +32,8 @@ func NewWatchdog() {
|
||||||
return
|
return
|
||||||
case t := <-me.dog.C:
|
case t := <-me.dog.C:
|
||||||
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
|
log.Info("Watchdog() ticked", me.zookeeper, "Current time: ", t)
|
||||||
|
updatePackages()
|
||||||
|
pingStatus()
|
||||||
// h.pollHypervisor()
|
// h.pollHypervisor()
|
||||||
// h.Scan()
|
// h.Scan()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue