summaryrefslogtreecommitdiffstats
path: root/health
diff options
context:
space:
mode:
authorEmmanuel Vasilakis <mrzammler@mm.st>2022-12-19 13:52:37 +0200
committerGitHub <noreply@github.com>2022-12-19 13:52:37 +0200
commite6c04cb4de6387c7ba1dbf80076ca4bd7578237b (patch)
tree31feca5e2dd311c2194b35c3f0275cf00995487f /health
parentccfda8fa501f8e77e5b7036dd0ed71fef4e8c2a4 (diff)
Add a health configuration option of what alarms to load (#14150)
* use a simple pattern to choose what alerts to load * rename config to alarms * add config entry doc * fix link * change wording * change wording 2 * add to analytics * build a list of disabled alarms for analytics * add silenced alarms * remove analytics related * remove analytics related 2
Diffstat (limited to 'health')
-rw-r--r--health/health.c4
-rw-r--r--health/health.h1
-rw-r--r--health/health_config.c102
3 files changed, 59 insertions, 48 deletions
diff --git a/health/health.c b/health/health.c
index 096eedec4a..03cfd51447 100644
--- a/health/health.c
+++ b/health/health.c
@@ -159,6 +159,7 @@ static bool prepare_command(BUFFER *wb,
unsigned int default_health_enabled = 1;
char *silencers_filename;
+SIMPLE_PATTERN *conf_enabled_alarms = NULL;
// the queue of executed alarm notifications that haven't been waited for yet
static __thread struct {
@@ -769,6 +770,8 @@ static void initialize_health(RRDHOST *host, int is_localhost) {
else
host->health_log.max = (unsigned int)n;
+ conf_enabled_alarms = simple_pattern_create(config_get(CONFIG_SECTION_HEALTH, "enabled alarms", "*"), NULL, SIMPLE_PATTERN_EXACT);
+
netdata_rwlock_init(&host->health_log.alarm_log_rwlock);
char filename[FILENAME_MAX + 1];
@@ -1553,7 +1556,6 @@ void *health_main(void *ptr) {
void health_add_host_labels(void) {
DICTIONARY *labels = localhost->rrdlabels;
- enum rrdlabel_source src;
// The source should be CONF, but when it is set, these labels are exported by default ('send configured labels' in exporting.conf).
// Their export seems to break exporting to Graphite, see https://github.com/netdata/netdata/issues/14084.
diff --git a/health/health.h b/health/health.h
index 15d8326ee8..8e5191bec8 100644
--- a/health/health.h
+++ b/health/health.h
@@ -31,6 +31,7 @@ extern unsigned int default_health_enabled;
#define HEALTH_SILENCERS_MAX_FILE_LEN 10000
extern char *silencers_filename;
+extern SIMPLE_PATTERN *conf_enabled_alarms;
void health_init(void);
diff --git a/health/health_config.c b/health/health_config.c
index f9decfad58..24fca624cc 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -553,33 +553,37 @@ static int health_readfile(const char *filename, void *data) {
rt = NULL;
}
- rc = callocz(1, sizeof(RRDCALC));
- rc->next_event_id = 1;
-
- {
- 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;
- rc->value = NAN;
- rc->old_value = NAN;
- rc->delay_multiplier = 1.0;
- rc->old_status = RRDCALC_STATUS_UNINITIALIZED;
- rc->warn_repeat_every = host->health_default_warn_repeat_every;
- rc->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));
-
- alert_cfg->alarm = string_dup(rc->name);
- ignore_this = 0;
+ if (simple_pattern_matches(conf_enabled_alarms, value)) {
+ rc = callocz(1, sizeof(RRDCALC));
+ rc->next_event_id = 1;
+
+ {
+ 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;
+ rc->value = NAN;
+ rc->old_value = NAN;
+ rc->delay_multiplier = 1.0;
+ rc->old_status = RRDCALC_STATUS_UNINITIALIZED;
+ rc->warn_repeat_every = host->health_default_warn_repeat_every;
+ rc->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));
+
+ alert_cfg->alarm = string_dup(rc->name);
+ ignore_this = 0;
+ } else {
+ rc = NULL;
+ }
}
else if(hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) {
if(rc) {
@@ -599,29 +603,33 @@ static int health_readfile(const char *filename, void *data) {
rrdcalctemplate_add_from_config(host, rt);
}
- rt = callocz(1, sizeof(RRDCALCTEMPLATE));
+ if (simple_pattern_matches(conf_enabled_alarms, value)) {
+ rt = callocz(1, sizeof(RRDCALCTEMPLATE));
- {
- 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);
- }
+ {
+ char *tmp = strdupz(value);
+ if(rrdvar_fix_name(tmp))
+ error("Health configuration renamed template '%s' to '%s'", value, tmp);
- rt->source = health_source_file(line, filename);
- rt->green = NAN;
- rt->red = NAN;
- 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));
+ rt->name = string_strdupz(tmp);
+ freez(tmp);
+ }
- alert_cfg->template_key = string_dup(rt->name);
- ignore_this = 0;
+ rt->source = health_source_file(line, filename);
+ rt->green = NAN;
+ rt->red = NAN;
+ 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));
+
+ alert_cfg->template_key = string_dup(rt->name);
+ ignore_this = 0;
+ } else {
+ rt = NULL;
+ }
}
else if(hash == hash_os && !strcasecmp(key, HEALTH_OS_KEY)) {
char *os_match = value;