summaryrefslogtreecommitdiffstats
path: root/health/health_config.c
diff options
context:
space:
mode:
Diffstat (limited to 'health/health_config.c')
-rw-r--r--health/health_config.c705
1 files changed, 306 insertions, 399 deletions
diff --git a/health/health_config.c b/health/health_config.c
index e1dd32ab1..f9decfad5 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -33,148 +33,6 @@
#define HEALTH_HOST_LABEL_KEY "host labels"
#define HEALTH_FOREACH_KEY "foreach"
-static inline int rrdcalc_add_alarm_from_config(RRDHOST *host, RRDCALC *rc) {
- if(!rc->chart) {
- error("Health configuration for alarm '%s' does not have a chart", rc->name);
- return 0;
- }
-
- if(!rc->update_every) {
- error("Health configuration for alarm '%s.%s' has no frequency (parameter 'every'). Ignoring it.", rc->chart?rc->chart:"NOCHART", rc->name);
- return 0;
- }
-
- if(!RRDCALC_HAS_DB_LOOKUP(rc) && !rc->calculation && !rc->warning && !rc->critical) {
- 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);
- return 0;
- }
-
- if (rrdcalc_exists(host, rc->chart, rc->name, rc->hash_chart, rc->hash))
- return 0;
-
- rc->id = rrdcalc_get_unique_id(host, rc->chart, rc->name, &rc->next_event_id);
-
- debug(D_HEALTH, "Health configuration adding alarm '%s.%s' (%u): exec '%s', recipient '%s', green " NETDATA_DOUBLE_FORMAT_AUTO
- ", red " NETDATA_DOUBLE_FORMAT_AUTO
- ", 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",
- rc->chart?rc->chart:"NOCHART",
- rc->name,
- rc->id,
- (rc->exec)?rc->exec:"DEFAULT",
- (rc->recipient)?rc->recipient:"DEFAULT",
- rc->green,
- rc->red,
- (int)rc->group,
- rc->after,
- rc->before,
- rc->options,
- (rc->dimensions)?rc->dimensions:"NONE",
- (rc->foreachdim)?rc->foreachdim:"NONE",
- rc->update_every,
- (rc->calculation)?rc->calculation->parsed_as:"NONE",
- (rc->warning)?rc->warning->parsed_as:"NONE",
- (rc->critical)?rc->critical->parsed_as:"NONE",
- rc->source,
- rc->delay_up_duration,
- rc->delay_down_duration,
- rc->delay_max_duration,
- rc->delay_multiplier,
- rc->warn_repeat_every,
- rc->crit_repeat_every
- );
-
- rrdcalc_add_to_host(host, rc);
-
- return 1;
-}
-
-static inline int rrdcalctemplate_add_template_from_config(RRDHOST *host, RRDCALCTEMPLATE *rt) {
- if(unlikely(!rt->context)) {
- error("Health configuration for template '%s' does not have a context", rt->name);
- return 0;
- }
-
- if(unlikely(!rt->update_every)) {
- error("Health configuration for template '%s' has no frequency (parameter 'every'). Ignoring it.", rt->name);
- return 0;
- }
-
- if(unlikely(!RRDCALCTEMPLATE_HAS_DB_LOOKUP(rt) && !rt->calculation && !rt->warning && !rt->critical)) {
- error("Health configuration for template '%s' is useless (no calculation, no warning and no critical evaluation)", rt->name);
- return 0;
- }
-
- RRDCALCTEMPLATE *t, *last = NULL;
- if(!rt->foreachdim) {
- for (t = host->templates; t ; last = t, t = t->next) {
- if(unlikely(t->hash_name == rt->hash_name
- && !strcmp(t->name, rt->name)
- && !strcmp(t->family_match?t->family_match:"*", rt->family_match?rt->family_match:"*")
- )) {
- info("Health configuration template '%s' already exists for host '%s'.", rt->name, host->hostname);
- return 0;
- }
- }
-
- if(likely(last)) {
- last->next = rt;
- }
- else {
- rt->next = host->templates;
- host->templates = rt;
- }
- } else {
- for (t = host->alarms_template_with_foreach; t ; last = t, t = t->next) {
- if(unlikely(t->hash_name == rt->hash_name
- && !strcmp(t->name, rt->name)
- && !strcmp(t->family_match?t->family_match:"*", rt->family_match?rt->family_match:"*")
- )) {
- info("Health configuration template '%s' already exists for host '%s'.", rt->name, host->hostname);
- return 0;
- }
- }
-
- if(likely(last)) {
- last->next = rt;
- }
- else {
- rt->next = host->alarms_template_with_foreach;
- host->alarms_template_with_foreach = rt;
- }
- }
-
- debug(D_HEALTH, "Health configuration adding template '%s': context '%s', exec '%s', recipient '%s', green " NETDATA_DOUBLE_FORMAT_AUTO
- ", red " NETDATA_DOUBLE_FORMAT_AUTO
- ", 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",
- rt->name,
- (rt->context)?rt->context:"NONE",
- (rt->exec)?rt->exec:"DEFAULT",
- (rt->recipient)?rt->recipient:"DEFAULT",
- rt->green,
- rt->red,
- (int)rt->group,
- rt->after,
- rt->before,
- rt->options,
- (rt->dimensions)?rt->dimensions:"NONE",
- (rt->foreachdim)?rt->foreachdim:"NONE",
- rt->update_every,
- (rt->calculation)?rt->calculation->parsed_as:"NONE",
- (rt->warning)?rt->warning->parsed_as:"NONE",
- (rt->critical)?rt->critical->parsed_as:"NONE",
- rt->source,
- rt->delay_up_duration,
- rt->delay_down_duration,
- rt->delay_max_duration,
- rt->delay_multiplier,
- rt->warn_repeat_every,
- rt->crit_repeat_every
- );
-
-
- return 1;
-}
-
static inline int health_parse_delay(
size_t line, const char *filename, char *string,
int *delay_up_duration,
@@ -275,7 +133,7 @@ static inline uint32_t health_parse_options(const char *s) {
buf[count] = '\0';
if(!strcasecmp(buf, "no-clear-notification") || !strcasecmp(buf, "no-clear"))
- options |= RRDCALC_FLAG_NO_CLEAR_NOTIFICATION;
+ options |= RRDCALC_OPTION_NO_CLEAR_NOTIFICATION;
else
error("Ignoring unknown alarm option '%s'", buf);
}
@@ -334,13 +192,21 @@ static inline int health_parse_repeat(
*
* @param s the string that will be used to create the simple pattern.
*/
-SIMPLE_PATTERN *health_pattern_from_foreach(char *s) {
+
+static void dimension_remove_pipe_comma(char *str) {
+ while(*str) {
+ if(*str == '|' || *str == ',') *str = ' ';
+ str++;
+ }
+}
+
+static SIMPLE_PATTERN *health_pattern_from_foreach(const char *s) {
char *convert= strdupz(s);
SIMPLE_PATTERN *val = NULL;
+
if(convert) {
dimension_remove_pipe_comma(convert);
val = simple_pattern_create(convert, NULL, SIMPLE_PATTERN_EXACT);
-
freez(convert);
}
@@ -350,18 +216,18 @@ SIMPLE_PATTERN *health_pattern_from_foreach(char *s) {
static inline int health_parse_db_lookup(
size_t line, const char *filename, char *string,
RRDR_GROUPING *group_method, int *after, int *before, int *every,
- uint32_t *options, char **dimensions, char **foreachdim
+ RRDCALC_OPTIONS *options, STRING **dimensions, STRING **foreachdim
) {
debug(D_HEALTH, "Health configuration parsing database lookup %zu@%s: %s", line, filename, string);
- if(*dimensions) freez(*dimensions);
- if(*foreachdim) freez(*foreachdim);
+ if(*dimensions) string_freez(*dimensions);
+ if(*foreachdim) string_freez(*foreachdim);
*dimensions = NULL;
*foreachdim = NULL;
*after = 0;
*before = 0;
*every = 0;
- *options = 0;
+ *options = (*options) & RRDCALC_ALL_OPTIONS_EXCLUDING_THE_RRDR_ONES; // preserve rrdcalc options
char *s = string, *key;
@@ -453,7 +319,7 @@ static inline int health_parse_db_lookup(
if(find) {
*find = '\0';
}
- *dimensions = strdupz(s);
+ *dimensions = string_strdupz(s);
}
if(!find) {
@@ -462,7 +328,7 @@ static inline int health_parse_db_lookup(
s = ++find;
}
else if(!strcasecmp(key, HEALTH_FOREACH_KEY )) {
- *foreachdim = strdupz(s);
+ *foreachdim = string_strdupz(s);
break;
}
else {
@@ -474,10 +340,10 @@ static inline int health_parse_db_lookup(
return 1;
}
-static inline char *health_source_file(size_t line, const char *file) {
+static inline STRING *health_source_file(size_t line, const char *file) {
char buffer[FILENAME_MAX + 1];
snprintfz(buffer, FILENAME_MAX, "%zu@%s", line, file);
- return strdupz(buffer);
+ return string_strdupz(buffer);
}
char *health_edit_command_from_source(const char *source)
@@ -496,7 +362,7 @@ char *health_edit_command_from_source(const char *source)
netdata_configured_user_config_dir,
file_no_path + 1,
temp,
- localhost->registry_hostname);
+ rrdhost_registry_hostname(localhost));
} else
buffer[0] = '\0';
@@ -513,35 +379,35 @@ static inline void strip_quotes(char *s) {
static inline void alert_config_free(struct alert_config *cfg)
{
- freez(cfg->alarm);
- freez(cfg->template_key);
- freez(cfg->os);
- freez(cfg->host);
- freez(cfg->on);
- freez(cfg->families);
- freez(cfg->plugin);
- freez(cfg->module);
- freez(cfg->charts);
- freez(cfg->lookup);
- freez(cfg->calc);
- freez(cfg->warn);
- freez(cfg->crit);
- freez(cfg->every);
- freez(cfg->green);
- freez(cfg->red);
- freez(cfg->exec);
- freez(cfg->to);
- freez(cfg->units);
- freez(cfg->info);
- freez(cfg->classification);
- freez(cfg->component);
- freez(cfg->type);
- freez(cfg->delay);
- freez(cfg->options);
- freez(cfg->repeat);
- freez(cfg->host_labels);
- freez(cfg->p_db_lookup_dimensions);
- freez(cfg->p_db_lookup_method);
+ string_freez(cfg->alarm);
+ string_freez(cfg->template_key);
+ string_freez(cfg->os);
+ string_freez(cfg->host);
+ string_freez(cfg->on);
+ string_freez(cfg->families);
+ string_freez(cfg->plugin);
+ string_freez(cfg->module);
+ string_freez(cfg->charts);
+ string_freez(cfg->lookup);
+ string_freez(cfg->calc);
+ string_freez(cfg->warn);
+ string_freez(cfg->crit);
+ string_freez(cfg->every);
+ string_freez(cfg->green);
+ string_freez(cfg->red);
+ string_freez(cfg->exec);
+ string_freez(cfg->to);
+ string_freez(cfg->units);
+ string_freez(cfg->info);
+ string_freez(cfg->classification);
+ string_freez(cfg->component);
+ string_freez(cfg->type);
+ string_freez(cfg->delay);
+ string_freez(cfg->options);
+ string_freez(cfg->repeat);
+ string_freez(cfg->host_labels);
+ string_freez(cfg->p_db_lookup_dimensions);
+ string_freez(cfg->p_db_lookup_method);
freez(cfg);
}
@@ -670,23 +536,35 @@ static int health_readfile(const char *filename, void *data) {
if(hash == hash_alarm && !strcasecmp(key, HEALTH_ALARM_KEY)) {
if(rc) {
- if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
- rrdcalc_free(rc);
- }
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this)
+ rrdcalc_free_unused_rrdcalc_loaded_from_config(rc);
+ else
+ rrdcalc_add_from_config(host, rc);
+
// health_add_alarms_loop(host, rc, ignore_this) ;
}
if(rt) {
- if (!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
- rrdcalctemplate_free(rt);
- }
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this)
+ rrdcalctemplate_free_unused_rrdcalctemplate_loaded_from_config(rt);
+ else
+ rrdcalctemplate_add_from_config(host, rt);
+
rt = NULL;
}
rc = callocz(1, sizeof(RRDCALC));
rc->next_event_id = 1;
- rc->name = strdupz(value);
- rc->hash = simple_hash(rc->name);
+
+ {
+ char *tmp = strdupz(value);
+ if(rrdvar_fix_name(tmp))
+ error("Health configuration renamed alarm '%s' to '%s'", value, tmp);
+
+ rc->name = string_strdupz(tmp);
+ freez(tmp);
+ }
+
rc->source = health_source_file(line, filename);
rc->green = NAN;
rc->red = NAN;
@@ -700,58 +578,62 @@ static int health_readfile(const char *filename, void *data) {
alert_config_free(alert_cfg);
alert_cfg = callocz(1, sizeof(struct alert_config));
- if(rrdvar_fix_name(rc->name))
- error("Health configuration renamed alarm '%s' to '%s'", value, rc->name);
-
- alert_cfg->alarm = strdupz(rc->name);
+ alert_cfg->alarm = string_dup(rc->name);
ignore_this = 0;
}
else if(hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) {
if(rc) {
// health_add_alarms_loop(host, rc, ignore_this) ;
- if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
- rrdcalc_free(rc);
- }
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this)
+ rrdcalc_free_unused_rrdcalc_loaded_from_config(rc);
+ else
+ rrdcalc_add_from_config(host, rc);
rc = NULL;
}
if(rt) {
- if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
- rrdcalctemplate_free(rt);
- }
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this)
+ rrdcalctemplate_free_unused_rrdcalctemplate_loaded_from_config(rt);
+ else
+ rrdcalctemplate_add_from_config(host, rt);
}
rt = callocz(1, sizeof(RRDCALCTEMPLATE));
- rt->name = strdupz(value);
- rt->hash_name = simple_hash(rt->name);
+
+ {
+ char *tmp = strdupz(value);
+ if(rrdvar_fix_name(tmp))
+ error("Health configuration renamed template '%s' to '%s'", value, tmp);
+
+ rt->name = string_strdupz(tmp);
+ freez(tmp);
+ }
+
rt->source = health_source_file(line, filename);
rt->green = NAN;
rt->red = NAN;
- rt->delay_multiplier = 1.0;
+ rt->delay_multiplier = (float)1.0;
rt->warn_repeat_every = host->health_default_warn_repeat_every;
rt->crit_repeat_every = host->health_default_crit_repeat_every;
if (alert_cfg)
alert_config_free(alert_cfg);
alert_cfg = callocz(1, sizeof(struct alert_config));
- if(rrdvar_fix_name(rt->name))
- error("Health configuration renamed template '%s' to '%s'", value, rt->name);
-
- alert_cfg->template_key = strdupz(rt->name);
+ alert_cfg->template_key = string_dup(rt->name);
ignore_this = 0;
}
else if(hash == hash_os && !strcasecmp(key, HEALTH_OS_KEY)) {
char *os_match = value;
- if (alert_cfg) alert_cfg->os = strdupz(value);
+ if (alert_cfg) alert_cfg->os = string_strdupz(value);
SIMPLE_PATTERN *os_pattern = simple_pattern_create(os_match, NULL, SIMPLE_PATTERN_EXACT);
- if(!simple_pattern_matches(os_pattern, host->os)) {
+ if(!simple_pattern_matches(os_pattern, rrdhost_os(host))) {
if(rc)
- 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);
+ 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);
if(rt)
- 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);
+ 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);
ignore_this = 1;
}
@@ -760,15 +642,15 @@ static int health_readfile(const char *filename, void *data) {
}
else if(hash == hash_host && !strcasecmp(key, HEALTH_HOST_KEY)) {
char *host_match = value;
- if (alert_cfg) alert_cfg->host = strdupz(value);
+ if (alert_cfg) alert_cfg->host = string_strdupz(value);
SIMPLE_PATTERN *host_pattern = simple_pattern_create(host_match, NULL, SIMPLE_PATTERN_EXACT);
- if(!simple_pattern_matches(host_pattern, host->hostname)) {
+ if(!simple_pattern_matches(host_pattern, rrdhost_hostname(host))) {
if(rc)
- 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);
+ 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);
if(rt)
- 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);
+ 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);
ignore_this = 1;
}
@@ -777,65 +659,68 @@ static int health_readfile(const char *filename, void *data) {
}
else if(rc) {
if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
- alert_cfg->on = strdupz(value);
+ alert_cfg->on = string_strdupz(value);
if(rc->chart) {
- if(strcmp(rc->chart, value) != 0)
+ if(strcmp(rrdcalc_chart_name(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->chart, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_chart_name(rc), value, value);
- freez(rc->chart);
+ string_freez(rc->chart);
}
- rc->chart = strdupz(value);
- rc->hash_chart = simple_hash(rc->chart);
+ rc->chart = string_strdupz(value);
}
else if(hash == hash_class && !strcasecmp(key, HEALTH_CLASS_KEY)) {
- alert_cfg->classification = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->classification = string_strdupz(value);
if(rc->classification) {
- if(strcmp(rc->classification, value) != 0)
+ if(strcmp(rrdcalc_classification(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->classification, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_classification(rc), value, value);
- freez(rc->classification);
+ string_freez(rc->classification);
}
- rc->classification = strdupz(value);
- strip_quotes(rc->classification);
+ rc->classification = string_strdupz(value);
}
else if(hash == hash_component && !strcasecmp(key, HEALTH_COMPONENT_KEY)) {
- alert_cfg->component = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->component = string_strdupz(value);
if(rc->component) {
- if(strcmp(rc->component, value) != 0)
+ if(strcmp(rrdcalc_component(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->component, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_component(rc), value, value);
- freez(rc->component);
+ string_freez(rc->component);
}
- rc->component = strdupz(value);
- strip_quotes(rc->component);
+ rc->component = string_strdupz(value);
}
else if(hash == hash_type && !strcasecmp(key, HEALTH_TYPE_KEY)) {
- alert_cfg->type = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->type = string_strdupz(value);
if(rc->type) {
- if(strcmp(rc->type, value) != 0)
+ if(strcmp(rrdcalc_type(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->type, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_type(rc), value, value);
- freez(rc->type);
+ string_freez(rc->type);
}
- rc->type = strdupz(value);
- strip_quotes(rc->type);
+ rc->type = string_strdupz(value);
}
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
- alert_cfg->lookup = strdupz(value);
+ alert_cfg->lookup = string_strdupz(value);
health_parse_db_lookup(line, filename, value, &rc->group, &rc->after, &rc->before,
- &rc->update_every, &rc->options, &rc->dimensions, &rc->foreachdim);
- if(rc->foreachdim) {
- rc->spdim = health_pattern_from_foreach(rc->foreachdim);
- }
+ &rc->update_every, &rc->options, &rc->dimensions, &rc->foreach_dimension);
+
+ if(rc->foreach_dimension)
+ rc->foreach_dimension_pattern = health_pattern_from_foreach(rrdcalc_foreachdim(rc));
+
if (rc->after) {
if (rc->dimensions)
- alert_cfg->p_db_lookup_dimensions = strdupz(rc->dimensions);
+ alert_cfg->p_db_lookup_dimensions = string_dup(rc->dimensions);
if (rc->group)
- alert_cfg->p_db_lookup_method = strdupz(group_method2string(rc->group));
+ alert_cfg->p_db_lookup_method = string_strdupz(group_method2string(rc->group));
alert_cfg->p_db_lookup_options = rc->options;
alert_cfg->p_db_lookup_after = rc->after;
alert_cfg->p_db_lookup_before = rc->before;
@@ -843,248 +728,261 @@ static int health_readfile(const char *filename, void *data) {
}
}
else if(hash == hash_every && !strcasecmp(key, HEALTH_EVERY_KEY)) {
- alert_cfg->every = strdupz(value);
+ alert_cfg->every = string_strdupz(value);
if(!config_parse_duration(value, &rc->update_every))
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' cannot parse duration: '%s'.",
- line, filename, rc->name, key, value);
+ line, filename, rrdcalc_name(rc), key, value);
alert_cfg->p_update_every = rc->update_every;
}
else if(hash == hash_green && !strcasecmp(key, HEALTH_GREEN_KEY)) {
- alert_cfg->green = strdupz(value);
+ alert_cfg->green = string_strdupz(value);
char *e;
rc->green = str2ndd(value, &e);
if(e && *e) {
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
- line, filename, rc->name, key, e);
+ line, filename, rrdcalc_name(rc), key, e);
}
}
else if(hash == hash_red && !strcasecmp(key, HEALTH_RED_KEY)) {
- alert_cfg->red = strdupz(value);
+ alert_cfg->red = string_strdupz(value);
char *e;
rc->red = str2ndd(value, &e);
if(e && *e) {
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' leaves this string unmatched: '%s'.",
- line, filename, rc->name, key, e);
+ line, filename, rrdcalc_name(rc), key, e);
}
}
else if(hash == hash_calc && !strcasecmp(key, HEALTH_CALC_KEY)) {
- alert_cfg->calc = strdupz(value);
+ alert_cfg->calc = string_strdupz(value);
const char *failed_at = NULL;
int error = 0;
rc->calculation = expression_parse(value, &failed_at, &error);
if(!rc->calculation) {
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
- line, filename, rc->name, key, value, expression_strerror(error), failed_at);
+ line, filename, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
}
}
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
- alert_cfg->warn = strdupz(value);
+ alert_cfg->warn = string_strdupz(value);
const char *failed_at = NULL;
int error = 0;
rc->warning = expression_parse(value, &failed_at, &error);
if(!rc->warning) {
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
- line, filename, rc->name, key, value, expression_strerror(error), failed_at);
+ line, filename, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
}
}
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
- alert_cfg->crit = strdupz(value);
+ alert_cfg->crit = string_strdupz(value);
const char *failed_at = NULL;
int error = 0;
rc->critical = expression_parse(value, &failed_at, &error);
if(!rc->critical) {
error("Health configuration at line %zu of file '%s' for alarm '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
- line, filename, rc->name, key, value, expression_strerror(error), failed_at);
+ line, filename, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
}
}
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
- alert_cfg->exec = strdupz(value);
+ alert_cfg->exec = string_strdupz(value);
if(rc->exec) {
- if(strcmp(rc->exec, value) != 0)
+ if(strcmp(rrdcalc_exec(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->exec, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_exec(rc), value, value);
- freez(rc->exec);
+ string_freez(rc->exec);
}
- rc->exec = strdupz(value);
+ rc->exec = string_strdupz(value);
}
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
- alert_cfg->to = strdupz(value);
+ alert_cfg->to = string_strdupz(value);
if(rc->recipient) {
- if(strcmp(rc->recipient, value) != 0)
+ if(strcmp(rrdcalc_recipient(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->recipient, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_recipient(rc), value, value);
- freez(rc->recipient);
+ string_freez(rc->recipient);
}
- rc->recipient = strdupz(value);
+ rc->recipient = string_strdupz(value);
}
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
- alert_cfg->units = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->units = string_strdupz(value);
if(rc->units) {
- if(strcmp(rc->units, value) != 0)
+ if(strcmp(rrdcalc_units(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->units, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_units(rc), value, value);
- freez(rc->units);
+ string_freez(rc->units);
}
- rc->units = strdupz(value);
- strip_quotes(rc->units);
+ rc->units = string_strdupz(value);
}
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
- alert_cfg->info = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->info = string_strdupz(value);
if(rc->info) {
- if(strcmp(rc->info, value) != 0)
+ if(strcmp(rrdcalc_info(rc), value) != 0)
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').",
- line, filename, rc->name, key, rc->info, value, value);
+ line, filename, rrdcalc_name(rc), key, rrdcalc_info(rc), value, value);
- freez(rc->info);
+ string_freez(rc->info);
+ string_freez(rc->original_info);
}
- rc->info = strdupz(value);
- strip_quotes(rc->info);
+ rc->info = string_strdupz(value);
+ rc->original_info = string_dup(rc->info);
}
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
- alert_cfg->delay = strdupz(value);
+ alert_cfg->delay = string_strdupz(value);
health_parse_delay(line, filename, value, &rc->delay_up_duration, &rc->delay_down_duration, &rc->delay_max_duration, &rc->delay_multiplier);
}
else if(hash == hash_options && !strcasecmp(key, HEALTH_OPTIONS_KEY)) {
- alert_cfg->options = strdupz(value);
+ alert_cfg->options = string_strdupz(value);
rc->options |= health_parse_options(value);
}
else if(hash == hash_repeat && !strcasecmp(key, HEALTH_REPEAT_KEY)){
- alert_cfg->repeat = strdupz(value);
+ alert_cfg->repeat = string_strdupz(value);
health_parse_repeat(line, filename, value,
&rc->warn_repeat_every,
&rc->crit_repeat_every);
}
else if(hash == hash_host_label && !strcasecmp(key, HEALTH_HOST_LABEL_KEY)) {
- alert_cfg->host_labels = strdupz(value);
+ alert_cfg->host_labels = string_strdupz(value);
if(rc->host_labels) {
- if(strcmp(rc->host_labels, value) != 0)
+ if(strcmp(rrdcalc_host_labels(rc), value) != 0)
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'.",
- line, filename, rc->name, key, value, value);
+ line, filename, rrdcalc_name(rc), key, value, value);
- freez(rc->host_labels);
+ string_freez(rc->host_labels);
simple_pattern_free(rc->host_labels_pattern);
}
- rc->host_labels = simple_pattern_trim_around_equal(value);
- rc->host_labels_pattern = simple_pattern_create(rc->host_labels, NULL, SIMPLE_PATTERN_EXACT);
+ {
+ char *tmp = simple_pattern_trim_around_equal(value);
+ rc->host_labels = string_strdupz(tmp);
+ freez(tmp);
+ }
+ rc->host_labels_pattern = simple_pattern_create(rrdcalc_host_labels(rc), NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
- alert_cfg->plugin = strdupz(value);
- freez(rc->plugin_match);
+ alert_cfg->plugin = string_strdupz(value);
+ string_freez(rc->plugin_match);
simple_pattern_free(rc->plugin_pattern);
- rc->plugin_match = strdupz(value);
- rc->plugin_pattern = simple_pattern_create(rc->plugin_match, NULL, SIMPLE_PATTERN_EXACT);
+ rc->plugin_match = string_strdupz(value);
+ rc->plugin_pattern = simple_pattern_create(rrdcalc_plugin_match(rc), NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
- alert_cfg->module = strdupz(value);
- freez(rc->module_match);
+ alert_cfg->module = string_strdupz(value);
+ string_freez(rc->module_match);
simple_pattern_free(rc->module_pattern);
- rc->module_match = strdupz(value);
- rc->module_pattern = simple_pattern_create(rc->module_match, NULL, SIMPLE_PATTERN_EXACT);
+ rc->module_match = string_strdupz(value);
+ rc->module_pattern = simple_pattern_create(rrdcalc_module_match(rc), NULL, SIMPLE_PATTERN_EXACT);
}
else {
error("Health configuration at line %zu of file '%s' for alarm '%s' has unknown key '%s'.",
- line, filename, rc->name, key);
+ line, filename, rrdcalc_name(rc), key);
}
}
else if(rt) {
if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
- alert_cfg->on = strdupz(value);
+ alert_cfg->on = string_strdupz(value);
if(rt->context) {
- if(strcmp(rt->context, value) != 0)
+ if(strcmp(string2str(rt->context), value) != 0)
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').",
- line, filename, rt->name, key, rt->context, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, string2str(rt->context), value, value);
- freez(rt->context);
+ string_freez(rt->context);
}
- rt->context = strdupz(value);
- rt->hash_context = simple_hash(rt->context);
+ rt->context = string_strdupz(value);
}
else if(hash == hash_class && !strcasecmp(key, HEALTH_CLASS_KEY)) {
- alert_cfg->classification = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->classification = string_strdupz(value);
if(rt->classification) {
- if(strcmp(rt->classification, value) != 0)
+ if(strcmp(rrdcalctemplate_classification(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->classification, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_classification(rt), value, value);
- freez(rt->classification);
+ string_freez(rt->classification);
}
- rt->classification = strdupz(value);
- strip_quotes(rt->classification);
+ rt->classification = string_strdupz(value);
}
else if(hash == hash_component && !strcasecmp(key, HEALTH_COMPONENT_KEY)) {
- alert_cfg->component = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->component = string_strdupz(value);
if(rt->component) {
- if(strcmp(rt->component, value) != 0)
+ if(strcmp(rrdcalctemplate_component(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->component, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_component(rt), value, value);
- freez(rt->component);
+ string_freez(rt->component);
}
- rt->component = strdupz(value);
- strip_quotes(rt->component);
+ rt->component = string_strdupz(value);
}
else if(hash == hash_type && !strcasecmp(key, HEALTH_TYPE_KEY)) {
- alert_cfg->type = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->type = string_strdupz(value);
if(rt->type) {
- if(strcmp(rt->type, value) != 0)
+ if(strcmp(rrdcalctemplate_type(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->type, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_type(rt), value, value);
- freez(rt->type);
+ string_freez(rt->type);
}
- rt->type = strdupz(value);
- strip_quotes(rt->type);
+ rt->type = string_strdupz(value);
}
else if(hash == hash_families && !strcasecmp(key, HEALTH_FAMILIES_KEY)) {
- alert_cfg->families = strdupz(value);
- freez(rt->family_match);
+ alert_cfg->families = string_strdupz(value);
+ string_freez(rt->family_match);
simple_pattern_free(rt->family_pattern);
- rt->family_match = strdupz(value);
- rt->family_pattern = simple_pattern_create(rt->family_match, NULL, SIMPLE_PATTERN_EXACT);
+ rt->family_match = string_strdupz(value);
+ rt->family_pattern = simple_pattern_create(rrdcalctemplate_family_match(rt), NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
- alert_cfg->plugin = strdupz(value);
- freez(rt->plugin_match);
+ alert_cfg->plugin = string_strdupz(value);
+ string_freez(rt->plugin_match);
simple_pattern_free(rt->plugin_pattern);
- rt->plugin_match = strdupz(value);
- rt->plugin_pattern = simple_pattern_create(rt->plugin_match, NULL, SIMPLE_PATTERN_EXACT);
+ rt->plugin_match = string_strdupz(value);
+ rt->plugin_pattern = simple_pattern_create(rrdcalctemplate_plugin_match(rt), NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
- alert_cfg->module = strdupz(value);
- freez(rt->module_match);
+ alert_cfg->module = string_strdupz(value);
+ string_freez(rt->module_match);
simple_pattern_free(rt->module_pattern);
- rt->module_match = strdupz(value);
- rt->module_pattern = simple_pattern_create(rt->module_match, NULL, SIMPLE_PATTERN_EXACT);
+ rt->module_match = string_strdupz(value);
+ rt->module_pattern = simple_pattern_create(rrdcalctemplate_module_match(rt), NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_charts && !strcasecmp(key, HEALTH_CHARTS_KEY)) {
- alert_cfg->charts = strdupz(value);
- freez(rt->charts_match);
+ alert_cfg->charts = string_strdupz(value);
+ string_freez(rt->charts_match);
simple_pattern_free(rt->charts_pattern);
- rt->charts_match = strdupz(value);
- rt->charts_pattern = simple_pattern_create(rt->charts_match, NULL, SIMPLE_PATTERN_EXACT);
+ rt->charts_match = string_strdupz(value);
+ rt->charts_pattern = simple_pattern_create(rrdcalctemplate_charts_match(rt), NULL, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
- alert_cfg->lookup = strdupz(value);
+ alert_cfg->lookup = string_strdupz(value);
health_parse_db_lookup(line, filename, value, &rt->group, &rt->after, &rt->before,
- &rt->update_every, &rt->options, &rt->dimensions, &rt->foreachdim);
- if(rt->foreachdim) {
- rt->spdim = health_pattern_from_foreach(rt->foreachdim);
- }
+ &rt->update_every, &rt->options, &rt->dimensions, &rt->foreach_dimension);
+
+ if(rt->foreach_dimension)
+ rt->foreach_dimension_pattern = health_pattern_from_foreach(rrdcalctemplate_foreachdim(rt));
+
if (rt->after) {
if (rt->dimensions)
- alert_cfg->p_db_lookup_dimensions = strdupz(rt->dimensions);
+ alert_cfg->p_db_lookup_dimensions = string_dup(rt->dimensions);
+
if (rt->group)
- alert_cfg->p_db_lookup_method = strdupz(group_method2string(rt->group));
+ alert_cfg->p_db_lookup_method = string_strdupz(group_method2string(rt->group));
+
alert_cfg->p_db_lookup_options = rt->options;
alert_cfg->p_db_lookup_after = rt->after;
alert_cfg->p_db_lookup_before = rt->before;
@@ -1092,137 +990,143 @@ static int health_readfile(const char *filename, void *data) {
}
}
else if(hash == hash_every && !strcasecmp(key, HEALTH_EVERY_KEY)) {
- alert_cfg->every = strdupz(value);
+ alert_cfg->every = string_strdupz(value);
if(!config_parse_duration(value, &rt->update_every))
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' cannot parse duration: '%s'.",
- line, filename, rt->name, key, value);
+ line, filename, rrdcalctemplate_name(rt), key, value);
alert_cfg->p_update_every = rt->update_every;
}
else if(hash == hash_green && !strcasecmp(key, HEALTH_GREEN_KEY)) {
- alert_cfg->green = strdupz(value);
+ alert_cfg->green = string_strdupz(value);
char *e;
rt->green = str2ndd(value, &e);
if(e && *e) {
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
- line, filename, rt->name, key, e);
+ line, filename, rrdcalctemplate_name(rt), key, e);
}
}
else if(hash == hash_red && !strcasecmp(key, HEALTH_RED_KEY)) {
- alert_cfg->red = strdupz(value);
+ alert_cfg->red = string_strdupz(value);
char *e;
rt->red = str2ndd(value, &e);
if(e && *e) {
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' leaves this string unmatched: '%s'.",
- line, filename, rt->name, key, e);
+ line, filename, rrdcalctemplate_name(rt), key, e);
}
}
else if(hash == hash_calc && !strcasecmp(key, HEALTH_CALC_KEY)) {
- alert_cfg->calc = strdupz(value);
+ alert_cfg->calc = string_strdupz(value);
const char *failed_at = NULL;
int error = 0;
rt->calculation = expression_parse(value, &failed_at, &error);
if(!rt->calculation) {
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
- line, filename, rt->name, key, value, expression_strerror(error), failed_at);
+ line, filename, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
}
}
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
- alert_cfg->warn = strdupz(value);
+ alert_cfg->warn = string_strdupz(value);
const char *failed_at = NULL;
int error = 0;
rt->warning = expression_parse(value, &failed_at, &error);
if(!rt->warning) {
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
- line, filename, rt->name, key, value, expression_strerror(error), failed_at);
+ line, filename, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
}
}
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
- alert_cfg->crit = strdupz(value);
+ alert_cfg->crit = string_strdupz(value);
const char *failed_at = NULL;
int error = 0;
rt->critical = expression_parse(value, &failed_at, &error);
if(!rt->critical) {
error("Health configuration at line %zu of file '%s' for template '%s' at key '%s' has unparse-able expression '%s': %s at '%s'",
- line, filename, rt->name, key, value, expression_strerror(error), failed_at);
+ line, filename, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
}
}
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
- alert_cfg->exec = strdupz(value);
+ alert_cfg->exec = string_strdupz(value);
if(rt->exec) {
- if(strcmp(rt->exec, value) != 0)
+ if(strcmp(rrdcalctemplate_exec(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->exec, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_exec(rt), value, value);
- freez(rt->exec);
+ string_freez(rt->exec);
}
- rt->exec = strdupz(value);
+ rt->exec = string_strdupz(value);
}
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
- alert_cfg->to = strdupz(value);
+ alert_cfg->to = string_strdupz(value);
if(rt->recipient) {
- if(strcmp(rt->recipient, value) != 0)
+ if(strcmp(rrdcalctemplate_recipient(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->recipient, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_recipient(rt), value, value);
- freez(rt->recipient);
+ string_freez(rt->recipient);
}
- rt->recipient = strdupz(value);
+ rt->recipient = string_strdupz(value);
}
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
- alert_cfg->units = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->units = string_strdupz(value);
if(rt->units) {
- if(strcmp(rt->units, value) != 0)
+ if(strcmp(rrdcalctemplate_units(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->units, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_units(rt), value, value);
- freez(rt->units);
+ string_freez(rt->units);
}
- rt->units = strdupz(value);
- strip_quotes(rt->units);
+ rt->units = string_strdupz(value);
}
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
- alert_cfg->info = strdupz(value);
+ strip_quotes(value);
+
+ alert_cfg->info = string_strdupz(value);
if(rt->info) {
- if(strcmp(rt->info, value) != 0)
+ if(strcmp(rrdcalctemplate_info(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->info, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_info(rt), value, value);
- freez(rt->info);
+ string_freez(rt->info);
}
- rt->info = strdupz(value);
- strip_quotes(rt->info);
+ rt->info = string_strdupz(value);
}
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
- alert_cfg->delay = strdupz(value);
+ alert_cfg->delay = string_strdupz(value);
health_parse_delay(line, filename, value, &rt->delay_up_duration, &rt->delay_down_duration, &rt->delay_max_duration, &rt->delay_multiplier);
}
else if(hash == hash_options && !strcasecmp(key, HEALTH_OPTIONS_KEY)) {
- alert_cfg->options = strdupz(value);
+ alert_cfg->options = string_strdupz(value);
rt->options |= health_parse_options(value);
}
else if(hash == hash_repeat && !strcasecmp(key, HEALTH_REPEAT_KEY)){
- alert_cfg->repeat = strdupz(value);
+ alert_cfg->repeat = string_strdupz(value);
health_parse_repeat(line, filename, value,
&rt->warn_repeat_every,
&rt->crit_repeat_every);
}
else if(hash == hash_host_label && !strcasecmp(key, HEALTH_HOST_LABEL_KEY)) {
- alert_cfg->host_labels = strdupz(value);
+ alert_cfg->host_labels = string_strdupz(value);
if(rt->host_labels) {
- if(strcmp(rt->host_labels, value) != 0)
+ if(strcmp(rrdcalctemplate_host_labels(rt), value) != 0)
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').",
- line, filename, rt->name, key, rt->host_labels, value, value);
+ line, filename, rrdcalctemplate_name(rt), key, rrdcalctemplate_host_labels(rt), value, value);
- freez(rt->host_labels);
+ string_freez(rt->host_labels);
simple_pattern_free(rt->host_labels_pattern);
}
- rt->host_labels = simple_pattern_trim_around_equal(value);
- rt->host_labels_pattern = simple_pattern_create(rt->host_labels, NULL, SIMPLE_PATTERN_EXACT);
+ {
+ char *tmp = simple_pattern_trim_around_equal(value);
+ rt->host_labels = string_strdupz(tmp);
+ freez(tmp);
+ }
+ rt->host_labels_pattern = simple_pattern_create(rrdcalctemplate_host_labels(rt), NULL, SIMPLE_PATTERN_EXACT);
}
else {
error("Health configuration at line %zu of file '%s' for template '%s' has unknown key '%s'.",
- line, filename, rt->name, key);
+ line, filename, rrdcalctemplate_name(rt), key);
}
}
else {
@@ -1233,15 +1137,17 @@ static int health_readfile(const char *filename, void *data) {
if(rc) {
//health_add_alarms_loop(host, rc, ignore_this) ;
- if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalc_add_alarm_from_config(host, rc)) {
- rrdcalc_free(rc);
- }
+ if(!alert_hash_and_store_config(rc->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this)
+ rrdcalc_free_unused_rrdcalc_loaded_from_config(rc);
+ else
+ rrdcalc_add_from_config(host, rc);
}
if(rt) {
- if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this || !rrdcalctemplate_add_template_from_config(host, rt)) {
- rrdcalctemplate_free(rt);
- }
+ if(!alert_hash_and_store_config(rt->config_hash_id, alert_cfg, sql_store_hashes) || ignore_this)
+ rrdcalctemplate_free_unused_rrdcalctemplate_loaded_from_config(rt);
+ else
+ rrdcalctemplate_add_from_config(host, rt);
}
if (alert_cfg)
@@ -1257,8 +1163,8 @@ void sql_refresh_hashes(void)
}
void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path, const char *subpath) {
- if(unlikely(!host->health_enabled)) {
- debug(D_HEALTH, "CONFIG health is not enabled for host '%s'", host->hostname);
+ if(unlikely(!host->health_enabled) && !rrdhost_flag_check(host, RRDHOST_FLAG_INITIALIZED_HEALTH)) {
+ debug(D_HEALTH, "CONFIG health is not enabled for host '%s'", rrdhost_hostname(host));
return;
}
@@ -1266,10 +1172,11 @@ void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path
CONFIG_BOOLEAN_YES);
if (!stock_enabled) {
- info("Netdata will not load stock alarms.");
+ log_health("[%s]: Netdata will not load stock alarms.", rrdhost_hostname(host));
stock_path = user_path;
}
recursive_config_double_dir_load(user_path, stock_path, subpath, health_readfile, (void *) host, 0);
+ log_health("[%s]: Read health configuration.", rrdhost_hostname(host));
sql_store_hashes = 0;
}