summaryrefslogtreecommitdiffstats
path: root/health
diff options
context:
space:
mode:
authorPavlos Emm. Katsoulakis <paul@netdata.rocks>2019-06-28 08:27:57 +0200
committerPavlos Emm. Katsoulakis <paul@netdata.rocks>2019-06-28 08:27:57 +0200
commit171d8f5d01f17dddbd531139b86e1a1c96f95b0d (patch)
tree7b2f049259656e4c14c3d7e23a639964ebb2e07b /health
parent5d5266dc1a863d877d91cab232b6369091a198ee (diff)
Revert "Easily disable alarms, by persisting the silencers configuration (#6274)"
This reverts commit 60a73e90de2aa1c2eaae2ebbc45dd1fb96034df2. Emergency rollback of potential culprit as per issue #6356 Will be re-merging the change after investigation
Diffstat (limited to 'health')
-rw-r--r--health/health.c101
-rw-r--r--health/health.h44
-rw-r--r--health/health_config.c2
3 files changed, 46 insertions, 101 deletions
diff --git a/health/health.c b/health/health.c
index 55d44e955d..f92a1ba6b0 100644
--- a/health/health.c
+++ b/health/health.c
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
-#include <libnetdata/json/json.h>
#include "health.h"
struct health_cmdapi_thread_status {
@@ -14,79 +13,18 @@ unsigned int default_health_enabled = 1;
// ----------------------------------------------------------------------------
// health initialization
-/**
- * User Config directory
- *
- * Get the config directory for health and return it.
- *
- * @return a pointer to the user config directory
- */
inline char *health_user_config_dir(void) {
char buffer[FILENAME_MAX + 1];
snprintfz(buffer, FILENAME_MAX, "%s/health.d", netdata_configured_user_config_dir);
return config_get(CONFIG_SECTION_HEALTH, "health configuration directory", buffer);
}
-/**
- * Stock Config Directory
- *
- * Get the Stock config directory and return it.
- *
- * @return a pointer to the stock config directory.
- */
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);
}
-
-/**
- * Silencers init
- *
- * Function used to initialize the silencer structure.
- */
-void health_silencers_init(void) {
- silencers = mallocz(sizeof(SILENCERS));
- silencers->all_alarms=0;
- silencers->stype=STYPE_NONE;
- silencers->silencers=NULL;
-
- char filename[FILENAME_MAX + 1];
- snprintfz(filename, FILENAME_MAX, "%s/health.silencers.json", netdata_configured_varlib_dir);
- silencers_filename = config_get(CONFIG_SECTION_HEALTH, "silencers file", filename);
-
- struct stat statbuf;
- if (!stat(silencers_filename,&statbuf)) {
- off_t length = statbuf.st_size;
- if (length && length < HEALTH_SILENCERS_MAX_FILE_LEN) {
- FILE *fd = fopen(silencers_filename, "r");
- if (fd) {
- char *str = mallocz((length+1)* sizeof(char));
- if(str) {
- fread(str, sizeof(char), length, fd);
- str[length] = 0x00;
- json_parse(str, NULL, health_silencers_json_read_callback);
- freez(str);
- info("Parsed health silencers file %s", silencers_filename);
- }
- fclose(fd);
- } else {
- error("Cannot open the file %s",silencers_filename);
- }
- } else {
- error("Health silencers file %s has the size %ld that is out of range[ 1 , %d ]. Aborting read.", silencers_filename, length, HEALTH_SILENCERS_MAX_FILE_LEN);
- }
- } else {
- error("Cannot open the file %s",silencers_filename);
- }
-}
-
-/**
- * Health Init
- *
- * Initialize the health thread.
- */
void health_init(void) {
debug(D_HEALTH, "Health configuration initializing");
@@ -94,20 +32,11 @@ void health_init(void) {
debug(D_HEALTH, "Health is disabled.");
return;
}
-
- health_silencers_init();
}
// ----------------------------------------------------------------------------
// re-load health configuration
-/**
- * Reload host
- *
- * Reload configuration for a specific host.
- *
- * @param host the structure of the host that the function will reload the configuration.
- */
void health_reload_host(RRDHOST *host) {
if(unlikely(!host->health_enabled))
return;
@@ -155,11 +84,6 @@ void health_reload_host(RRDHOST *host) {
rrdhost_unlock(host);
}
-/**
- * Reload
- *
- * Reload the host configuration for all hosts.
- */
void health_reload(void) {
rrd_rdlock();
@@ -501,16 +425,6 @@ SILENCE_TYPE check_silenced(RRDCALC *rc, char* host, SILENCERS *silencers) {
return STYPE_NONE;
}
-/**
- * Update Disabled Silenced
- *
- * Update the variable rrdcalc_flags of the structure RRDCALC according with the values of the host structure
- *
- * @param host structure that contains information about the host monitored.
- * @param rc structure with information about the alarm
- *
- * @return It returns 1 case rrdcalc_flags is DISABLED or 0 otherwise
- */
int update_disabled_silenced(RRDHOST *host, RRDCALC *rc) {
uint32_t rrdcalc_flags_old = rc->rrdcalc_flags;
// Clear the flags
@@ -540,15 +454,6 @@ int update_disabled_silenced(RRDHOST *host, RRDCALC *rc) {
return 0;
}
-/**
- * Health Main
- *
- * The main thread of the health system. In this function all the alarms will be processed.
- *
- * @param ptr is a pointer to the netdata_static_thread structure.
- *
- * @return It always returns NULL
- */
void *health_main(void *ptr) {
netdata_thread_cleanup_push(health_main_cleanup, ptr);
@@ -560,6 +465,11 @@ void *health_main(void *ptr) {
unsigned int loop = 0;
+ silencers = mallocz(sizeof(SILENCERS));
+ silencers->all_alarms=0;
+ silencers->stype=STYPE_NONE;
+ silencers->silencers=NULL;
+
while(!netdata_exit) {
loop++;
debug(D_HEALTH, "Health monitoring iteration no %u started", loop);
@@ -613,7 +523,6 @@ void *health_main(void *ptr) {
// the first loop is to lookup values from the db
for (rc = host->alarms; rc; rc = rc->next) {
- //case it is disabled I will get the next rc
if (update_disabled_silenced(host, rc))
continue;
diff --git a/health/health.h b/health/health.h
index acbcf827c2..1511f36486 100644
--- a/health/health.h
+++ b/health/health.h
@@ -35,9 +35,16 @@ extern unsigned int default_health_enabled;
#define HEALTH_LISTEN_BACKLOG 4096
#endif
-
+#define HEALTH_ALARM_KEY "alarm"
+#define HEALTH_TEMPLATE_KEY "template"
#define HEALTH_ON_KEY "on"
-
+#define HEALTH_CONTEXT_KEY "context"
+#define HEALTH_CHART_KEY "chart"
+#define HEALTH_HOST_KEY "hosts"
+#define HEALTH_OS_KEY "os"
+#define HEALTH_FAMILIES_KEY "families"
+#define HEALTH_LOOKUP_KEY "lookup"
+#define HEALTH_CALC_KEY "calc"
#define HEALTH_EVERY_KEY "every"
#define HEALTH_GREEN_KEY "green"
#define HEALTH_RED_KEY "red"
@@ -50,9 +57,38 @@ extern unsigned int default_health_enabled;
#define HEALTH_DELAY_KEY "delay"
#define HEALTH_OPTIONS_KEY "options"
-#define HEALTH_SILENCERS_MAX_FILE_LEN 10000
+typedef struct silencer {
+ char *alarms;
+ SIMPLE_PATTERN *alarms_pattern;
+
+ char *hosts;
+ SIMPLE_PATTERN *hosts_pattern;
+
+ char *contexts;
+ SIMPLE_PATTERN *contexts_pattern;
+
+ char *charts;
+ SIMPLE_PATTERN *charts_pattern;
+
+ char *families;
+ SIMPLE_PATTERN *families_pattern;
+
+ struct silencer *next;
+} SILENCER;
+
+typedef enum silence_type {
+ STYPE_NONE,
+ STYPE_DISABLE_ALARMS,
+ STYPE_SILENCE_NOTIFICATIONS
+} SILENCE_TYPE;
+
+typedef struct silencers {
+ int all_alarms;
+ SILENCE_TYPE stype;
+ SILENCER *silencers;
+} SILENCERS;
-char *silencers_filename;
+SILENCERS *silencers;
extern void health_init(void);
extern void *health_main(void *ptr);
diff --git a/health/health_config.c b/health/health_config.c
index 54d11b6a1c..35fde90bc2 100644
--- a/health/health_config.c
+++ b/health/health_config.c
@@ -481,7 +481,7 @@ static int health_readfile(const char *filename, void *data) {
if(append < HEALTH_CONF_MAX_LINE)
continue;
else {
- error("Health configuration has too long multi-line at line %zu of file '%s'.", line, filename);
+ error("Health configuration has too long muli-line at line %zu of file '%s'.", line, filename);
}
}
append = 0;