@@ -40,53 +40,59 @@ func StartPeriodicals(context *context.Ctx) {
40
40
go func () {
41
41
configChecksums := make (map [string ]string )
42
42
backendChecksum := ""
43
+ assignmentChecksum := ""
43
44
logOnce := true
44
45
for {
45
46
time .Sleep (time .Duration (context .UserConfig .UpdateInterval ) * time .Second )
46
47
47
48
// registration response contains configuration assignments
48
- response , err := updateCollectorRegistration (httpClient , context )
49
+ response , err := updateCollectorRegistration (httpClient , assignmentChecksum , context )
49
50
if err != nil {
50
51
continue
51
52
}
53
+ assignmentChecksum = response .Checksum
52
54
// backend list is needed before configuration assignments are updated
53
- backendChecksum , err = fetchBackendList (httpClient , backendChecksum , context )
55
+ backendResponse , err : = fetchBackendList (httpClient , backendChecksum , context )
54
56
if err != nil {
55
57
continue
56
58
}
57
- assignments .Store .Update (response .Assignments )
58
- // create process instances
59
- daemon .Daemon .SyncWithAssignments (configChecksums , context )
60
- // test for new or updated configurations and start the corresponding collector
61
- if assignments .Store .Len () == 0 {
62
- if logOnce {
63
- log .Info ("No configurations assigned to this instance. Skipping configuration request." )
64
- logOnce = false
59
+ backendChecksum = backendResponse .Checksum
60
+
61
+ if ! response .NotModified || ! backendResponse .NotModified {
62
+ assignments .Store .Update (response .Assignments )
63
+ // create process instances
64
+ daemon .Daemon .SyncWithAssignments (configChecksums , context )
65
+ // test for new or updated configurations and start the corresponding collector
66
+ if assignments .Store .Len () == 0 {
67
+ if logOnce {
68
+ log .Info ("No configurations assigned to this instance. Skipping configuration request." )
69
+ logOnce = false
70
+ }
71
+ continue
72
+ } else {
73
+ logOnce = true
65
74
}
66
- continue
67
- } else {
68
- logOnce = true
69
75
}
70
76
checkForUpdateAndRestart (httpClient , configChecksums , context )
71
77
}
72
78
}()
73
79
}
74
80
75
- // report collector status to Graylog server
76
- func updateCollectorRegistration (httpClient * http.Client , context * context.Ctx ) (graylog.ResponseCollectorRegistration , error ) {
81
+ // report collector status to Graylog server and receive assignments
82
+ func updateCollectorRegistration (httpClient * http.Client , checksum string , context * context.Ctx ) (graylog.ResponseCollectorRegistration , error ) {
77
83
statusRequest := api .NewStatusRequest ()
78
- return api .UpdateRegistration (httpClient , context , & statusRequest )
84
+ return api .UpdateRegistration (httpClient , checksum , context , & statusRequest )
79
85
}
80
86
81
- func fetchBackendList (httpClient * http.Client , checksum string , ctx * context.Ctx ) (string , error ) {
87
+ func fetchBackendList (httpClient * http.Client , checksum string , ctx * context.Ctx ) (graylog. ResponseBackendList , error ) {
82
88
response , err := api .RequestBackendList (httpClient , checksum , ctx )
83
89
if err != nil {
84
90
log .Error ("Can't fetch collector list from Graylog API: " , err )
85
- return "" , err
91
+ return response , err
86
92
}
87
- if response .IsEmpty () {
93
+ if response .NotModified {
88
94
// etag match, skipping all other actions
89
- return response . Checksum , nil
95
+ return response , nil
90
96
}
91
97
92
98
backendList := []backends.Backend {}
@@ -95,7 +101,7 @@ func fetchBackendList(httpClient *http.Client, checksum string, ctx *context.Ctx
95
101
}
96
102
backends .Store .Update (backendList )
97
103
98
- return response . Checksum , nil
104
+ return response , nil
99
105
}
100
106
101
107
// fetch configuration periodically
@@ -113,13 +119,13 @@ func checkForUpdateAndRestart(httpClient *http.Client, checksums map[string]stri
113
119
return
114
120
}
115
121
116
- if response .IsEmpty () {
122
+ if response .NotModified {
117
123
// etag match, skip file render
118
124
continue
119
125
}
126
+ checksums [backendId ] = response .Checksum
120
127
121
128
if backend .RenderOnChange (backends.Backend {Template : response .Template }, context ) {
122
- checksums [backendId ] = response .Checksum
123
129
if err , output := backend .ValidateConfigurationFile (context ); err != nil {
124
130
backend .SetStatusLogErrorf (err .Error ())
125
131
if output != "" {
0 commit comments