#include "common.h"
+#define RRDSETVAR_ID_MAX 1024
+
static const char *health_default_exec = PLUGINS_DIR "/alarm.sh";
+int health_enabled = 1;
// ----------------------------------------------------------------------------
// RRDVAR management
// ----------------------------------------------------------------------------
// RRDSETVAR management
-#define RRDSETVAR_ID_MAX 1024
-
RRDSETVAR *rrdsetvar_create(RRDSET *st, const char *variable, int type, void *value, uint32_t options) {
debug(D_VARIABLES, "RRDVARSET create for chart id '%s' name '%s' with variable name '%s'", st->id, st->name, variable);
RRDSETVAR *rs = (RRDSETVAR *)callocz(1, sizeof(RRDSETVAR));
// ----------------------------------------------------------------------------
// RRDCALCTEMPLATE management
+static inline int variable_fix_name(char *variable) {
+ int fixed = 0;
+ while(*variable) {
+ if (!isalnum(*variable) && *variable != '.' && *variable != '_') {
+ *variable++ = '_';
+ fixed++;
+ }
+ else
+ variable++;
+ }
+
+ return fixed;
+}
+
void rrdcalctemplate_link_matching(RRDSET *st) {
RRDCALCTEMPLATE *rt;
for(rt = st->rrdhost->templates; rt ; rt = rt->next) {
if(rt->hash_context == st->hash_context && !strcmp(rt->context, st->context)) {
- char *s, buffer[RRDSETVAR_ID_MAX + 1];
+ char buffer[RRDSETVAR_ID_MAX + 1];
snprintfz(buffer, RRDSETVAR_ID_MAX, "%s.%s", st->family, rt->name);
- s = buffer;
- while(*s) {
- if (!isalnum(*s) && *s != '.' && *s != '_')
- *s++ = '_';
- else
- s++;
- }
-
+ variable_fix_name(buffer);
rrdcalc_create(st->rrdhost, buffer, st->id,
rt->dimensions, rt->group, rt->after, rt->before, rt->update_every, rt->options,
rt->green, rt->red, rt->exec,
rt = NULL;
}
- // FIXME: make sure the value does not any operators or spaces
rc = callocz(1, sizeof(RRDCALC));
rc->name = strdupz(value);
rc->hash = simple_hash(rc->name);
rc->source = health_source_file(line, path, filename);
+
+ if(variable_fix_name(rc->name))
+ error("Health configuration renamed alarm '%s' to '%s'", value, rc->name);
}
else if(hash == hash_template && !strcasecmp(key, HEALTH_TEMPLATE_KEY)) {
if(rc) {
if(rt && !rrdcalctemplate_add(&localhost, rt))
rrdcalctemplate_free(&localhost, rt);
- // FIXME: make sure the value does not any operators or spaces
rt = callocz(1, sizeof(RRDCALCTEMPLATE));
rt->name = strdupz(value);
rt->hash_name = simple_hash(rt->name);
rt->source = health_source_file(line, path, filename);
+
+ if(variable_fix_name(rt->name))
+ error("Health configuration renamed template '%s' to '%s'", value, rt->name);
}
else if(rc) {
if(hash == hash_on && !strcasecmp(key, HEALTH_ON_KEY)) {
char *path;
- if(!config_get_boolean("health", "enabled", 1)) {
+ if(!(health_enabled = config_get_boolean("health", "enabled", 1))) {
debug(D_HEALTH, "Health is disabled.");
return;
}
#ifndef NETDATA_HEALTH_H
#define NETDATA_HEALTH_H
-extern int rrdvar_compare(void *a, void *b);
+extern int health_enabled;
-/*
- * RRDVAR
- * a variable
- *
- * There are 4 scopes: local (chart), context, host and global variables
- *
- * Standard global variables:
- * $now
- *
- * Standard host variables:
- * - none -
- *
- * Standard context variables:
- * - none -
- *
- * Standard local variables:
- * $last_updated
- * $last_collected_value
- * $last_value
- *
- */
+extern int rrdvar_compare(void *a, void *b);
#define RRDVAR_TYPE_CALCULATED 1
#define RRDVAR_TYPE_TIME_T 2