178
}
179
180
static inline int health_parse_delay(
181
- size_t line, const char *path, const char *file, char *string,
181
+ size_t line, const char *filename, char *string,
182
int *delay_up_duration,
183
int *delay_down_duration,
184
int *delay_max_duration,
204
205
if(!strcasecmp(key, "up")) {
206
if (!health_parse_duration(value, delay_up_duration)) {
207
- error("Health configuration at line %zu of file '%s/%s': invalid value '%s' for '%s' keyword",
208
- line, path, file, value, key);
207
+ error("Health configuration at line %zu of file '%s': invalid value '%s' for '%s' keyword",
208
+ line, filename, value, key);
209
}
210
else given_up = 1;
211
}
212
else if(!strcasecmp(key, "down")) {
213
if (!health_parse_duration(value, delay_down_duration)) {
214
- error("Health configuration at line %zu of file '%s/%s': invalid value '%s' for '%s' keyword",
215
- line, path, file, value, key);
214
+ error("Health configuration at line %zu of file '%s': invalid value '%s' for '%s' keyword",
215
+ line, filename, value, key);
216
}
217
else given_down = 1;
218
}
219
else if(!strcasecmp(key, "multiplier")) {
220
*delay_multiplier = strtof(value, NULL);
221
if(isnan(*delay_multiplier) || isinf(*delay_multiplier) || islessequal(*delay_multiplier, 0)) {
222
- error("Health configuration at line %zu of file '%s/%s': invalid value '%s' for '%s' keyword",
223
- line, path, file, value, key);
222
+ error("Health configuration at line %zu of file '%s': invalid value '%s' for '%s' keyword",
223
+ line, filename, value, key);
224
}
225
else given_multiplier = 1;
226
}
227
else if(!strcasecmp(key, "max")) {
228
if (!health_parse_duration(value, delay_max_duration)) {
229
- error("Health configuration at line %zu of file '%s/%s': invalid value '%s' for '%s' keyword",
230
- line, path, file, value, key);
229
+ error("Health configuration at line %zu of file '%s': invalid value '%s' for '%s' keyword",
230
+ line, filename, value, key);
231
}
232
else given_max = 1;
233
}
234
else {
235
- error("Health configuration at line %zu of file '%s/%s': unknown keyword '%s'",
236
- line, path, file, key);
235
+ error("Health configuration at line %zu of file '%s': unknown keyword '%s'",
236
+ line, filename, key);
237
}
238
}
239
287
}
288
289
static inline int health_parse_db_lookup(
290
- size_t line, const char *path, const char *file, char *string,
290
+ size_t line, const char *filename, char *string,
291
int *group_method, int *after, int *before, int *every,
292
uint32_t *options, char **dimensions
293
) {
294
- debug(D_HEALTH, "Health configuration parsing database lookup %zu@%s/%s: %s", line, path, file, string);
294
+ debug(D_HEALTH, "Health configuration parsing database lookup %zu@%s: %s", line, filename, string);
295
296
if(*dimensions) freez(*dimensions);
297
*dimensions = NULL;
307
while(*s && !isspace(*s)) s++;
308
while(*s && isspace(*s)) *s++ = '\0';
309
if(!*s) {
310
- error("Health configuration invalid chart calculation at line %zu of file '%s/%s': expected group method followed by the 'after' time, but got '%s'",
311
- line, path, file, key);
310
+ error("Health configuration invalid chart calculation at line %zu of file '%s': expected group method followed by the 'after' time, but got '%s'",
311
+ line, filename, key);
312
return 0;
313
}
314
315
if((*group_method = web_client_api_request_v1_data_group(key, -1)) == -1) {
316
- error("Health configuration at line %zu of file '%s/%s': invalid group method '%s'",
317
- line, path, file, key);
316
+ error("Health configuration at line %zu of file '%s': invalid group method '%s'",
317
+ line, filename, key);
318
return 0;
319
}
320
324
while(*s && isspace(*s)) *s++ = '\0';
325
326
if(!health_parse_duration(key, after)) {
327
- error("Health configuration at line %zu of file '%s/%s': invalid duration '%s' after group method",
328
- line, path, file, key);
327
+ error("Health configuration at line %zu of file '%s': invalid duration '%s' after group method",
328
+ line, filename, key);
329
return 0;
330
}
331
345
while(*s && isspace(*s)) *s++ = '\0';
346
347
if (!health_parse_duration(value, before)) {
348
- error("Health configuration at line %zu of file '%s/%s': invalid duration '%s' for '%s' keyword",
349
- line, path, file, value, key);
348
+ error("Health configuration at line %zu of file '%s': invalid duration '%s' for '%s' keyword",
349
+ line, filename, value, key);
350
}
351
}
352
else if(!strcasecmp(key, HEALTH_EVERY_KEY)) {
355
while(*s && isspace(*s)) *s++ = '\0';
356
357
if (!health_parse_duration(value, every)) {
358
- error("Health configuration at line %zu of file '%s/%s': invalid duration '%s' for '%s' keyword",
359
- line, path, file, value, key);
358
+ error("Health configuration at line %zu of file '%s': invalid duration '%s' for '%s' keyword",
359
+ line, filename, value, key);
360
}
361
}
362
else if(!strcasecmp(key, "absolute") || !strcasecmp(key, "abs") || !strcasecmp(key, "absolute_sum")) {
386
break;
387
}
388
else {
389
- error("Health configuration at line %zu of file '%s/%s': unknown keyword '%s'",
390
- line, path, file, key);
389
+ error("Health configuration at line %zu of file '%s': unknown keyword '%s'",
390
+ line, filename, key);
391
}
392
}
393
394
return 1;
395
}
396
397
-static inline char *health_source_file(size_t line, const char *path, const char *filename) {
397
+static inline char *health_source_file(size_t line, const char *file) {
398
char buffer[FILENAME_MAX + 1];
399
- snprintfz(buffer, FILENAME_MAX, "%zu@%s/%s", line, path, filename);
399
+ snprintfz(buffer, FILENAME_MAX, "%zu@%s", line, file);
400
return strdupz(buffer);
401
}
402
407
}
408
}
409
410
-int health_readfile(RRDHOST *host, const char *path, const char *filename) {
411
- debug(D_HEALTH, "Health configuration reading file '%s/%s'", path, filename);
410
+static int health_readfile(const char *filename, void *data) {
411
+ RRDHOST *host = (RRDHOST *)data;
412
+
413
+ debug(D_HEALTH, "Health configuration reading file '%s'", filename);
414
415
static uint32_t
416
hash_alarm = 0,
457
hash_options = simple_uhash(HEALTH_OPTIONS_KEY);
458
}
459
458
- snprintfz(buffer, HEALTH_CONF_MAX_LINE, "%s/%s", path, filename);
459
- FILE *fp = fopen(buffer, "r");
460
+ FILE *fp = fopen(filename, "r");
461
if(!fp) {
461
- error("Health configuration cannot read file '%s'.", buffer);
462
+ error("Health configuration cannot read file '%s'.", filename);
463
return 0;
464
}
465
482
if(append < HEALTH_CONF_MAX_LINE)
483
continue;
484
else {
484
- error("Health configuration has too long muli-line at line %zu of file '%s/%s'.", line, path, filename);
485
+ error("Health configuration has too long muli-line at line %zu of file '%s'.", line, filename);
486
}
487
}
488
append = 0;
490
char *key = s;
491
while(*s && *s != ':') s++;
492
if(!*s) {
492
- error("Health configuration has invalid line %zu of file '%s/%s'. It does not contain a ':'. Ignoring it.", line, path, filename);
493
+ error("Health configuration has invalid line %zu of file '%s'. It does not contain a ':'. Ignoring it.", line, filename);
494
continue;
495
}
496
*s = '\0';
501
value = trim_all(value);
502
503
if(!key) {
503
- error("Health configuration has invalid line %zu of file '%s/%s'. Keyword is empty. Ignoring it.", line, path, filename);
504
+ error("Health configuration has invalid line %zu of file '%s'. Keyword is empty. Ignoring it.", line, filename);
505
continue;
506
}
507
508
if(!value) {
508
- error("Health configuration has invalid line %zu of file '%s/%s'. value is empty. Ignoring it.", line, path, filename);
509
+ error("Health configuration has invalid line %zu of file '%s'. value is empty. Ignoring it.", line, filename);
510
continue;
511
}
512
527
rc->next_event_id = 1;
528
rc->name = strdupz(value);
529
rc->hash = simple_hash(rc->name);
529
- rc->source = health_source_file(line, path, filename);
530
+ rc->source = health_source_file(line, filename);
531
rc->green = NAN;
532
rc->red = NAN;
533
rc->value = NAN;
553
rt = callocz(1, sizeof(RRDCALCTEMPLATE));
554
rt->name = strdupz(value);
555
rt->hash_name = simple_hash(rt->name);
555
- rt->source = health_source_file(line, path, filename);
556
+ rt->source = health_source_file(line, filename);
557
rt->green = NAN;
558
rt->red = NAN;
559
rt->delay_multiplier = 1.0;
569
570
if(!simple_pattern_matches(os_pattern, host->os)) {
571
if(rc)
571
- debug(D_HEALTH, "HEALTH on '%s' ignoring alarm '%s' defined at %zu@%s/%s: host O/S does not match '%s'", host->hostname, rc->name, line, path, filename, os_match);
572
+ debug(D_HEALTH, "HEALTH on '%s' ignoring alarm '%s' defined at %zu@%s: host O/S does not match '%s'", host->hostname, rc->name, line, filename, os_match);
573
574
if(rt)
574
- debug(D_HEALTH, "HEALTH on '%s' ignoring template '%s' defined at %zu@%s/%s: host O/S does not match '%s'", host->hostname, rt->name, line, path, filename, os_match);
575
+ debug(D_HEALTH, "HEALTH on '%s' ignoring template '%s' defined at %zu@%s: host O/S does not match '%s'", host->hostname, rt->name, line, filename, os_match);
576
577
ignore_this = 1;
578
}
585
586
if(!simple_pattern_matches(host_pattern, host->hostname)) {
587
if(rc)
587
- debug(D_HEALTH, "HEALTH on '%s' ignoring alarm '%s' defined at %zu@%s/%s: hostname does not match '%s'", host->hostname, rc->name, line, path, filename, host_match);
588
+ debug(D_HEALTH, "HEALTH on '%s' ignoring alarm '%s' defined at %zu@%s: hostname does not match '%s'", host->hostname, rc->name, line, filename, host_match);
589
590
if(rt)
590
- debug(D_HEALTH, "HEALTH on '%s' ignoring template '%s' defined at %zu@%s/%s: hostname does not match '%s'", host->hostname, rt->name, line, path, filename, host_match);
591
+ debug(D_HEALTH, "HEALTH on '%s' ignoring template '%s' defined at %zu@%s: hostname does not match '%s'", host->hostname, rt->name, line, filename, host_match);
592
593
ignore_this = 1;
594
}
599
if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
600
if(rc->chart) {
601
if(strcmp(rc->chart, value) != 0)
601
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
602
- line, path, filename, rc->name, key, rc->chart, value, value);
602
+ error("Health configuration at line %zu of file '%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
603
+ line, filename, rc->name, key, rc->chart, value, value);
604
605
freez(rc->chart);
606
}
608
rc->hash_chart = simple_hash(rc->chart);
609
}
610
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
610
- health_parse_db_lookup(line, path, filename, value, &rc->group, &rc->after, &rc->before,
611
+ health_parse_db_lookup(line, filename, value, &rc->group, &rc->after, &rc->before,
612
&rc->update_every,
613
&rc->options, &rc->dimensions);
614
}
615
else if(hash == hash_every && !strcasecmp(key, HEALTH_EVERY_KEY)) {
616
if(!health_parse_duration(value, &rc->update_every))
616
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' at key '%s' cannot parse duration: '%s'.",
617
- line, path, filename, rc->name, key, value);
617
+ error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' cannot parse duration: '%s'.",
618
+ line, filename, rc->name, key, value);
619
}
620
else if(hash == hash_green && !strcasecmp(key, HEALTH_GREEN_KEY)) {
621
char *e;
622
rc->green = str2ld(value, &e);
623
if(e && *e) {
623
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
624
- line, path, filename, rc->name, key, e);
624
+ error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
625
+ line, filename, rc->name, key, e);
626
}
627
}
628
else if(hash == hash_red && !strcasecmp(key, HEALTH_RED_KEY)) {
629
char *e;
630
rc->red = str2ld(value, &e);
631
if(e && *e) {
631
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
632
- line, path, filename, rc->name, key, e);
632
+ error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
633
+ line, filename, rc->name, key, e);
634
}
635
}
636
else if(hash == hash_calc && !strcasecmp(key, HEALTH_CALC_KEY)) {
638
int error = 0;
639
rc->calculation = expression_parse(value, &failed_at, &error);
640
if(!rc->calculation) {
640
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
641
- line, path, filename, rc->name, key, value, expression_strerror(error), failed_at);
641
+ error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
642
+ line, filename, rc->name, key, value, expression_strerror(error), failed_at);
643
}
644
}
645
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
647
int error = 0;
648
rc->warning = expression_parse(value, &failed_at, &error);
649
if(!rc->warning) {
649
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
650
- line, path, filename, rc->name, key, value, expression_strerror(error), failed_at);
650
+ error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
651
+ line, filename, rc->name, key, value, expression_strerror(error), failed_at);
652
}
653
}
654
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
656
int error = 0;
657
rc->critical = expression_parse(value, &failed_at, &error);
658
if(!rc->critical) {
658
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
659
- line, path, filename, rc->name, key, value, expression_strerror(error), failed_at);
659
+ error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
660
+ line, filename, rc->name, key, value, expression_strerror(error), failed_at);
661
}
662
}
663
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
664
if(rc->exec) {
665
if(strcmp(rc->exec, value) != 0)
665
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
666
- line, path, filename, rc->name, key, rc->exec, value, value);
666
+ error("Health configuration at line %zu of file '%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
667
+ line, filename, rc->name, key, rc->exec, value, value);
668
669
freez(rc->exec);
670
}
673
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
674
if(rc->recipient) {
675
if(strcmp(rc->recipient, value) != 0)
675
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
676
- line, path, filename, rc->name, key, rc->recipient, value, value);
676
+ error("Health configuration at line %zu of file '%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
677
+ line, filename, rc->name, key, rc->recipient, value, value);
678
679
freez(rc->recipient);
680
}
683
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
684
if(rc->units) {
685
if(strcmp(rc->units, value) != 0)
685
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
686
- line, path, filename, rc->name, key, rc->units, value, value);
686
+ error("Health configuration at line %zu of file '%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
687
+ line, filename, rc->name, key, rc->units, value, value);
688
689
freez(rc->units);
690
}
694
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
695
if(rc->info) {
696
if(strcmp(rc->info, value) != 0)
696
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
697
- line, path, filename, rc->name, key, rc->info, value, value);
697
+ error("Health configuration at line %zu of file '%s' for alarm '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
698
+ line, filename, rc->name, key, rc->info, value, value);
699
700
freez(rc->info);
701
}
703
strip_quotes(rc->info);
704
}
705
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
705
- health_parse_delay(line, path, filename, value, &rc->delay_up_duration, &rc->delay_down_duration, &rc->delay_max_duration, &rc->delay_multiplier);
706
+ health_parse_delay(line, filename, value, &rc->delay_up_duration, &rc->delay_down_duration, &rc->delay_max_duration, &rc->delay_multiplier);
707
}
708
else if(hash == hash_options && !strcasecmp(key, HEALTH_OPTIONS_KEY)) {
709
rc->options |= health_parse_options(value);
710
}
711
else {
711
- error("Health configuration at line %zu of file '%s/%s' for alarm '%s' has unknown key '%s'.",
712
- line, path, filename, rc->name, key);
712
+ error("Health configuration at line %zu of file '%s' for alarm '%s' has unknown key '%s'.",
713
+ line, filename, rc->name, key);
714
}
715
}
716
else if(rt) {
717
if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
718
if(rt->context) {
719
if(strcmp(rt->context, value) != 0)
719
- error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
720
- line, path, filename, rt->name, key, rt->context, value, value);
720
+ error("Health configuration at line %zu of file '%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
721
+ line, filename, rt->name, key, rt->context, value, value);
722
723
freez(rt->context);
724
}
733
rt->family_pattern = simple_pattern_create(rt->family_match, NULL, SIMPLE_PATTERN_EXACT);
734
}
735
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
735
- health_parse_db_lookup(line, path, filename, value, &rt->group, &rt->after, &rt->before,
736
+ health_parse_db_lookup(line, filename, value, &rt->group, &rt->after, &rt->before,
737
&rt->update_every, &rt->options, &rt->dimensions);
738
}
739
else if(hash == hash_every && !strcasecmp(key, HEALTH_EVERY_KEY)) {
740
if(!health_parse_duration(value, &rt->update_every))
740
- error("Health configuration at line %zu of file '%s/%s' for template '%s' at key '%s' cannot parse duration: '%s'.",
741
- line, path, filename, rt->name, key, value);
741
+ error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' cannot parse duration: '%s'.",
742
+ line, filename, rt->name, key, value);
743
}
744
else if(hash == hash_green && !strcasecmp(key, HEALTH_GREEN_KEY)) {
745
char *e;
746
rt->green = str2ld(value, &e);
747
if(e && *e) {
747
- error("Health configuration at line %zu of file '%s/%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
748
- line, path, filename, rt->name, key, e);
748
+ error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
749
+ line, filename, rt->name, key, e);
750
}
751
}
752
else if(hash == hash_red && !strcasecmp(key, HEALTH_RED_KEY)) {
753
char *e;
754
rt->red = str2ld(value, &e);
755
if(e && *e) {
755
- error("Health configuration at line %zu of file '%s/%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
756
- line, path, filename, rt->name, key, e);
756
+ error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
757
+ line, filename, rt->name, key, e);
758
}
759
}
760
else if(hash == hash_calc && !strcasecmp(key, HEALTH_CALC_KEY)) {
762
int error = 0;
763
rt->calculation = expression_parse(value, &failed_at, &error);
764
if(!rt->calculation) {
764
- error("Health configuration at line %zu of file '%s/%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
765
- line, path, filename, rt->name, key, value, expression_strerror(error), failed_at);
765
+ error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
766
+ line, filename, rt->name, key, value, expression_strerror(error), failed_at);
767
}
768
}
769
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
771
int error = 0;
772
rt->warning = expression_parse(value, &failed_at, &error);
773
if(!rt->warning) {
773
- error("Health configuration at line %zu of file '%s/%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
774
- line, path, filename, rt->name, key, value, expression_strerror(error), failed_at);
774
+ error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
775
+ line, filename, rt->name, key, value, expression_strerror(error), failed_at);
776
}
777
}
778
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
780
int error = 0;
781
rt->critical = expression_parse(value, &failed_at, &error);
782
if(!rt->critical) {
782
- error("Health configuration at line %zu of file '%s/%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
783
- line, path, filename, rt->name, key, value, expression_strerror(error), failed_at);
783
+ error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
784
+ line, filename, rt->name, key, value, expression_strerror(error), failed_at);
785
}
786
}
787
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
788
if(rt->exec) {
789
if(strcmp(rt->exec, value) != 0)
789
- error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
790
- line, path, filename, rt->name, key, rt->exec, value, value);
790
+ error("Health configuration at line %zu of file '%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
791
+ line, filename, rt->name, key, rt->exec, value, value);
792
793
freez(rt->exec);
794
}
797
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
798
if(rt->recipient) {
799
if(strcmp(rt->recipient, value) != 0)
799
- error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
800
- line, path, filename, rt->name, key, rt->recipient, value, value);
800
+ error("Health configuration at line %zu of file '%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
801
+ line, filename, rt->name, key, rt->recipient, value, value);
802
803
freez(rt->recipient);
804
}
807
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
808
if(rt->units) {
809
if(strcmp(rt->units, value) != 0)
809
- error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
810
- line, path, filename, rt->name, key, rt->units, value, value);
810
+ error("Health configuration at line %zu of file '%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
811
+ line, filename, rt->name, key, rt->units, value, value);
812
813
freez(rt->units);
814
}
818
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
819
if(rt->info) {
820
if(strcmp(rt->info, value) != 0)
820
- error("Health configuration at line %zu of file '%s/%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
821
- line, path, filename, rt->name, key, rt->info, value, value);
821
+ error("Health configuration at line %zu of file '%s' for template '%s' has key '%s' twice, once with value '%s' and later with value '%s'. Using ('%s').",
822
+ line, filename, rt->name, key, rt->info, value, value);
823
824
freez(rt->info);
825
}
827
strip_quotes(rt->info);
828
}
829
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
829
- health_parse_delay(line, path, filename, value, &rt->delay_up_duration, &rt->delay_down_duration, &rt->delay_max_duration, &rt->delay_multiplier);
830
+ health_parse_delay(line, filename, value, &rt->delay_up_duration, &rt->delay_down_duration, &rt->delay_max_duration, &rt->delay_multiplier);
831
}
832
else if(hash == hash_options && !strcasecmp(key, HEALTH_OPTIONS_KEY)) {
833
rt->options |= health_parse_options(value);
834
}
835
else {
835
- error("Health configuration at line %zu of file '%s/%s' for template '%s' has unknown key '%s'.",
836
- line, path, filename, rt->name, key);
836
+ error("Health configuration at line %zu of file '%s' for template '%s' has unknown key '%s'.",
837
+ line, filename, rt->name, key);
838
}
839
}
840
else {
840
- error("Health configuration at line %zu of file '%s/%s' has unknown key '%s'. Expected either '" HEALTH_ALARM_KEY "' or '" HEALTH_TEMPLATE_KEY "'.",
841
- line, path, filename, key);
841
+ error("Health configuration at line %zu of file '%s' has unknown key '%s'. Expected either '" HEALTH_ALARM_KEY "' or '" HEALTH_TEMPLATE_KEY "'.",
842
+ line, filename, key);
843
}
844
}
845
853
return 1;
854
}
855
855
-void health_readdir(RRDHOST *host, const char *path) {
856
- if(!host->health_enabled) return;
857
-
858
- size_t pathlen = strlen(path);
859
-
860
- debug(D_HEALTH, "Health configuration reading directory '%s'", path);
861
-
862
- DIR *dir = opendir(path);
863
- if (!dir) {
864
- error("Health configuration cannot open directory '%s'.", path);
865
- return;
866
- }
867
-
868
- struct dirent *de = NULL;
869
- while ((de = readdir(dir))) {
870
- size_t len = strlen(de->d_name);
871
-
872
- if(de->d_type == DT_DIR
873
- && (
874
- (de->d_name[0] == '.' && de->d_name[1] == '\0')
875
- || (de->d_name[0] == '.' && de->d_name[1] == '.' && de->d_name[2] == '\0')
876
- )) {
877
- debug(D_HEALTH, "Ignoring directory '%s'", de->d_name);
878
- continue;
879
- }
880
-
881
- else if(de->d_type == DT_DIR) {
882
- char *s = mallocz(pathlen + strlen(de->d_name) + 2);
883
- strcpy(s, path);
884
- strcat(s, "/");
885
- strcat(s, de->d_name);
886
- health_readdir(host, s);
887
- freez(s);
888
- continue;
889
- }
890
-
891
- else if((de->d_type == DT_LNK || de->d_type == DT_REG || de->d_type == DT_UNKNOWN) &&
892
- len > 5 && !strcmp(&de->d_name[len - 5], ".conf")) {
893
- health_readfile(host, path, de->d_name);
894
- }
895
-
896
- else debug(D_HEALTH, "Ignoring file '%s'", de->d_name);
897
- }
898
-
899
- closedir(dir);
856
+void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path, const char *subpath) {
857
+ if(unlikely(!host->health_enabled)) return;
858
+ recursive_config_double_dir_load(user_path, stock_path, subpath, health_readfile, (void *) host);
859
}
901
-
902
-