detect out of order alarm log entries when loading them
Costa Tsaousis (ktsaou) committed
Oct 16, 2016 at 15:38 UTC
cb2bc8db75ea9973bd675ba96825ec46e3fd21ba
1 file changed
+11
-3
src/health.c
+11
-3
@@ -174,10 +174,11 @@ static inline ssize_t health_alarm_log_load(RRDHOST *host) {
174
}
175
176
// find a possible overwrite
177
- for(ae = host->health_log.alarms; ae ;ae = ae->next) {
177
+ for(ae = host->health_log.alarms; ae; ae = ae->next) {
178
if(unlikely(ae->unique_id == unique_id)) {
179
if(unlikely(*pointers[0] == 'A')) {
180
- error("Health: line %zu of file '%s' adds duplicate alarm log entry with unique id %u.", line, health.log_filename, unique_id);
180
+ error("Health: line %zu of file '%s' adds duplicate alarm log entry with unique id %u."
181
+ , line, health.log_filename, unique_id);
182
*pointers[0] = 'U';
183
duplicate++;
184
}
@@ -187,12 +188,19 @@ static inline ssize_t health_alarm_log_load(RRDHOST *host) {
188
189
// if not found, create a new one
190
if(likely(!ae)) {
191
+
192
// if it is an update, but we haven't found it, make it an addition
193
if(unlikely(*pointers[0] == 'U')) {
194
*pointers[0] = 'A';
195
error("Health: line %zu of file '%s' updates alarm log entry with unique id %u, but it is not found.", line, health.log_filename, unique_id);
196
}
197
198
+ // alarms should be added in the right order
199
+ if(unlikely(unique_id < max_unique_id)) {
200
+ error("Health: line %zu of file '%s' has alarm log entry with %u in wrong order.", line
201
+ , health.log_filename, ae->unique_id);
202
+ }
203
+
204
ae = callocz(1, sizeof(ALARM_ENTRY));
205
}
206
@@ -285,7 +293,7 @@ static inline ssize_t health_alarm_log_load(RRDHOST *host) {
293
host->health_log.next_log_id = max_unique_id + 1;
294
host->health_log.next_alarm_id = max_alarm_id + 1;
295
288
- fprintf(stderr, "Health loaded %zd alarms, updated %zd alarms, errors %zd entries, duplicate %zd\n", loaded, updated, errored, duplicate);
296
+ info("Health: loaded %zd alarms, updated %zd alarms, errors %zd entries, duplicate %zd", loaded, updated, errored, duplicate);
297
298
health_alarm_log_open();
299
return loaded;