summaryrefslogtreecommitdiffstats
path: root/health/health_config.c
diff options
context:
space:
mode:
authorAndrew Moss <1043609+amoss@users.noreply.github.com>2019-12-16 15:12:00 +0100
committerGitHub <noreply@github.com>2019-12-16 15:12:00 +0100
commitc8c72f18a6a8fd09d3b6284e49525396b24e8395 (patch)
tree5b9aeaea7d72e1d1029d45f67c0a5f130ecc2f80 /health/health_config.c
parentc4bb3d2642ab34e6aca912b22e55aed52f84e974 (diff)
Labels issues (#7515)
Initial work on host labels from the dedicated branch. Includes work for issues #7096, #7400, #7411, #7369, #7410, #7458, #7459, #7412 and #7408 by @vlvkobal, @thiagoftsm, @cakrit and @amoss.
Diffstat (limited to 'health/health_config.c')
-rw-r--r--health/health_config.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/health/health_config.c b/health/health_config.c
index 65c6d8bd7f..1323f17f7d 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -24,6 +24,7 @@
#define HEALTH_DELAY_KEY "delay"
#define HEALTH_OPTIONS_KEY "options"
#define HEALTH_REPEAT_KEY "repeat"
+#define HEALTH_LABEL_KEY "label"
static inline int rrdcalc_add_alarm_from_config(RRDHOST *host, RRDCALC *rc) {
if(!rc->chart) {
@@ -497,7 +498,8 @@ static int health_readfile(const char *filename, void *data) {
hash_recipient = 0,
hash_delay = 0,
hash_options = 0,
- hash_repeat = 0;
+ hash_repeat = 0,
+ hash_label = 0;
char buffer[HEALTH_CONF_MAX_LINE + 1];
@@ -522,6 +524,7 @@ static int health_readfile(const char *filename, void *data) {
hash_delay = simple_uhash(HEALTH_DELAY_KEY);
hash_options = simple_uhash(HEALTH_OPTIONS_KEY);
hash_repeat = simple_uhash(HEALTH_REPEAT_KEY);
+ hash_label = simple_uhash(HEALTH_LABEL_KEY);
}
FILE *fp = fopen(filename, "r");
@@ -795,6 +798,19 @@ static int health_readfile(const char *filename, void *data) {
&rc->warn_repeat_every,
&rc->crit_repeat_every);
}
+ else if(hash == hash_label && !strcasecmp(key, HEALTH_LABEL_KEY)) {
+ if(rc->labels) {
+ if(strcmp(rc->labels, 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);
+
+ freez(rc->labels);
+ simple_pattern_free(rc->splabels);
+ }
+
+ rc->labels = simple_pattern_trim_around_equal(value);
+ rc->splabels = simple_pattern_create(rc->labels, 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);
@@ -927,6 +943,19 @@ static int health_readfile(const char *filename, void *data) {
&rt->warn_repeat_every,
&rt->crit_repeat_every);
}
+ else if(hash == hash_label && !strcasecmp(key, HEALTH_LABEL_KEY)) {
+ if(rt->labels) {
+ if(strcmp(rt->labels, 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->labels, value, value);
+
+ freez(rt->labels);
+ simple_pattern_free(rt->splabels);
+ }
+
+ rt->labels = simple_pattern_trim_around_equal(value);
+ rt->splabels = simple_pattern_create(rt->labels, 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);