diff --git a/api/graylog.go b/api/graylog.go index f12fc16..306ff46 100644 --- a/api/graylog.go +++ b/api/graylog.go @@ -233,10 +233,10 @@ func NewStatusRequest() graylog.StatusRequest { statusRequest := graylog.StatusRequest{Backends: make([]graylog.StatusRequestBackend, 0)} combined, count := system.GlobalStatus.Status, 0 - for name, runner := range daemon.Daemon.Runner { + for id, runner := range daemon.Daemon.Runner { backendStatus := runner.GetBackend().Status() statusRequest.Backends = append(statusRequest.Backends, graylog.StatusRequestBackend{ - Name: name, + Id: id, Status: backendStatus.Status, Message: backendStatus.Message, }) diff --git a/api/graylog/requests.go b/api/graylog/requests.go index b59ad95..1a4e63c 100644 --- a/api/graylog/requests.go +++ b/api/graylog/requests.go @@ -33,7 +33,7 @@ type NodeDetailsRequest struct { } type StatusRequestBackend struct { - Name string `json:"name"` + Id string `json:"collector_id"` Status int `json:"status"` Message string `json:"message"` } diff --git a/backends/registry.go b/backends/registry.go index 8385c3e..d58be8b 100644 --- a/backends/registry.go +++ b/backends/registry.go @@ -31,23 +31,23 @@ type backendStore struct { } func (bs *backendStore) SetBackend(backend Backend) { - bs.backends[backend.Name] = &backend + bs.backends[backend.Id] = &backend executeParameters, err := common.SprintfList(backend.ExecuteParameters, backend.ConfigurationPath) if err != nil { log.Errorf("Invalid execute parameters, skip adding backend: %s", backend.Name) return } - bs.backends[backend.Name].ExecuteParameters = executeParameters + bs.backends[backend.Id].ExecuteParameters = executeParameters validationParameters, err := common.SprintfList(backend.ValidationParameters, backend.ConfigurationPath) if err != nil { log.Errorf("Invalid validation parameters, skip adding backend: %s", backend.Name) return } - bs.backends[backend.Name].ValidationParameters = validationParameters + bs.backends[backend.Id].ValidationParameters = validationParameters } -func (bs *backendStore) GetBackend(name string) *Backend { - return bs.backends[name] +func (bs *backendStore) GetBackend(id string) *Backend { + return bs.backends[id] } func (bs *backendStore) GetBackendById(id string) *Backend { @@ -66,11 +66,11 @@ func (bs *backendStore) Update(backends []Backend) { activeIds = append(activeIds, backend.Id) // add new backend - if bs.backends[backend.Name] == nil { + if bs.backends[backend.Id] == nil { bs.SetBackend(backend) // update if settings did change } else { - if !bs.backends[backend.Name].EqualSettings(&backend) { + if !bs.backends[backend.Id].EqualSettings(&backend) { bs.SetBackend(backend) } } @@ -85,7 +85,7 @@ func (bs *backendStore) Cleanup(validBackendIds []string) { for _, backend := range bs.backends { if !common.IsInList(backend.Id, validBackendIds) { log.Debug("Cleaning up backend: " + backend.Name) - delete(bs.backends, backend.Name) + delete(bs.backends, backend.Id) } } } diff --git a/daemon/action_handler.go b/daemon/action_handler.go index 34b477a..0cd092b 100644 --- a/daemon/action_handler.go +++ b/daemon/action_handler.go @@ -43,31 +43,31 @@ func HandleCollectorActions(actions []graylog.ResponseCollectorAction) { } func startAction(backend *backends.Backend) { - for name, runner := range Daemon.Runner { - if name == backend.Name { + for id, runner := range Daemon.Runner { + if id == backend.Id { if !runner.Running() { - log.Infof("[%s] Staring collector", name) + log.Infof("[%s] Staring collector", backend.Name) runner.Restart() } else { - log.Infof("Collector [%s] is already running, skipping start action.", name) + log.Infof("Collector [%s] is already running, skipping start action.", backend.Name) } } } } func restartAction(backend *backends.Backend) { - for name, runner := range Daemon.Runner { - if name == backend.Name { - log.Infof("[%s] Restarting collector", name) + for id, runner := range Daemon.Runner { + if id == backend.Id { + log.Infof("[%s] Restarting collector", backend.Name) runner.Restart() } } } func stopAction(backend *backends.Backend) { - for name, runner := range Daemon.Runner { - if name == backend.Name { - log.Infof("[%s] Stopping collector", name) + for id, runner := range Daemon.Runner { + if id == backend.Id { + log.Infof("[%s] Stopping collector", backend.Name) runner.Shutdown() } } diff --git a/daemon/daemon.go b/daemon/daemon.go index a1a87a3..7639ace 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -82,20 +82,20 @@ func (dc *DaemonConfig) AddRunner(backend backends.Backend, context *context.Ctx log.Fatalf("Execution driver %s is not supported on this platform", backend.ServiceType) } runner.SetDaemon(dc) - dc.Runner[backend.Name] = runner + dc.Runner[backend.Id] = runner } -func (dc *DaemonConfig) DeleteRunner(backendName string) { - if dc.Runner[backendName] == nil { +func (dc *DaemonConfig) DeleteRunner(backendId string) { + if dc.Runner[backendId] == nil { return } - if dc.Runner[backendName].Running() { - if err := dc.Runner[backendName].Shutdown(); err != nil { - log.Errorf("[%s] Failed to stop backend during deletion: %v", backendName, err) + if dc.Runner[backendId].Running() { + if err := dc.Runner[backendId].Shutdown(); err != nil { + log.Errorf("[%s] Failed to stop backend during deletion: %v", backendId, err) } } - delete(dc.Runner, backendName) + delete(dc.Runner, backendId) } func (dc *DaemonConfig) GetRunnerByBackendId(id string) Runner { @@ -112,8 +112,8 @@ func (dc *DaemonConfig) SyncWithAssignments(context *context.Ctx) { return } - for name, runner := range dc.Runner { - backend := backends.Store.GetBackend(name) + for id, runner := range dc.Runner { + backend := backends.Store.GetBackend(id) // update outdated runner backend runnerBackend := runner.GetBackend() @@ -124,15 +124,15 @@ func (dc *DaemonConfig) SyncWithAssignments(context *context.Ctx) { // cleanup backends that should not run anymore if backend == nil || assignments.Store.GetAll()[backend.Id] == "" { - log.Info("Removing process runner: " + name) - dc.DeleteRunner(name) + log.Info("Removing process runner: " + backend.Name) + dc.DeleteRunner(id) } } // add new backends to registry for backendId := range assignments.Store.GetAll() { backend := backends.Store.GetBackendById(backendId) - if backend != nil && dc.Runner[backend.Name] == nil { + if backend != nil && dc.Runner[backend.Id] == nil { log.Info("Adding process runner for: " + backend.Name) dc.AddRunner(*backend, context) } diff --git a/daemon/exec_runner.go b/daemon/exec_runner.go index 3af2be1..2d651af 100644 --- a/daemon/exec_runner.go +++ b/daemon/exec_runner.go @@ -106,6 +106,7 @@ func (r *ExecRunner) GetBackend() *backends.Backend { func (r *ExecRunner) SetBackend(b backends.Backend) { r.backend = b + r.name = b.Name r.exec = b.ExecutablePath r.args = b.ExecuteParameters r.restartCount = 1 diff --git a/daemon/svc_runner_windows.go b/daemon/svc_runner_windows.go index 1bcc70f..e95fbb2 100644 --- a/daemon/svc_runner_windows.go +++ b/daemon/svc_runner_windows.go @@ -113,6 +113,7 @@ func (r *SvcRunner) GetBackend() *backends.Backend { func (r *SvcRunner) SetBackend(b backends.Backend) { r.backend = b + r.name = b.Name r.exec = b.ExecutablePath r.args = b.ExecuteParameters } diff --git a/services/periodicals.go b/services/periodicals.go index 56faf0e..92ab69c 100644 --- a/services/periodicals.go +++ b/services/periodicals.go @@ -121,7 +121,7 @@ func checkForUpdateAndRestart(httpClient *http.Client, checksum string, context continue } - if err := daemon.Daemon.Runner[backend.Name].Restart(); err != nil { + if err := daemon.Daemon.Runner[backend.Id].Restart(); err != nil { msg := "Failed to restart collector" backend.SetStatus(backends.StatusError, msg) log.Errorf("[%s] %s: %v", backend.Name, msg, err)