// SPDX-License-Identifier: GPL-3.0-or-later
#include "health.h"
unsigned int default_health_enabled = 1;
char *silencers_filename;
// the queue of executed alarm notifications that haven't been waited for yet
static struct {
ALARM_ENTRY *head; // oldest
ALARM_ENTRY *tail; // latest
} alarm_notifications_in_progress = {NULL, NULL};
static inline void enqueue_alarm_notify_in_progress(ALARM_ENTRY *ae)
{
ae->prev_in_progress = NULL;
ae->next_in_progress = NULL;
if (NULL != alarm_notifications_in_progress.tail) {
ae->prev_in_progress = alarm_notifications_in_progress.tail;
alarm_notifications_in_progress.tail->next_in_progress = ae;
}
if (NULL == alarm_notifications_in_progress.head) {
alarm_notifications_in_progress.head = ae;
}
alarm_notifications_in_progress.tail = ae;
}
static inline void unlink_alarm_notify_in_progress(ALARM_ENTRY *ae)
{
struct alarm_entry *prev = ae->prev_in_progress;
struct alarm_entry *next = ae->next_in_progress;
if (NULL != prev) {
prev->next_in_progress = next;
}
if (NULL != next) {
next->prev_in_progress = prev;
}
if (ae == alarm_notifications_in_progress.head) {
alarm_notifications_in_progress.head = next;
}
if (ae == alarm_notifications_in_progress.tail) {
alarm_notifications_in_progress.tail = prev;
}
}
// ----------------------------------------------------------------------------
// 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.
*/
static void health_silencers_init(void) {
FILE *fd = fopen(silencers_filename, "r");
if (fd) {
fseek(fd, 0 , SEEK_END);
off_t length = (off_t) ftell(fd);
fseek(fd, 0 , SEEK_SET);
if (length > 0 && length < HEALTH_SILENCERS_MAX_FILE_LEN) {
char *str = mallocz((length+1)* sizeof(char));
if(str) {
size_t copied;
copied = fread(str, sizeof(char), length, fd);
if (copied == (length* sizeof(char))) {
str[length] = 0x00;
json_parse(str, NULL, health_silencers_json_read_callback);
info("Parsed health silencers file %s", silencers_filename);
} else {
error("Cannot read the data from health silencers file %s", silencers_filename);
}
freez(str);
}
} else {
error("Health silencers file %s has the size %ld that is out of range[ 1 , %d ]. Aborting read.",<