Skip to content

Commit 0f07b9a

Browse files
authored
Handle action requests for collectors (#444)
An action is retrieved per collector ID. We need to iterate over all backends for a collector and execute that action.
1 parent 5541513 commit 0f07b9a

File tree

3 files changed

+26
-12
lines changed

3 files changed

+26
-12
lines changed

backends/backend.go

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ type Backend struct {
3636
Enabled *bool
3737
Id string
3838
ConfigId string
39+
CollectorId string
3940
Name string
4041
ServiceType string
4142
OperatingSystem string
@@ -51,6 +52,7 @@ func BackendFromResponse(response graylog.ResponseCollectorBackend, configId str
5152
return &Backend{
5253
Enabled: common.NewTrue(),
5354
Id: response.Id + "-" + configId,
55+
CollectorId: response.Id,
5456
ConfigId: configId,
5557
Name: response.Name + "-" + configId,
5658
ServiceType: response.ServiceType,
@@ -83,6 +85,7 @@ func (b *Backend) EqualSettings(a *Backend) bool {
8385
Enabled: b.Enabled,
8486
Id: a.Id,
8587
ConfigId: a.ConfigId,
88+
CollectorId: a.CollectorId,
8689
Name: a.Name,
8790
ServiceType: a.ServiceType,
8891
OperatingSystem: a.OperatingSystem,

backends/registry.go

+10
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@ func (bs *backendStore) SetBackend(backend Backend) {
4646
bs.backends[backend.Id].ValidationParameters = validationParameters
4747
}
4848

49+
func (bs *backendStore) GetBackendsForCollectorId(collectorId string) []*Backend {
50+
var backends []*Backend
51+
for _, backend := range bs.backends {
52+
if backend.CollectorId == collectorId {
53+
backends = append(backends, backend)
54+
}
55+
}
56+
return backends
57+
}
58+
4959
func (bs *backendStore) GetBackend(id string) *Backend {
5060
return bs.backends[id]
5161
}

daemon/action_handler.go

+13-12
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,22 @@ import (
2323

2424
func HandleCollectorActions(actions []graylog.ResponseCollectorAction) {
2525
for _, action := range actions {
26-
backend := backends.Store.GetBackend(action.BackendId)
27-
if backend == nil {
26+
backends := backends.Store.GetBackendsForCollectorId(action.BackendId)
27+
if backends == nil {
2828
log.Errorf("Got action for non-existing collector: %s", action.BackendId)
2929
continue
3030
}
31-
32-
switch {
33-
case action.Properties["start"] == true:
34-
startAction(backend)
35-
case action.Properties["restart"] == true:
36-
restartAction(backend)
37-
case action.Properties["stop"] == true:
38-
stopAction(backend)
39-
default:
40-
log.Infof("Got unsupported collector command: %s", common.Inspect(action.Properties))
31+
for _, backend := range backends {
32+
switch {
33+
case action.Properties["start"] == true:
34+
startAction(backend)
35+
case action.Properties["restart"] == true:
36+
restartAction(backend)
37+
case action.Properties["stop"] == true:
38+
stopAction(backend)
39+
default:
40+
log.Infof("Got unsupported collector command: %s", common.Inspect(action.Properties))
41+
}
4142
}
4243
}
4344
}

0 commit comments

Comments
 (0)