diff options
Diffstat (limited to '')
-rw-r--r-- | health/health.c (renamed from src/health.c) | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/src/health.c b/health/health.c index 04e04f08..ae0c464b 100644 --- a/src/health.c +++ b/health/health.c @@ -1,21 +1,28 @@ -#define NETDATA_HEALTH_INTERNALS -#include "common.h" +// SPDX-License-Identifier: GPL-3.0-or-later -int default_health_enabled = 1; +#include "health.h" + +unsigned int default_health_enabled = 1; // ---------------------------------------------------------------------------- // health initialization -inline char *health_config_dir(void) { +inline char *health_user_config_dir(void) { char buffer[FILENAME_MAX + 1]; - snprintfz(buffer, FILENAME_MAX, "%s/health.d", netdata_configured_config_dir); + snprintfz(buffer, FILENAME_MAX, "%s/health.d", netdata_configured_user_config_dir); return config_get(CONFIG_SECTION_HEALTH, "health configuration directory", buffer); } +inline char *health_stock_config_dir(void) { + char buffer[FILENAME_MAX + 1]; + snprintfz(buffer, FILENAME_MAX, "%s/health.d", netdata_configured_stock_config_dir); + return config_get(CONFIG_SECTION_HEALTH, "stock health configuration directory", buffer); +} + void health_init(void) { debug(D_HEALTH, "Health configuration initializing"); - if(!(default_health_enabled = config_get_boolean(CONFIG_SECTION_HEALTH, "enabled", 1))) { + if(!(default_health_enabled = (unsigned int)config_get_boolean(CONFIG_SECTION_HEALTH, "enabled", default_health_enabled))) { debug(D_HEALTH, "Health is disabled."); return; } @@ -28,7 +35,8 @@ void health_reload_host(RRDHOST *host) { if(unlikely(!host->health_enabled)) return; - char *path = health_config_dir(); + char *user_path = health_user_config_dir(); + char *stock_path = health_stock_config_dir(); // free all running alarms rrdhost_wrlock(host); @@ -59,7 +67,7 @@ void health_reload_host(RRDHOST *host) { // load the new alarms rrdhost_wrlock(host); - health_readdir(host, path); + health_readdir(host, user_path, stock_path, NULL); // link the loaded alarms to their charts rrdset_foreach_write(st, host) { @@ -178,9 +186,9 @@ static inline void health_alarm_execute(RRDHOST *host, ALARM_ENTRY *ae) { error("HEALTH: Cannot popen(\"%s\", \"r\").", command_to_run); goto done; } - debug(D_HEALTH, "HEALTH reading from command"); - char *s = fgets(command_to_run, FILENAME_MAX, fp); - (void)s; + debug(D_HEALTH, "HEALTH reading from command (discarding command's output)"); + char buffer[100 + 1]; + while(fgets(buffer, 100, fp) != NULL) ; ae->exec_code = mypclose(fp, command_pid); debug(D_HEALTH, "done executing command - returned with code %d", ae->exec_code); @@ -521,6 +529,11 @@ void *health_main(void *ptr) { ); rc->value = rc->calculation->result; + + if(rc->local) rc->local->last_updated = now; + if(rc->family) rc->family->last_updated = now; + if(rc->hostid) rc->hostid->last_updated = now; + if(rc->hostname) rc->hostname->last_updated = now; } } } |