summaryrefslogtreecommitdiffstats
path: root/health/health_config.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-05-08 16:27:04 +0000
commita836a244a3d2bdd4da1ee2641e3e957850668cea (patch)
treecb87c75b3677fab7144f868435243f864048a1e6 /health/health_config.c
parentAdding upstream version 1.38.1. (diff)
downloadnetdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.tar.xz
netdata-a836a244a3d2bdd4da1ee2641e3e957850668cea.zip
Adding upstream version 1.39.0.upstream/1.39.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'health/health_config.c')
-rw-r--r--health/health_config.c94
1 files changed, 77 insertions, 17 deletions
diff --git a/health/health_config.c b/health/health_config.c
index 55d5e10eb..38857fc9a 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -185,6 +185,51 @@ static inline int health_parse_repeat(
return 1;
}
+static inline int isvariableterm(const char s) {
+ if(isalnum(s) || s == '.' || s == '_')
+ return 0;
+
+ return 1;
+}
+
+static inline void parse_variables_and_store_in_health_rrdvars(char *value, size_t len) {
+ const char *s = value;
+ char buffer[RRDVAR_MAX_LENGTH];
+
+ // $
+ while (*s) {
+ if(*s == '$') {
+ size_t i = 0;
+ s++;
+
+ if(*s == '{') {
+ // ${variable_name}
+
+ s++;
+ while (*s && *s != '}' && i < len)
+ buffer[i++] = *s++;
+
+ if(*s == '}')
+ s++;
+ }
+ else {
+ // $variable_name
+
+ while (*s && !isvariableterm(*s) && i < len)
+ buffer[i++] = *s++;
+ }
+
+ buffer[i] = '\0';
+
+ //TODO: check and try to store only variables
+ STRING *name_string = rrdvar_name_to_string(buffer);
+ rrdvar_add("health", health_rrdvars, name_string, RRDVAR_TYPE_CALCULATED, RRDVAR_FLAG_CONFIG_VAR, NULL);
+ string_freez(name_string);
+ } else
+ s++;
+ }
+}
+
/**
* Health pattern from Foreach
*
@@ -206,7 +251,7 @@ static SIMPLE_PATTERN *health_pattern_from_foreach(const char *s) {
if(convert) {
dimension_remove_pipe_comma(convert);
- val = simple_pattern_create(convert, NULL, SIMPLE_PATTERN_EXACT);
+ val = simple_pattern_create(convert, NULL, SIMPLE_PATTERN_EXACT, true);
freez(convert);
}
@@ -215,7 +260,7 @@ static SIMPLE_PATTERN *health_pattern_from_foreach(const 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,
+ RRDR_TIME_GROUPING *group_method, int *after, int *before, int *every,
RRDCALC_OPTIONS *options, STRING **dimensions, STRING **foreachdim
) {
debug(D_HEALTH, "Health configuration parsing database lookup %zu@%s: %s", line, filename, string);
@@ -241,7 +286,7 @@ static inline int health_parse_db_lookup(
return 0;
}
- if((*group_method = web_client_api_request_v1_data_group(key, RRDR_GROUPING_UNDEFINED)) == RRDR_GROUPING_UNDEFINED) {
+ if((*group_method = time_grouping_parse(key, RRDR_GROUPING_UNDEFINED)) == RRDR_GROUPING_UNDEFINED) {
error("Health configuration at line %zu of file '%s': invalid group method '%s'",
line, filename, key);
return 0;
@@ -634,9 +679,9 @@ static int health_readfile(const char *filename, void *data) {
else if(hash == hash_os && !strcasecmp(key, HEALTH_OS_KEY)) {
char *os_match = value;
if (alert_cfg) alert_cfg->os = string_strdupz(value);
- SIMPLE_PATTERN *os_pattern = simple_pattern_create(os_match, NULL, SIMPLE_PATTERN_EXACT);
+ SIMPLE_PATTERN *os_pattern = simple_pattern_create(os_match, NULL, SIMPLE_PATTERN_EXACT, true);
- if(!simple_pattern_matches(os_pattern, rrdhost_os(host))) {
+ if(!simple_pattern_matches_string(os_pattern, host->os)) {
if(rc)
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);
@@ -651,9 +696,9 @@ 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 = string_strdupz(value);
- SIMPLE_PATTERN *host_pattern = simple_pattern_create(host_match, NULL, SIMPLE_PATTERN_EXACT);
+ SIMPLE_PATTERN *host_pattern = simple_pattern_create(host_match, NULL, SIMPLE_PATTERN_EXACT, true);
- if(!simple_pattern_matches(host_pattern, rrdhost_hostname(host))) {
+ if(!simple_pattern_matches_string(host_pattern, host->hostname)) {
if(rc)
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);
@@ -728,7 +773,7 @@ static int health_readfile(const char *filename, void *data) {
if (rc->dimensions)
alert_cfg->p_db_lookup_dimensions = string_dup(rc->dimensions);
if (rc->group)
- alert_cfg->p_db_lookup_method = string_strdupz(group_method2string(rc->group));
+ alert_cfg->p_db_lookup_method = string_strdupz(time_grouping_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;
@@ -769,6 +814,7 @@ static int health_readfile(const char *filename, void *data) {
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, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
}
+ parse_variables_and_store_in_health_rrdvars(value, HEALTH_CONF_MAX_LINE);
}
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
alert_cfg->warn = string_strdupz(value);
@@ -779,6 +825,7 @@ static int health_readfile(const char *filename, void *data) {
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, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
}
+ parse_variables_and_store_in_health_rrdvars(value, HEALTH_CONF_MAX_LINE);
}
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
alert_cfg->crit = string_strdupz(value);
@@ -789,6 +836,7 @@ static int health_readfile(const char *filename, void *data) {
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, rrdcalc_name(rc), key, value, expression_strerror(error), failed_at);
}
+ parse_variables_and_store_in_health_rrdvars(value, HEALTH_CONF_MAX_LINE);
}
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
alert_cfg->exec = string_strdupz(value);
@@ -870,7 +918,8 @@ static int health_readfile(const char *filename, void *data) {
rc->host_labels = string_strdupz(tmp);
freez(tmp);
}
- rc->host_labels_pattern = simple_pattern_create(rrdcalc_host_labels(rc), NULL, SIMPLE_PATTERN_EXACT);
+ rc->host_labels_pattern = simple_pattern_create(rrdcalc_host_labels(rc), NULL, SIMPLE_PATTERN_EXACT,
+ true);
}
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
alert_cfg->plugin = string_strdupz(value);
@@ -878,7 +927,7 @@ static int health_readfile(const char *filename, void *data) {
simple_pattern_free(rc->plugin_pattern);
rc->plugin_match = string_strdupz(value);
- rc->plugin_pattern = simple_pattern_create(rrdcalc_plugin_match(rc), NULL, SIMPLE_PATTERN_EXACT);
+ rc->plugin_pattern = simple_pattern_create(rrdcalc_plugin_match(rc), NULL, SIMPLE_PATTERN_EXACT, true);
}
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
alert_cfg->module = string_strdupz(value);
@@ -886,7 +935,7 @@ static int health_readfile(const char *filename, void *data) {
simple_pattern_free(rc->module_pattern);
rc->module_match = string_strdupz(value);
- rc->module_pattern = simple_pattern_create(rrdcalc_module_match(rc), NULL, SIMPLE_PATTERN_EXACT);
+ rc->module_pattern = simple_pattern_create(rrdcalc_module_match(rc), NULL, SIMPLE_PATTERN_EXACT, true);
}
else {
error("Health configuration at line %zu of file '%s' for alarm '%s' has unknown key '%s'.",
@@ -950,7 +999,8 @@ static int health_readfile(const char *filename, void *data) {
simple_pattern_free(rt->family_pattern);
rt->family_match = string_strdupz(value);
- rt->family_pattern = simple_pattern_create(rrdcalctemplate_family_match(rt), NULL, SIMPLE_PATTERN_EXACT);
+ rt->family_pattern = simple_pattern_create(rrdcalctemplate_family_match(rt), NULL, SIMPLE_PATTERN_EXACT,
+ true);
}
else if(hash == hash_plugin && !strcasecmp(key, HEALTH_PLUGIN_KEY)) {
alert_cfg->plugin = string_strdupz(value);
@@ -958,7 +1008,8 @@ static int health_readfile(const char *filename, void *data) {
simple_pattern_free(rt->plugin_pattern);
rt->plugin_match = string_strdupz(value);
- rt->plugin_pattern = simple_pattern_create(rrdcalctemplate_plugin_match(rt), NULL, SIMPLE_PATTERN_EXACT);
+ rt->plugin_pattern = simple_pattern_create(rrdcalctemplate_plugin_match(rt), NULL, SIMPLE_PATTERN_EXACT,
+ true);
}
else if(hash == hash_module && !strcasecmp(key, HEALTH_MODULE_KEY)) {
alert_cfg->module = string_strdupz(value);
@@ -966,7 +1017,8 @@ static int health_readfile(const char *filename, void *data) {
simple_pattern_free(rt->module_pattern);
rt->module_match = string_strdupz(value);
- rt->module_pattern = simple_pattern_create(rrdcalctemplate_module_match(rt), NULL, SIMPLE_PATTERN_EXACT);
+ rt->module_pattern = simple_pattern_create(rrdcalctemplate_module_match(rt), NULL, SIMPLE_PATTERN_EXACT,
+ true);
}
else if(hash == hash_charts && !strcasecmp(key, HEALTH_CHARTS_KEY)) {
alert_cfg->charts = string_strdupz(value);
@@ -974,7 +1026,8 @@ static int health_readfile(const char *filename, void *data) {
simple_pattern_free(rt->charts_pattern);
rt->charts_match = string_strdupz(value);
- rt->charts_pattern = simple_pattern_create(rrdcalctemplate_charts_match(rt), NULL, SIMPLE_PATTERN_EXACT);
+ rt->charts_pattern = simple_pattern_create(rrdcalctemplate_charts_match(rt), NULL, SIMPLE_PATTERN_EXACT,
+ true);
}
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
alert_cfg->lookup = string_strdupz(value);
@@ -989,7 +1042,7 @@ static int health_readfile(const char *filename, void *data) {
alert_cfg->p_db_lookup_dimensions = string_dup(rt->dimensions);
if (rt->group)
- alert_cfg->p_db_lookup_method = string_strdupz(group_method2string(rt->group));
+ alert_cfg->p_db_lookup_method = string_strdupz(time_grouping_method2string(rt->group));
alert_cfg->p_db_lookup_options = rt->options;
alert_cfg->p_db_lookup_after = rt->after;
@@ -1031,6 +1084,7 @@ static int health_readfile(const char *filename, void *data) {
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, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
}
+ parse_variables_and_store_in_health_rrdvars(value, HEALTH_CONF_MAX_LINE);
}
else if(hash == hash_warn && !strcasecmp(key, HEALTH_WARN_KEY)) {
alert_cfg->warn = string_strdupz(value);
@@ -1041,6 +1095,7 @@ static int health_readfile(const char *filename, void *data) {
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, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
}
+ parse_variables_and_store_in_health_rrdvars(value, HEALTH_CONF_MAX_LINE);
}
else if(hash == hash_crit && !strcasecmp(key, HEALTH_CRIT_KEY)) {
alert_cfg->crit = string_strdupz(value);
@@ -1051,6 +1106,7 @@ static int health_readfile(const char *filename, void *data) {
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, rrdcalctemplate_name(rt), key, value, expression_strerror(error), failed_at);
}
+ parse_variables_and_store_in_health_rrdvars(value, HEALTH_CONF_MAX_LINE);
}
else if(hash == hash_exec && !strcasecmp(key, HEALTH_EXEC_KEY)) {
alert_cfg->exec = string_strdupz(value);
@@ -1130,7 +1186,8 @@ static int health_readfile(const char *filename, void *data) {
rt->host_labels = string_strdupz(tmp);
freez(tmp);
}
- rt->host_labels_pattern = simple_pattern_create(rrdcalctemplate_host_labels(rt), NULL, SIMPLE_PATTERN_EXACT);
+ rt->host_labels_pattern = simple_pattern_create(rrdcalctemplate_host_labels(rt), NULL,
+ SIMPLE_PATTERN_EXACT, true);
}
else {
error("Health configuration at line %zu of file '%s' for template '%s' has unknown key '%s'.",
@@ -1185,6 +1242,9 @@ void health_readdir(RRDHOST *host, const char *user_path, const char *stock_path
stock_path = user_path;
}
+ if (!health_rrdvars)
+ health_rrdvars = health_rrdvariables_create();
+
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;