diff options
-rw-r--r-- | daemon/config/README.md | 1 | ||||
-rw-r--r-- | health/health.c | 4 | ||||
-rw-r--r-- | health/health.h | 1 | ||||
-rw-r--r-- | health/health_config.c | 102 |
4 files changed, 60 insertions, 48 deletions
diff --git a/daemon/config/README.md b/daemon/config/README.md index 7b4d27ecff..376aae0a5f 100644 --- a/daemon/config/README.md +++ b/daemon/config/README.md @@ -175,6 +175,7 @@ monitoring](/health/README.md). | run at least every seconds | `10` | Controls how often all alarm conditions should be evaluated. | | postpone alarms during hibernation for seconds | `60` | Prevents false alarms. May need to be increased if you get alarms during hibernation. | | rotate log every lines | 2000 | Controls the number of alarm log entries stored in `<lib directory>/health-log.db`, where `<lib directory>` is the one configured in the [\[global\] section](#global-section-options) | +| enabled alarms | * | Defines which alarms to load from both user and stock directories. This is a [simple pattern](/libnetdata/simple_pattern/README.md) list of alarm or template names. Can be used to disable specific alarms. For example, `enabled alarms = !oom_kill *` will load all alarms except `oom_kill`. | ### [web] section options 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; |