35
36
static inline int rrdcalc_add_alarm_from_config(RRDHOST *host, RRDCALC *rc) {
37
if(!rc->chart) {
38
- error("Health configuration for alarm '%s' does not have a chart", rc->name);
38
+ error("Health configuration for alarm '%s' does not have a chart", rrdcalc_name(rc));
39
return 0;
40
}
41
42
if(!rc->update_every) {
43
- error("Health configuration for alarm '%s.%s' has no frequency (parameter 'every'). Ignoring it.", rc->chart?rc->chart:"NOCHART", rc->name);
43
+ error("Health configuration for alarm '%s.%s' has no frequency (parameter 'every'). Ignoring it.", rrdcalc_chart_name(rc), rrdcalc_name(rc));
44
return 0;
45
}
46
47
if(!RRDCALC_HAS_DB_LOOKUP(rc) && !rc->calculation && !rc->warning && !rc->critical) {
48
- error("Health configuration for alarm '%s.%s' is useless (no db lookup, no calculation, no warning and no critical expressions)", rc->chart?rc->chart:"NOCHART", rc->name);
48
+ error("Health configuration for alarm '%s.%s' is useless (no db lookup, no calculation, no warning and no critical expressions)", rrdcalc_chart_name(rc), rrdcalc_name(rc));
49
return 0;
50
}
51
52
- if (rrdcalc_exists(host, rc->chart, rc->name, rc->hash_chart, rc->hash))
52
+ if (rrdcalc_exists(host, rrdcalc_chart_name(rc), rrdcalc_name(rc)))
53
return 0;
54
55
rc->id = rrdcalc_get_unique_id(host, rc->chart, rc->name, &rc->next_event_id);
57
debug(D_HEALTH, "Health configuration adding alarm '%s.%s' (%u): exec '%s', recipient '%s', green " NETDATA_DOUBLE_FORMAT_AUTO
58
", red " NETDATA_DOUBLE_FORMAT_AUTO
59
", lookup: group %d, after %d, before %d, options %u, dimensions '%s', for each dimension '%s', update every %d, calculation '%s', warning '%s', critical '%s', source '%s', delay up %d, delay down %d, delay max %d, delay_multiplier %f, warn_repeat_every %u, crit_repeat_every %u",
60
- rc->chart?rc->chart:"NOCHART",
61
- rc->name,
60
+ rrdcalc_chart_name(rc),
61
+ rrdcalc_name(rc),
62
rc->id,
63
- (rc->exec)?rc->exec:"DEFAULT",
64
- (rc->recipient)?rc->recipient:"DEFAULT",
63
+ (rc->exec)?rrdcalc_exec(rc):"DEFAULT",
64
+ (rc->recipient)?rrdcalc_recipient(rc):"DEFAULT",
65
rc->green,
66
rc->red,
67
(int)rc->group,
68
rc->after,
69
rc->before,
70
rc->options,
71
- (rc->dimensions)?rc->dimensions:"NONE",
72
- (rc->foreachdim)?rc->foreachdim:"NONE",
71
+ (rc->dimensions)?rrdcalc_dimensions(rc):"NONE",
72
+ (rc->foreachdim)?rrdcalc_foreachdim(rc):"NONE",
73
rc->update_every,
74
(rc->calculation)?rc->calculation->parsed_as:"NONE",
75
(rc->warning)?rc->warning->parsed_as:"NONE",
76
(rc->critical)?rc->critical->parsed_as:"NONE",
77
- rc->source,
77
+ rrdcalc_source(rc),
78
rc->delay_up_duration,
79
rc->delay_down_duration,
80
rc->delay_max_duration,
90
91
static inline int rrdcalctemplate_add_template_from_config(RRDHOST *host, RRDCALCTEMPLATE *rt) {
92
if(unlikely(!rt->context)) {
93
- error("Health configuration for template '%s' does not have a context", rt->name);
93
+ error("Health configuration for template '%s' does not have a context", rrdcalctemplate_name(rt));
94
return 0;
95
}
96
97
if(unlikely(!rt->update_every)) {
98
- error("Health configuration for template '%s' has no frequency (parameter 'every'). Ignoring it.", rt->name);
98
+ error("Health configuration for template '%s' has no frequency (parameter 'every'). Ignoring it.", rrdcalctemplate_name(rt));
99
return 0;
100
}
101
102
if(unlikely(!RRDCALCTEMPLATE_HAS_DB_LOOKUP(rt) && !rt->calculation && !rt->warning && !rt->critical)) {
103
- error("Health configuration for template '%s' is useless (no calculation, no warning and no critical evaluation)", rt->name);
103
+ error("Health configuration for template '%s' is useless (no calculation, no warning and no critical evaluation)", rrdcalctemplate_name(rt));
104
return 0;
105
}
106
107
- RRDCALCTEMPLATE *t, *last = NULL;
108
- if(!rt->foreachdim) {
109
- for (t = host->templates; t ; last = t, t = t->next) {
110
- if(unlikely(t->hash_name == rt->hash_name
111
- && !strcmp(t->name, rt->name)
112
- && !strcmp(t->family_match?t->family_match:"*", rt->family_match?rt->family_match:"*")
113
- )) {
114
- info("Health configuration template '%s' already exists for host '%s'.", rt->name, host->hostname);
115
- return 0;
116
- }
117
- }
118
-
119
- if(likely(last)) {
120
- last->next = rt;
121
- }
122
- else {
123
- rt->next = host->templates;
124
- host->templates = rt;
125
- }
126
- } else {
127
- for (t = host->alarms_template_with_foreach; t ; last = t, t = t->next) {
128
- if(unlikely(t->hash_name == rt->hash_name
129
- && !strcmp(t->name, rt->name)
130
- && !strcmp(t->family_match?t->family_match:"*", rt->family_match?rt->family_match:"*")
131
- )) {
132
- info("Health configuration template '%s' already exists for host '%s'.", rt->name, host->hostname);
133
- return 0;
134
- }
135
- }
136
-
137
- if(likely(last)) {
138
- last->next = rt;
139
- }
140
- else {
141
- rt->next = host->alarms_template_with_foreach;
142
- host->alarms_template_with_foreach = rt;
107
+ RRDCALCTEMPLATE *t;
108
+ foreach_rrdcalctemplate_in_rrdhost(host, t) {
109
+ if(unlikely(t->name == rt->name && !strcmp(t->family_match?rrdcalctemplate_family_match(t):"*", rt->family_match?rrdcalctemplate_family_match(rt):"*"))) {
110
+ info("Health configuration template '%s' already exists for host '%s'.", rrdcalctemplate_name(rt), rrdhost_hostname(host));
111
+ return 0;
112
}
113
}
114
115
+ if(rt->foreachdim)
116
+ DOUBLE_LINKED_LIST_PREPEND_UNSAFE(host->alarms_templates, rt, prev, next);
117
+ else
118
+ DOUBLE_LINKED_LIST_APPEND_UNSAFE(host->alarms_templates, rt, prev, next);
119
+
120
debug(D_HEALTH, "Health configuration adding template '%s': context '%s', exec '%s', recipient '%s', green " NETDATA_DOUBLE_FORMAT_AUTO
121
", red " NETDATA_DOUBLE_FORMAT_AUTO
122
", lookup: group %d, after %d, before %d, options %u, dimensions '%s', for each dimension '%s', update every %d, calculation '%s', warning '%s', critical '%s', source '%s', delay up %d, delay down %d, delay max %d, delay_multiplier %f, warn_repeat_every %u, crit_repeat_every %u",
149
- rt->name,
150
- (rt->context)?rt->context:"NONE",
151
- (rt->exec)?rt->exec:"DEFAULT",
152
- (rt->recipient)?rt->recipient:"DEFAULT",
123
+ rrdcalctemplate_name(rt),
124
+ (rt->context)?string2str(rt->context):"NONE",
125
+ (rt->exec)?rrdcalctemplate_exec(rt):"DEFAULT",
126
+ (rt->recipient)?rrdcalctemplate_recipient(rt):"DEFAULT",
127
rt->green,
128
rt->red,
129
(int)rt->group,
130
rt->after,
131
rt->before,
132
rt->options,
159
- (rt->dimensions)?rt->dimensions:"NONE",
160
- (rt->foreachdim)?rt->foreachdim:"NONE",
133
+ (rt->dimensions)?rrdcalctemplate_dimensions(rt):"NONE",
134
+ (rt->foreachdim)?rrdcalctemplate_foreachdim(rt):"NONE",
135
rt->update_every,
136
(rt->calculation)?rt->calculation->parsed_as:"NONE",
137
(rt->warning)?rt->warning->parsed_as:"NONE",
138
(rt->critical)?rt->critical->parsed_as:"NONE",
165
- rt->source,
139
+ rrdcalctemplate_source(rt),
140
rt->delay_up_duration,
141
rt->delay_down_duration,
142
rt->delay_max_duration,
308
*
309
* @param s the string that will be used to create the simple pattern.
310
*/
337
-SIMPLE_PATTERN *health_pattern_from_foreach(char *s) {
311
+SIMPLE_PATTERN *health_pattern_from_foreach(const char *s) {
312
char *convert= strdupz(s);
313
SIMPLE_PATTERN *val = NULL;
314
if(convert) {
324
static inline int health_parse_db_lookup(
325
size_t line, const char *filename, char *string,
326
RRDR_GROUPING *group_method, int *after, int *before, int *every,
353
- uint32_t *options, char **dimensions, char **foreachdim
327
+ uint32_t *options, STRING **dimensions, STRING **foreachdim
328
) {
329
debug(D_HEALTH, "Health configuration parsing database lookup %zu@%s: %s", line, filename, string);
330
357
- if(*dimensions) freez(*dimensions);
358
- if(*foreachdim) freez(*foreachdim);
331
+ if(*dimensions) string_freez(*dimensions);
332
+ if(*foreachdim) string_freez(*foreachdim);
333
*dimensions = NULL;
334
*foreachdim = NULL;
335
*after = 0;
427
if(find) {
428
*find = '\0';
429
}
456
- *dimensions = strdupz(s);
430
+ *dimensions = string_strdupz(s);
431
}
432
433
if(!find) {
436
s = ++find;
437
}
438
else if(!strcasecmp(key, HEALTH_FOREACH_KEY )) {
465
- *foreachdim = strdupz(s);
439
+ *foreachdim = string_strdupz(s);
440
break;
441
}
442
else {
448
return 1;
449
}
450
477
-static inline char *health_source_file(size_t line, const char *file) {
451
+static inline STRING *health_source_file(size_t line, const char *file) {
452
char buffer[FILENAME_MAX + 1];
453
snprintfz(buffer, FILENAME_MAX, "%zu@%s", line, file);
480
- return strdupz(buffer);
454
+ return string_strdupz(buffer);
455
}
456
457
char *health_edit_command_from_source(const char *source)
470
netdata_configured_user_config_dir,
471
file_no_path + 1,
472
temp,
499
- localhost->registry_hostname);
473
+ rrdhost_registry_hostname(localhost));
474
} else
475
buffer[0] = '\0';
476
487
488
static inline void alert_config_free(struct alert_config *cfg)
489
{
516
- freez(cfg->alarm);
517
- freez(cfg->template_key);
518
- freez(cfg->os);
519
- freez(cfg->host);
520
- freez(cfg->on);
521
- freez(cfg->families);
522
- freez(cfg->plugin);
523
- freez(cfg->module);
524
- freez(cfg->charts);
525
- freez(cfg->lookup);
526
- freez(cfg->calc);
527
- freez(cfg->warn);
528
- freez(cfg->crit);
529
- freez(cfg->every);
530
- freez(cfg->green);
531
- freez(cfg->red);
532
- freez(cfg->exec);
533
- freez(cfg->to);
534
- freez(cfg->units);
535
- freez(cfg->info);
536
- freez(cfg->classification);
537
- freez(cfg->component);
538
- freez(cfg->type);
539
- freez(cfg->delay);
540
- freez(cfg->options);
541
- freez(cfg->repeat);
542
- freez(cfg->host_labels);
543
- freez(cfg->p_db_lookup_dimensions);
544
- freez(cfg->p_db_lookup_method);
490
+ string_freez(cfg->alarm);
491
+ string_freez(cfg->template_key);
492
+ string_freez(cfg->os);
493
+ string_freez(cfg->host);
494
+ string_freez(cfg->on);
495
+ string_freez(cfg->families);
496
+ string_freez(cfg->plugin);
497
+ string_freez(cfg->module);
498
+ string_freez(cfg->charts);
499
+ string_freez(cfg->lookup);
500
+ string_freez(cfg->calc);
501
+ string_freez(cfg->warn);
502
+ string_freez(cfg->crit);
503
+ string_freez(cfg->every);
504
+ string_freez(cfg->green);
505
+ string_freez(cfg->red);
506
+ string_freez(cfg->exec);
507
+ string_freez(cfg->to);
508
+ string_freez(cfg->units);
509
+ string_freez(cfg->info);
510
+ string_freez(cfg->classification);
511
+ string_freez(cfg->component);
512
+ string_freez(cfg->type);
513
+ string_freez(cfg->delay);
514
+ string_freez(cfg->options);
515
+ string_freez(cfg->repeat);
516
+ string_freez(cfg->host_labels);
517
+ string_freez(cfg->p_db_lookup_dimensions);
518
+ string_freez(cfg->p_db_lookup_method);
519
freez(cfg);
520
}
521
659
660
rc = callocz(1, sizeof(RRDCALC));
661
rc->next_event_id = 1;
688
- rc->name = strdupz(value);
662
+
663
+ {
664
+ char *tmp = strdupz(value);
665
+ if(rrdvar_fix_name(tmp))
666
+ error("Health configuration renamed alarm '%s' to '%s'", value, tmp);
667
+
668
+ rc->name = string_strdupz(tmp);
669
+ freez(tmp);
670
+ }
671
+
672
rc->source = health_source_file(line, filename);
673
rc->green = NAN;
674
rc->red = NAN;
682
alert_config_free(alert_cfg);
683
alert_cfg = callocz(1, sizeof(struct alert_config));
684
702
- if(rrdvar_fix_name(rc->name))
703
- error("Health configuration renamed alarm '%s' to '%s'", value, rc->name);
704
-
705
- rc->hash = simple_hash(rc->name);
706
- alert_cfg->alarm = strdupz(rc->name);
685
+ alert_cfg->alarm = string_dup(rc->name);
686
ignore_this = 0;
687
}
688
else if(hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) {
689
if(rc) {
690
// health_add_alarms_loop(host, rc, ignore_this) ;
712
- if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
691
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc))
692
rrdcalc_free(rc);
714
- }
693
694
rc = NULL;
695
}
696
697
if(rt) {
720
- if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
698
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt))
699
rrdcalctemplate_free(rt);
722
- }
700
}
701
702
rt = callocz(1, sizeof(RRDCALCTEMPLATE));
726
- rt->name = strdupz(value);
703
+
704
+ {
705
+ char *tmp = strdupz(value);
706
+ if(rrdvar_fix_name(tmp))
707
+ error("Health configuration renamed template '%s' to '%s'", value, tmp);
708
+
709
+ rt->name = string_strdupz(tmp);
710
+ freez(tmp);
711
+ }
712
+
713
rt->source = health_source_file(line, filename);
714
rt->green = NAN;
715
rt->red = NAN;
730
- rt->delay_multiplier = 1.0;
716
+ rt->delay_multiplier = (float)1.0;
717
rt->warn_repeat_every = host->health_default_warn_repeat_every;
718
rt->crit_repeat_every = host->health_default_crit_repeat_every;
719
if (alert_cfg)
720
alert_config_free(alert_cfg);
721
alert_cfg = callocz(1, sizeof(struct alert_config));
722
737
- if(rrdvar_fix_name(rt->name))
738
- error("Health configuration renamed template '%s' to '%s'", value, rt->name);
739
-
740
- rt->hash_name = simple_hash(rt->name);
741
- alert_cfg->template_key = strdupz(rt->name);
723
+ alert_cfg->template_key = string_dup(rt->name);
724
ignore_this = 0;
725
}
726
else if(hash == hash_os && !strcasecmp(key, HEALTH_OS_KEY)) {
727
char *os_match = value;
746
- if (alert_cfg) alert_cfg->os = strdupz(value);
728
+ if (alert_cfg) alert_cfg->os = string_strdupz(value);
729
SIMPLE_PATTERN *os_pattern = simple_pattern_create(os_match, NULL, SIMPLE_PATTERN_EXACT);
730
749
- if(!simple_pattern_matches(os_pattern, host->os)) {
731
+ if(!simple_pattern_matches(os_pattern, rrdhost_os(host))) {
732
if(rc)
751
- 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);
733
+ debug(D_HEALTH, "HEALTH on '%s' ignoring alarm '%s' defined at %zu@%s: host O/S does not match '%s'", rrdhost_hostname(host), rrdcalc_name(rc), line, filename, os_match);
734
735
if(rt)
754
- 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);
736
+ debug(D_HEALTH, "HEALTH on '%s' ignoring template '%s' defined at %zu@%s: host O/S does not match '%s'", rrdhost_hostname(host), rrdcalctemplate_name(rt), line, filename, os_match);
737
738
ignore_this = 1;
739
}
742
}
743
else if(hash == hash_host && !strcasecmp(key, HEALTH_HOST_KEY)) {
744
char *host_match = value;
763
- if (alert_cfg) alert_cfg->host = strdupz(value);
745
+ if (alert_cfg) alert_cfg->host = string_strdupz(value);
746
SIMPLE_PATTERN *host_pattern = simple_pattern_create(host_match, NULL, SIMPLE_PATTERN_EXACT);
747
766
- if(!simple_pattern_matches(host_pattern, host->hostname)) {
748
+ if(!simple_pattern_matches(host_pattern, rrdhost_hostname(host))) {
749
if(rc)
768
- 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);
750
+ debug(D_HEALTH, "HEALTH on '%s' ignoring alarm '%s' defined at %zu@%s: hostname does not match '%s'", rrdhost_hostname(host), rrdcalc_name(rc), line, filename, host_match);
751
752
if(rt)
771
- 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);
753
+ debug(D_HEALTH, "HEALTH on '%s' ignoring template '%s' defined at %zu@%s: hostname does not match '%s'", rrdhost_hostname(host), rrdcalctemplate_name(rt), line, filename, host_match);
754
755
ignore_this = 1;
756
}
759
}
760
else if(rc) {
761
if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
780
- alert_cfg->on = strdupz(value);
762
+ alert_cfg->on = string_strdupz(value);
763
if(rc->chart) {
782
- if(strcmp(rc->chart, value) != 0)
764
+ if(strcmp(rrdcalc_chart_name(rc), value) != 0)
765
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').",
784
- line, filename, rc->name, key, rc->chart, value, value);
766
+ line, filename, rrdcalc_name(rc), key, rrdcalc_chart_name(rc), value, value);
767
786
- freez(rc->chart);
768
+ string_freez(rc->chart);
769
}
788
- rc->chart = strdupz(value);
789
- rc->hash_chart = simple_hash(rc->chart);
770
+ rc->chart = string_strdupz(value);
771
}
772
else if(hash == hash_class && !strcasecmp(key, HEALTH_CLASS_KEY)) {
792
- alert_cfg->classification = strdupz(value);
773
+ strip_quotes(value);
774
+
775
+ alert_cfg->classification = string_strdupz(value);
776
if(rc->classification) {
794
- if(strcmp(rc->classification, value) != 0)
777
+ if(strcmp(rrdcalc_classification(rc), value) != 0)
778
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').",
796
- line, filename, rc->name, key, rc->classification, value, value);
779
+ line, filename, rrdcalc_name(rc), key, rrdcalc_classification(rc), value, value);
780
798
- freez(rc->classification);
781
+ string_freez(rc->classification);
782
}
800
- rc->classification = strdupz(value);
801
- strip_quotes(rc->classification);
783
+ rc->classification = string_strdupz(value);
784
}
785
else if(hash == hash_component && !strcasecmp(key, HEALTH_COMPONENT_KEY)) {
804
- alert_cfg->component = strdupz(value);
786
+ strip_quotes(value);
787
+
788
+ alert_cfg->component = string_strdupz(value);
789
if(rc->component) {
806
- if(strcmp(rc->component, value) != 0)
790
+ if(strcmp(rrdcalc_component(rc), value) != 0)
791
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').",
808
- line, filename, rc->name, key, rc->component, value, value);
792
+ line, filename, rrdcalc_name(rc), key, rrdcalc_component(rc), value, value);
793
810
- freez(rc->component);
794
+ string_freez(rc->component);
795
}
812
- rc->component = strdupz(value);
813
- strip_quotes(rc->component);
796
+ rc->component = string_strdupz(value);
797
}
798
else if(hash == hash_type && !strcasecmp(key, HEALTH_TYPE_KEY)) {
816
- alert_cfg->type = strdupz(value);
799
+ strip_quotes(value);
800
+
801
+ alert_cfg->type = string_strdupz(value);
802
if(rc->type) {
818
- if(strcmp(rc->type, value) != 0)
803
+ if(strcmp(rrdcalc_type(rc), value) != 0)
804
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').",
820
- line, filename, rc->name, key, rc->type, value, value);
805
+ line, filename, rrdcalc_name(rc), key, rrdcalc_type(rc), value, value);
806
822
- freez(rc->type);
807
+ string_freez(rc->type);
808
}
824
- rc->type = strdupz(value);
825
- strip_quotes(rc->type);
809
+ rc->type = string_strdupz(value);
810
}
811
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
828
- alert_cfg->lookup = strdupz(value);
812
+ alert_cfg->lookup = string_strdupz(value);
813
health_parse_db_lookup(line, filename, value, &rc->group, &rc->after, &rc->before,
814
&rc->update_every, &rc->options, &rc->dimensions, &rc->foreachdim);
831
- if(rc->foreachdim) {
832
- rc->spdim = health_pattern_from_foreach(rc->foreachdim);
833
- }
815
+
816
+ if(rc->foreachdim)
817
+ rc->spdim = health_pattern_from_foreach(rrdcalc_foreachdim(rc));
818
+
819
if (rc->after) {
820
if (rc->dimensions)
836
- alert_cfg->p_db_lookup_dimensions = strdupz(rc->dimensions);
821
+ alert_cfg->p_db_lookup_dimensions = string_dup(rc->dimensions);
822
if (rc->group)
838
- alert_cfg->p_db_lookup_method = strdupz(group_method2string(rc->group));
823
+ alert_cfg->p_db_lookup_method = string_strdupz(group_method2string(rc->group));
824
alert_cfg->p_db_lookup_options = rc->options;
825
alert_cfg->p_db_lookup_after = rc->after;
826
alert_cfg->p_db_lookup_before = rc->before;
828
}
829
}
830
else if(hash == hash_every && !strcasecmp(key, HEALTH_EVERY_KEY)) {
846
- alert_cfg->every = strdupz(value);
831
+ alert_cfg->every = string_strdupz(value);
832
if(!config_parse_duration(value, &rc->update_every))
833
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' cannot parse duration: '%s'.",
849
- line, filename, rc->name, key, value);
834
+ line, filename, rrdcalc_name(rc), key, value);
835
alert_cfg->p_update_every = rc->update_every;
836
}
837
else if(hash == hash_green && !strcasecmp(key, HEALTH_GREEN_KEY)) {
853
- alert_cfg->green = strdupz(value);
838
+ alert_cfg->green = string_strdupz(value);
839
char *e;
840
rc->green = str2ndd(value, &e);
841
if(e && *e) {
842
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
858
- line, filename, rc->name, key, e);
843
+ line, filename, rrdcalc_name(rc), key, e);
844
}
845
}
846
else if(hash == hash_red && !strcasecmp(key, HEALTH_RED_KEY)) {
862
- alert_cfg->red = strdupz(value);
847
+ alert_cfg->red = string_strdupz(value);
848
char *e;
849
rc->red = str2ndd(value, &e);
850
if(e && *e) {
851
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
867
- line, filename, rc->name, key, e);
852
+ line, filename, rrdcalc_name(rc), key, e);
853
}
854
}
855
else if(hash == hash_calc && !strcasecmp(key, HEALTH_CALC_KEY)) {
871
- alert_cfg->calc = strdupz(value);
856
+ alert_cfg->calc = string_strdupz(value);
857
const char *failed_at = NULL;
858
int error = 0;
859
rc->calculation = expression_parse(value, &failed_at, &error);
860
if(!rc->calculation) {
861
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
877
- line, filename, rc->name, key, value, expression_strerror(error), failed_at);
862
+ line, filename, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
863
}
864
}
865
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
881
- alert_cfg->warn = strdupz(value);
866
+ alert_cfg->warn = string_strdupz(value);
867
const char *failed_at = NULL;
868
int error = 0;
869
rc->warning = expression_parse(value, &failed_at, &error);
870
if(!rc->warning) {
871
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
887
- line, filename, rc->name, key, value, expression_strerror(error), failed_at);
872
+ line, filename, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
873
}
874
}
875
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
891
- alert_cfg->crit = strdupz(value);
876
+ alert_cfg->crit = string_strdupz(value);
877
const char *failed_at = NULL;
878
int error = 0;
879
rc->critical = expression_parse(value, &failed_at, &error);
880
if(!rc->critical) {
881
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
897
- line, filename, rc->name, key, value, expression_strerror(error), failed_at);
882
+ line, filename, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
883
}
884
}
885
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
901
- alert_cfg->exec = strdupz(value);
886
+ alert_cfg->exec = string_strdupz(value);
887
if(rc->exec) {
903
- if(strcmp(rc->exec, value) != 0)
888
+ if(strcmp(rrdcalc_exec(rc), value) != 0)
889
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').",
905
- line, filename, rc->name, key, rc->exec, value, value);
890
+ line, filename, rrdcalc_name(rc), key, rrdcalc_exec(rc), value, value);
891
907
- freez(rc->exec);
892
+ string_freez(rc->exec);
893
}
909
- rc->exec = strdupz(value);
894
+ rc->exec = string_strdupz(value);
895
}
896
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
912
- alert_cfg->to = strdupz(value);
897
+ alert_cfg->to = string_strdupz(value);
898
if(rc->recipient) {
914
- if(strcmp(rc->recipient, value) != 0)
899
+ if(strcmp(rrdcalc_recipient(rc), value) != 0)
900
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').",
916
- line, filename, rc->name, key, rc->recipient, value, value);
901
+ line, filename, rrdcalc_name(rc), key, rrdcalc_recipient(rc), value, value);
902
918
- freez(rc->recipient);
903
+ string_freez(rc->recipient);
904
}
920
- rc->recipient = strdupz(value);
905
+ rc->recipient = string_strdupz(value);
906
}
907
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
923
- alert_cfg->units = strdupz(value);
908
+ strip_quotes(value);
909
+
910
+ alert_cfg->units = string_strdupz(value);
911
if(rc->units) {
925
- if(strcmp(rc->units, value) != 0)
912
+ if(strcmp(rrdcalc_units(rc), value) != 0)
913
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').",
927
- line, filename, rc->name, key, rc->units, value, value);
914
+ line, filename, rrdcalc_name(rc), key, rrdcalc_units(rc), value, value);
915
929
- freez(rc->units);
916
+ string_freez(rc->units);
917
}
931
- rc->units = strdupz(value);
932
- strip_quotes(rc->units);
918
+ rc->units = string_strdupz(value);
919
}
920
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
935
- alert_cfg->info = strdupz(value);
921
+ strip_quotes(value);
922
+
923
+ alert_cfg->info = string_strdupz(value);
924
if(rc->info) {
937
- if(strcmp(rc->info, value) != 0)
925
+ if(strcmp(rrdcalc_info(rc), value) != 0)
926
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').",
939
- line, filename, rc->name, key, rc->info, value, value);
927
+ line, filename, rrdcalc_name(rc), key, rrdcalc_info(rc), value, value);
928
941
- freez(rc->info);
929
+ string_freez(rc->info);
930
+ string_freez(rc->original_info);
931
}
943
- rc->info = strdupz(value);
944
- strip_quotes(rc->info);
945
- rc->original_info = strdupz(value);
946
- strip_quotes(rc->original_info);
932
+ rc->info = string_strdupz(value);
933
+ rc->original_info = string_dup(rc->info);
934
}
935
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
949
- alert_cfg->delay = strdupz(value);
936
+ alert_cfg->delay = string_strdupz(value);
937
health_parse_delay(line, filename, value, &rc->delay_up_duration, &rc->delay_down_duration, &rc->delay_max_duration, &rc->delay_multiplier);
938
}
939
else if(hash == hash_options && !strcasecmp(key, HEALTH_OPTIONS_KEY)) {
953
- alert_cfg->options = strdupz(value);
940
+ alert_cfg->options = string_strdupz(value);
941
rc->options |= health_parse_options(value);
942
}
943
else if(hash == hash_repeat && !strcasecmp(key, HEALTH_REPEAT_KEY)){
957
- alert_cfg->repeat = strdupz(value);
944
+ alert_cfg->repeat = string_strdupz(value);
945
health_parse_repeat(line, filename, value,
946
&rc->warn_repeat_every,
947
&rc->crit_repeat_every);
948
}
949
else if(hash == hash_host_label && !strcasecmp(key, HEALTH_HOST_LABEL_KEY)) {
963
- alert_cfg->host_labels = strdupz(value);
950
+ alert_cfg->host_labels = string_strdupz(value);
951
if(rc->host_labels) {
965
- if(strcmp(rc->host_labels, value) != 0)
952
+ if(strcmp(rrdcalc_host_labels(rc), value) != 0)
953
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'.",
967
- line, filename, rc->name, key, value, value);
954
+ line, filename, rrdcalc_name(rc), key, value, value);
955
969
- freez(rc->host_labels);
956
+ string_freez(rc->host_labels);
957
simple_pattern_free(rc->host_labels_pattern);
958
}
959
973
- rc->host_labels = simple_pattern_trim_around_equal(value);
974
- rc->host_labels_pattern = simple_pattern_create(rc->host_labels, NULL, SIMPLE_PATTERN_EXACT);
960
+ {
961
+ char *tmp = simple_pattern_trim_around_equal(value);
962
+ rc->host_labels = string_strdupz(tmp);
963
+ freez(tmp);
964
+ }
965
+ rc->host_labels_pattern = simple_pattern_create(rrdcalc_host_labels(rc), NULL, SIMPLE_PATTERN_EXACT);
966
}
967
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
977
- alert_cfg->plugin = strdupz(value);
978
- freez(rc->plugin_match);
968
+ alert_cfg->plugin = string_strdupz(value);
969
+ string_freez(rc->plugin_match);
970
simple_pattern_free(rc->plugin_pattern);
971
981
- rc->plugin_match = strdupz(value);
982
- rc->plugin_pattern = simple_pattern_create(rc->plugin_match, NULL, SIMPLE_PATTERN_EXACT);
972
+ rc->plugin_match = string_strdupz(value);
973
+ rc->plugin_pattern = simple_pattern_create(rrdcalc_plugin_match(rc), NULL, SIMPLE_PATTERN_EXACT);
974
}
975
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
985
- alert_cfg->module = strdupz(value);
986
- freez(rc->module_match);
976
+ alert_cfg->module = string_strdupz(value);
977
+ string_freez(rc->module_match);
978
simple_pattern_free(rc->module_pattern);
979
989
- rc->module_match = strdupz(value);
990
- rc->module_pattern = simple_pattern_create(rc->module_match, NULL, SIMPLE_PATTERN_EXACT);
980
+ rc->module_match = string_strdupz(value);
981
+ rc->module_pattern = simple_pattern_create(rrdcalc_module_match(rc), NULL, SIMPLE_PATTERN_EXACT);
982
}
983
else {
984
error("Health configuration at line %zu of file '%s' for alarm '%s' has unknown key '%s'.",
994
- line, filename, rc->name, key);
985
+ line, filename, rrdcalc_name(rc), key);
986
}
987
}
988
else if(rt) {
989
if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
999
- alert_cfg->on = strdupz(value);
990
+ alert_cfg->on = string_strdupz(value);
991
if(rt->context) {
1001
- if(strcmp(rt->context, value) != 0)
992
+ if(strcmp(string2str(rt->context), value) != 0)
993
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').",
1003
- line, filename, rt->name, key, rt->context, value, value);
994
+ line, filename, rrdcalctemplate_name(rt), key, string2str(rt->context), value, value);
995
1005
- freez(rt->context);
996
+ string_freez(rt->context);
997
}
1007
- rt->context = strdupz(value);
1008
- rt->hash_context = simple_hash(rt->context);
998
+ rt->context = string_strdupz(value);
999
}
1000
else if(hash == hash_class && !strcasecmp(key, HEALTH_CLASS_KEY)) {
1011
- alert_cfg->classification = strdupz(value);
1001
+ strip_quotes(value);
1002
+
1003
+ alert_cfg->classification = string_strdupz(value);
1004
if(rt->classification) {
1013
- if(strcmp(rt->classification, value) != 0)
1005
+ if(strcmp(rrdcalctemplate_classification(rt), value) != 0)
1006
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').",
1015
- line, filename, rt->name, key, rt->classification, value, value);
1007
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_classification(rt), value, value);
1008
1017
- freez(rt->classification);
1009
+ string_freez(rt->classification);
1010
}
1019
- rt->classification = strdupz(value);
1020
- strip_quotes(rt->classification);
1011
+ rt->classification = string_strdupz(value);
1012
}
1013
else if(hash == hash_component && !strcasecmp(key, HEALTH_COMPONENT_KEY)) {
1023
- alert_cfg->component = strdupz(value);
1014
+ strip_quotes(value);
1015
+
1016
+ alert_cfg->component = string_strdupz(value);
1017
if(rt->component) {
1025
- if(strcmp(rt->component, value) != 0)
1018
+ if(strcmp(rrdcalctemplate_component(rt), value) != 0)
1019
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').",
1027
- line, filename, rt->name, key, rt->component, value, value);
1020
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_component(rt), value, value);
1021
1029
- freez(rt->component);
1022
+ string_freez(rt->component);
1023
}
1031
- rt->component = strdupz(value);
1032
- strip_quotes(rt->component);
1024
+ rt->component = string_strdupz(value);
1025
}
1026
else if(hash == hash_type && !strcasecmp(key, HEALTH_TYPE_KEY)) {
1035
- alert_cfg->type = strdupz(value);
1027
+ strip_quotes(value);
1028
+
1029
+ alert_cfg->type = string_strdupz(value);
1030
if(rt->type) {
1037
- if(strcmp(rt->type, value) != 0)
1031
+ if(strcmp(rrdcalctemplate_type(rt), value) != 0)
1032
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').",
1039
- line, filename, rt->name, key, rt->type, value, value);
1033
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_type(rt), value, value);
1034
1041
- freez(rt->type);
1035
+ string_freez(rt->type);
1036
}
1043
- rt->type = strdupz(value);
1044
- strip_quotes(rt->type);
1037
+ rt->type = string_strdupz(value);
1038
}
1039
else if(hash == hash_families && !strcasecmp(key, HEALTH_FAMILIES_KEY)) {
1047
- alert_cfg->families = strdupz(value);
1048
- freez(rt->family_match);
1040
+ alert_cfg->families = string_strdupz(value);
1041
+ string_freez(rt->family_match);
1042
simple_pattern_free(rt->family_pattern);
1043
1051
- rt->family_match = strdupz(value);
1052
- rt->family_pattern = simple_pattern_create(rt->family_match, NULL, SIMPLE_PATTERN_EXACT);
1044
+ rt->family_match = string_strdupz(value);
1045
+ rt->family_pattern = simple_pattern_create(rrdcalctemplate_family_match(rt), NULL, SIMPLE_PATTERN_EXACT);
1046
}
1047
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
1055
- alert_cfg->plugin = strdupz(value);
1056
- freez(rt->plugin_match);
1048
+ alert_cfg->plugin = string_strdupz(value);
1049
+ string_freez(rt->plugin_match);
1050
simple_pattern_free(rt->plugin_pattern);
1051
1059
- rt->plugin_match = strdupz(value);
1060
- rt->plugin_pattern = simple_pattern_create(rt->plugin_match, NULL, SIMPLE_PATTERN_EXACT);
1052
+ rt->plugin_match = string_strdupz(value);
1053
+ rt->plugin_pattern = simple_pattern_create(rrdcalctemplate_plugin_match(rt), NULL, SIMPLE_PATTERN_EXACT);
1054
}
1055
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
1063
- alert_cfg->module = strdupz(value);
1064
- freez(rt->module_match);
1056
+ alert_cfg->module = string_strdupz(value);
1057
+ string_freez(rt->module_match);
1058
simple_pattern_free(rt->module_pattern);
1059
1067
- rt->module_match = strdupz(value);
1068
- rt->module_pattern = simple_pattern_create(rt->module_match, NULL, SIMPLE_PATTERN_EXACT);
1060
+ rt->module_match = string_strdupz(value);
1061
+ rt->module_pattern = simple_pattern_create(rrdcalctemplate_module_match(rt), NULL, SIMPLE_PATTERN_EXACT);
1062
}
1063
else if(hash == hash_charts && !strcasecmp(key, HEALTH_CHARTS_KEY)) {
1071
- alert_cfg->charts = strdupz(value);
1072
- freez(rt->charts_match);
1064
+ alert_cfg->charts = string_strdupz(value);
1065
+ string_freez(rt->charts_match);
1066
simple_pattern_free(rt->charts_pattern);
1067
1075
- rt->charts_match = strdupz(value);
1076
- rt->charts_pattern = simple_pattern_create(rt->charts_match, NULL, SIMPLE_PATTERN_EXACT);
1068
+ rt->charts_match = string_strdupz(value);
1069
+ rt->charts_pattern = simple_pattern_create(rrdcalctemplate_charts_match(rt), NULL, SIMPLE_PATTERN_EXACT);
1070
}
1071
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
1079
- alert_cfg->lookup = strdupz(value);
1072
+ alert_cfg->lookup = string_strdupz(value);
1073
health_parse_db_lookup(line, filename, value, &rt->group, &rt->after, &rt->before,
1074
&rt->update_every, &rt->options, &rt->dimensions, &rt->foreachdim);
1082
- if(rt->foreachdim) {
1083
- rt->spdim = health_pattern_from_foreach(rt->foreachdim);
1084
- }
1075
+
1076
+ if(rt->foreachdim)
1077
+ rt->spdim = health_pattern_from_foreach(rrdcalctemplate_foreachdim(rt));
1078
+
1079
if (rt->after) {
1080
if (rt->dimensions)
1087
- alert_cfg->p_db_lookup_dimensions = strdupz(rt->dimensions);
1081
+ alert_cfg->p_db_lookup_dimensions = string_dup(rt->dimensions);
1082
+
1083
if (rt->group)
1089
- alert_cfg->p_db_lookup_method = strdupz(group_method2string(rt->group));
1084
+ alert_cfg->p_db_lookup_method = string_strdupz(group_method2string(rt->group));
1085
+
1086
alert_cfg->p_db_lookup_options = rt->options;
1087
alert_cfg->p_db_lookup_after = rt->after;
1088
alert_cfg->p_db_lookup_before = rt->before;
1090
}
1091
}
1092
else if(hash == hash_every && !strcasecmp(key, HEALTH_EVERY_KEY)) {
1097
- alert_cfg->every = strdupz(value);
1093
+ alert_cfg->every = string_strdupz(value);
1094
if(!config_parse_duration(value, &rt->update_every))
1095
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' cannot parse duration: '%s'.",
1100
- line, filename, rt->name, key, value);
1096
+ line, filename, rrdcalctemplate_name(rt), key, value);
1097
alert_cfg->p_update_every = rt->update_every;
1098
}
1099
else if(hash == hash_green && !strcasecmp(key, HEALTH_GREEN_KEY)) {
1104
- alert_cfg->green = strdupz(value);
1100
+ alert_cfg->green = string_strdupz(value);
1101
char *e;
1102
rt->green = str2ndd(value, &e);
1103
if(e && *e) {
1104
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
1109
- line, filename, rt->name, key, e);
1105
+ line, filename, rrdcalctemplate_name(rt), key, e);
1106
}
1107
}
1108
else if(hash == hash_red && !strcasecmp(key, HEALTH_RED_KEY)) {
1113
- alert_cfg->red = strdupz(value);
1109
+ alert_cfg->red = string_strdupz(value);
1110
char *e;
1111
rt->red = str2ndd(value, &e);
1112
if(e && *e) {
1113
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
1118
- line, filename, rt->name, key, e);
1114
+ line, filename, rrdcalctemplate_name(rt), key, e);
1115
}
1116
}
1117
else if(hash == hash_calc && !strcasecmp(key, HEALTH_CALC_KEY)) {
1122
- alert_cfg->calc = strdupz(value);
1118
+ alert_cfg->calc = string_strdupz(value);
1119
const char *failed_at = NULL;
1120
int error = 0;
1121
rt->calculation = expression_parse(value, &failed_at, &error);
1122
if(!rt->calculation) {
1123
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
1128
- line, filename, rt->name, key, value, expression_strerror(error), failed_at);
1124
+ line, filename, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
1125
}
1126
}
1127
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
1132
- alert_cfg->warn = strdupz(value);
1128
+ alert_cfg->warn = string_strdupz(value);
1129
const char *failed_at = NULL;
1130
int error = 0;
1131
rt->warning = expression_parse(value, &failed_at, &error);
1132
if(!rt->warning) {
1133
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
1138
- line, filename, rt->name, key, value, expression_strerror(error), failed_at);
1134
+ line, filename, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
1135
}
1136
}
1137
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
1142
- alert_cfg->crit = strdupz(value);
1138
+ alert_cfg->crit = string_strdupz(value);
1139
const char *failed_at = NULL;
1140
int error = 0;
1141
rt->critical = expression_parse(value, &failed_at, &error);
1142
if(!rt->critical) {
1143
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
1148
- line, filename, rt->name, key, value, expression_strerror(error), failed_at);
1144
+ line, filename, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
1145
}
1146
}
1147
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
1152
- alert_cfg->exec = strdupz(value);
1148
+ alert_cfg->exec = string_strdupz(value);
1149
if(rt->exec) {
1154
- if(strcmp(rt->exec, value) != 0)
1150
+ if(strcmp(rrdcalctemplate_exec(rt), value) != 0)
1151
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').",
1156
- line, filename, rt->name, key, rt->exec, value, value);
1152
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_exec(rt), value, value);
1153
1158
- freez(rt->exec);
1154
+ string_freez(rt->exec);
1155
}
1160
- rt->exec = strdupz(value);
1156
+ rt->exec = string_strdupz(value);
1157
}
1158
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
1163
- alert_cfg->to = strdupz(value);
1159
+ alert_cfg->to = string_strdupz(value);
1160
if(rt->recipient) {
1165
- if(strcmp(rt->recipient, value) != 0)
1161
+ if(strcmp(rrdcalctemplate_recipient(rt), value) != 0)
1162
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').",
1167
- line, filename, rt->name, key, rt->recipient, value, value);
1163
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_recipient(rt), value, value);
1164
1169
- freez(rt->recipient);
1165
+ string_freez(rt->recipient);
1166
}
1171
- rt->recipient = strdupz(value);
1167
+ rt->recipient = string_strdupz(value);
1168
}
1169
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
1174
- alert_cfg->units = strdupz(value);
1170
+ strip_quotes(value);
1171
+
1172
+ alert_cfg->units = string_strdupz(value);
1173
if(rt->units) {
1176
- if(strcmp(rt->units, value) != 0)
1174
+ if(strcmp(rrdcalctemplate_units(rt), value) != 0)
1175
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').",
1178
- line, filename, rt->name, key, rt->units, value, value);
1176
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_units(rt), value, value);
1177
1180
- freez(rt->units);
1178
+ string_freez(rt->units);
1179
}
1182
- rt->units = strdupz(value);
1183
- strip_quotes(rt->units);
1180
+ rt->units = string_strdupz(value);
1181
}
1182
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
1186
- alert_cfg->info = strdupz(value);
1183
+ strip_quotes(value);
1184
+
1185
+ alert_cfg->info = string_strdupz(value);
1186
if(rt->info) {
1188
- if(strcmp(rt->info, value) != 0)
1187
+ if(strcmp(rrdcalctemplate_info(rt), value) != 0)
1188
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').",
1190
- line, filename, rt->name, key, rt->info, value, value);
1189
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_info(rt), value, value);
1190
1192
- freez(rt->info);
1191
+ string_freez(rt->info);
1192
}
1194
- rt->info = strdupz(value);
1195
- strip_quotes(rt->info);
1193
+ rt->info = string_strdupz(value);
1194
}
1195
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
1198
- alert_cfg->delay = strdupz(value);
1196
+ alert_cfg->delay = string_strdupz(value);
1197
health_parse_delay(line, filename, value, &rt->delay_up_duration, &rt->delay_down_duration, &rt->delay_max_duration, &rt->delay_multiplier);
1198
}
1199
else if(hash == hash_options && !strcasecmp(key, HEALTH_OPTIONS_KEY)) {
1202
- alert_cfg->options = strdupz(value);
1200
+ alert_cfg->options = string_strdupz(value);
1201
rt->options |= health_parse_options(value);
1202
}
1203
else if(hash == hash_repeat && !strcasecmp(key, HEALTH_REPEAT_KEY)){
1206
- alert_cfg->repeat = strdupz(value);
1204
+ alert_cfg->repeat = string_strdupz(value);
1205
health_parse_repeat(line, filename, value,
1206
&rt->warn_repeat_every,
1207
&rt->crit_repeat_every);
1208
}
1209
else if(hash == hash_host_label && !strcasecmp(key, HEALTH_HOST_LABEL_KEY)) {
1212
- alert_cfg->host_labels = strdupz(value);
1210
+ alert_cfg->host_labels = string_strdupz(value);
1211
if(rt->host_labels) {
1214
- if(strcmp(rt->host_labels, value) != 0)
1212
+ if(strcmp(rrdcalctemplate_host_labels(rt), value) != 0)
1213
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').",
1216
- line, filename, rt->name, key, rt->host_labels, value, value);
1214
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_host_labels(rt), value, value);
1215
1218
- freez(rt->host_labels);
1216
+ string_freez(rt->host_labels);
1217
simple_pattern_free(rt->host_labels_pattern);
1218
}
1219
1222
- rt->host_labels = simple_pattern_trim_around_equal(value);
1223
- rt->host_labels_pattern = simple_pattern_create(rt->host_labels, NULL, SIMPLE_PATTERN_EXACT);
1220
+ {
1221
+ char *tmp = simple_pattern_trim_around_equal(value);
1222
+ rt->host_labels = string_strdupz(tmp);
1223
+ freez(tmp);
1224
+ }
1225
+ rt->host_labels_pattern = simple_pattern_create(rrdcalctemplate_host_labels(rt), NULL, SIMPLE_PATTERN_EXACT);
1226
}
1227
else {
1228
error("Health configuration at line %zu of file '%s' for template '%s' has unknown key '%s'.",
1227
- line, filename, rt->name, key);
1229
+ line, filename, rrdcalctemplate_name(rt), key);
1230
}
1231
}
1232
else {
1262
1263
void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path, const char *subpath) {
1264
if(unlikely(!host->health_enabled)) {
1263
- debug(D_HEALTH, "CONFIG health is not enabled for host '%s'", host->hostname);
1265
+ debug(D_HEALTH, "CONFIG health is not enabled for host '%s'", rrdhost_hostname(host));
1266
return;
1267
}
1268