From 44ca7407ece56687ad1296bac4fba08e6df2e2f7 Mon Sep 17 00:00:00 2001 From: Julien Pivotto Date: Tue, 7 Mar 2023 14:47:10 +0100 Subject: [PATCH] Fix service host Signed-off-by: Julien Pivotto --- webhook/hook.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webhook/hook.go b/webhook/hook.go index 439f204..f79ce94 100644 --- a/webhook/hook.go +++ b/webhook/hook.go @@ -101,25 +101,28 @@ func Webhook(w http.ResponseWriter, r *http.Request, c config.Configuration) { if name, ok := data.CommonLabels["instance"]; ok { l.V(2).Infof("Creating host %v", name) - host, err = icinga.GetHost(serviceHost) + host, err = icinga.GetHost(name) if err != nil { err := icinga.CreateHost(icinga2.Host{ Name: name, DisplayName: name, Notes: "Created by signalio", + Address: name, }) if err != nil { l.Errorf("Could not create service host %v: %v\n", host, err) asJSON(w, http.StatusInternalServerError, err.Error()) return } - host, err = icinga.GetHost(serviceHost) + host, err = icinga.GetHost(name) if err != nil { l.Errorf("Did not find service host %v: %v\n", host, err) asJSON(w, http.StatusInternalServerError, err.Error()) return } } + serviceHost = name + l.V(2).Infof("Using host %v=%v", name, host) } else { l.V(2).Infof("No instance label") }