From fef7d94508a6e0decbb134bbdea91f088727c9a9 Mon Sep 17 00:00:00 2001 From: Jean Flach Date: Thu, 7 Mar 2019 17:24:01 +0100 Subject: [PATCH] Make use of Hosts and Envs --- configobject/host.go | 11 +++++++---- main.go | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/configobject/host.go b/configobject/host.go index 3e98301c..e4c114cd 100644 --- a/configobject/host.go +++ b/configobject/host.go @@ -1,7 +1,6 @@ package configobject import ( - "fmt" "git.icinga.com/icingadb/icingadb-json-decoder" "git.icinga.com/icingadb/icingadb-main/supervisor" "git.icinga.com/icingadb/icingadb-utils" @@ -120,21 +119,25 @@ func (h Host) UpdateValues() []interface{} { return v } -func (h *Host) GetId() string { +func (h Host) GetId() string { return h.Id } -func (h *Host) SetId(id string) { +func (h Host) SetId(id string) { h.Id = id } func HostOperator(super *supervisor.Supervisor) error { chBack := make(chan *icingadb_json_decoder.JsonDecodePackage) + var hosts = map[[20]byte]*Host{} //get checksums from redis go func() { res, err := super.Rdbw.HGetAll("icinga:config:checksum:host") count := len(res) + + hosts = make(map[[20]byte]*Host, count) + if err != nil { super.ChErr <- err return @@ -154,7 +157,7 @@ func HostOperator(super *supervisor.Supervisor) error { }() for ret := range chBack { - fmt.Println(ret) + hosts[ret.Id] = ret.Row.(*Host) count-- if 0 == count { close(chBack) diff --git a/main.go b/main.go index c85defe2..363dd5ef 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,21 @@ func main() { chErr <- configobject.HostOperator(&super) }() + for { + select { + case err := <- chErr: + if err != nil { + log.Fatal(err) + return + } + case env := <- super.ChEnv: { + if env != nil { + log.Print("Got env: " + hex.EncodeToString(env.ID)) + } + } + } + } + //go create object type supervisors