};
static struct health_options health = {
- .health_default_exec = PLUGINS_DIR "/alarm-notify.sh",
+ .health_default_exec = NULL,
.health_default_recipient = "root",
- .log_filename = VARLIB_DIR "/health/alarm_log.db",
+ .log_filename = NULL,
.log_entries_written = 0,
.log_fp = NULL
};
return 1;
}
-static inline char *tabs2spaces(char *s) {
- char *t = s;
- while(*t) {
- if(unlikely(*t == '\t')) *t = ' ';
- t++;
+static inline char *trim_all_spaces(char *buffer) {
+ char *d = buffer, *s = buffer;
+
+ // skip spaces
+ while(isspace(*s)) s++;
+
+ while(*s) {
+ // copy the non-space part
+ while(*s && !isspace(*s)) *d++ = *s++;
+
+ // add a space if we have to
+ if(*s && isspace(*s)) {
+ *d++ = ' ';
+ s++;
+ }
+
+ // skip spaces
+ while(isspace(*s)) s++;
+ }
+
+ *d = '\0';
+
+ if(d > buffer) {
+ d--;
+ if(isspace(*d)) *d = '\0';
}
- return s;
+ if(!buffer[0]) return NULL;
+ return buffer;
}
static inline char *health_source_file(size_t line, const char *path, const char *filename) {
s++;
char *value = s;
- key = trim(key);
- value = trim(value);
+ key = trim_all_spaces(key);
+ value = trim_all_spaces(value);
if(!key) {
error("Health configuration has invalid line %zu of file '%s/%s'. Keyword is empty. Ignoring it.", line, path, filename);
rc = callocz(1, sizeof(RRDCALC));
rc->next_event_id = 1;
- rc->name = tabs2spaces(strdupz(value));
+ rc->name = strdupz(value);
rc->hash = simple_hash(rc->name);
rc->source = health_source_file(line, path, filename);
rc->green = NAN;
rrdcalctemplate_free(&localhost, rt);
rt = callocz(1, sizeof(RRDCALCTEMPLATE));
- rt->name = tabs2spaces(strdupz(value));
+ rt->name = strdupz(value);
rt->hash_name = simple_hash(rt->name);
rt->source = health_source_file(line, path, filename);
rt->green = NAN;
freez(rc->chart);
}
- rc->chart = tabs2spaces(strdupz(value));
+ rc->chart = strdupz(value);
rc->hash_chart = simple_hash(rc->chart);
}
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
freez(rc->exec);
}
- rc->exec = tabs2spaces(strdupz(value));
+ rc->exec = strdupz(value);
}
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
if(rc->recipient) {
freez(rc->recipient);
}
- rc->recipient = tabs2spaces(strdupz(value));
+ rc->recipient = strdupz(value);
}
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
if(rc->units) {
freez(rc->units);
}
- rc->units = tabs2spaces(strdupz(value));
+ rc->units = strdupz(value);
strip_quotes(rc->units);
}
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
freez(rc->info);
}
- rc->info = tabs2spaces(strdupz(value));
+ rc->info = strdupz(value);
strip_quotes(rc->info);
}
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
freez(rt->context);
}
- rt->context = tabs2spaces(strdupz(value));
+ rt->context = strdupz(value);
rt->hash_context = simple_hash(rt->context);
}
else if(hash == hash_families && !strcasecmp(key, HEALTH_FAMILIES_KEY)) {
freez(rt->family_match);
simple_pattern_free(rt->family_pattern);
- rt->family_match = tabs2spaces(strdupz(value));
+ rt->family_match = strdupz(value);
rt->family_pattern = simple_pattern_create(rt->family_match, SIMPLE_PATTERN_EXACT);
}
else if(hash == hash_lookup && !strcasecmp(key, HEALTH_LOOKUP_KEY)) {
freez(rt->exec);
}
- rt->exec = tabs2spaces(strdupz(value));
+ rt->exec = strdupz(value);
}
else if(hash == hash_recipient && !strcasecmp(key, HEALTH_RECIPIENT_KEY)) {
if(rt->recipient) {
freez(rt->recipient);
}
- rt->recipient = tabs2spaces(strdupz(value));
+ rt->recipient = strdupz(value);
}
else if(hash == hash_units && !strcasecmp(key, HEALTH_UNITS_KEY)) {
if(rt->units) {
freez(rt->units);
}
- rt->units = tabs2spaces(strdupz(value));
+ rt->units = strdupz(value);
strip_quotes(rt->units);
}
else if(hash == hash_info && !strcasecmp(key, HEALTH_INFO_KEY)) {
freez(rt->info);
}
- rt->info = tabs2spaces(strdupz(value));
+ rt->info = strdupz(value);
strip_quotes(rt->info);
}
else if(hash == hash_delay && !strcasecmp(key, HEALTH_DELAY_KEY)) {
static inline char *health_config_dir(void) {
char buffer[FILENAME_MAX + 1];
- snprintfz(buffer, FILENAME_MAX, "%s/health.d", config_get("global", "config directory", CONFIG_DIR));
+ snprintfz(buffer, FILENAME_MAX, "%s/health.d", netdata_configured_config_dir);
return config_get("health", "health configuration directory", buffer);
}
return;
}
- char *pathname = config_get("health", "health db directory", VARLIB_DIR "/health");
+ char pathname[FILENAME_MAX + 1];
+ snprintfz(pathname, FILENAME_MAX, "%s/health", netdata_configured_varlib_dir);
if(mkdir(pathname, 0770) == -1 && errno != EEXIST)
fatal("Cannot create directory '%s'.", pathname);
char *path = health_config_dir();
- {
- char buffer[FILENAME_MAX + 1];
- snprintfz(buffer, FILENAME_MAX, "%s/alarm-notify.sh", config_get("global", "plugins directory", PLUGINS_DIR));
- health.health_default_exec = config_get("health", "script to execute on alarm", buffer);
- }
+ snprintfz(filename, FILENAME_MAX, "%s/alarm-notify.sh", netdata_configured_plugins_dir);
+ health.health_default_exec = config_get("health", "script to execute on alarm", filename);
long n = config_get_number("health", "in memory max health log entries", (long)localhost.health_log.max);
if(n < 10) {
}
static inline void health_rrdcalc2json_nolock(BUFFER *wb, RRDCALC *rc) {
+ char value_string[100 + 1];
+ format_value_and_unit(value_string, 100, rc->value, rc->units, -1);
+
buffer_sprintf(wb,
"\t\t\"%s.%s\": {\n"
"\t\t\t\"id\": %lu,\n"
"\t\t\t\"delay_multiplier\": %f,\n"
"\t\t\t\"delay\": %d,\n"
"\t\t\t\"delay_up_to_timestamp\": %lu,\n"
+ "\t\t\t\"value_string\": \"%s\",\n"
, rc->chart, rc->name
, (unsigned long)rc->id
, rc->name
, rc->delay_multiplier
, rc->delay_last
, (unsigned long)rc->delay_up_to_timestamp
+ , value_string
);
if(unlikely(rc->options & RRDCALC_FLAG_NO_CLEAR_NOTIFICATION)) {