summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-10-19 23:36:36 +0300
committerCosta Tsaousis (ktsaou) <costa@tsaousis.gr>2017-10-19 23:36:36 +0300
commite1b794fef42f95f8c6aefef21e70ecb28f0509ce (patch)
tree7467c3aed41348b7055ba6cdb8a1b18e95b12a45
parent561f74cbd9410151d3b34dcd27c137177471750d (diff)
support any character in alarm variable names
-rw-r--r--profile/test-eval.c5
-rw-r--r--src/eval.c28
2 files changed, 24 insertions, 9 deletions
diff --git a/profile/test-eval.c b/profile/test-eval.c
index ad521b7d84..7602690f82 100644
--- a/profile/test-eval.c
+++ b/profile/test-eval.c
@@ -3,11 +3,12 @@
* 1. build netdata (as normally)
* 2. cd profile/
* 3. compile with:
- * gcc -O1 -ggdb -Wall -Wextra -I ../src/ -I ../ -o test-eval test-eval.c ../src/log.o ../src/eval.o ../src/common.o ../src/web_buffer.o ../src/storage_number.o -pthread -lm
- *
+ * gcc -O1 -ggdb -Wall -Wextra -I ../src/ -I ../ -o test-eval test-eval.c ../src/log.o ../src/eval.o ../src/common.o ../src/clocks.o ../src/web_buffer.o ../src/storage_number.o -pthread -lm
*/
+#include "config.h"
#include "common.h"
+#include "clocks.h"
void netdata_cleanup_and_exit(int ret) { exit(ret); }
diff --git a/src/eval.c b/src/eval.c
index 063db50a23..84369f6d40 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -166,7 +166,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
}
if(exp->rrdcalc && health_variable_lookup(v->name, v->hash, exp->rrdcalc, &n)) {
- buffer_sprintf(exp->error_msg, "[ $%s = ", v->name);
+ buffer_sprintf(exp->error_msg, "[ ${%s} = ", v->name);
print_parsed_as_constant(exp->error_msg, n);
buffer_strcat(exp->error_msg, " ] ");
return n;
@@ -355,7 +355,7 @@ static inline calculated_number eval_node(EVAL_EXPRESSION *exp, EVAL_NODE *op, i
static inline void print_parsed_as_variable(BUFFER *out, EVAL_VARIABLE *v, int *error) {
(void)error;
- buffer_sprintf(out, "$%s", v->name);
+ buffer_sprintf(out, "${%s}", v->name);
}
static inline void print_parsed_as_constant(BUFFER *out, calculated_number n) {
@@ -703,17 +703,31 @@ static inline int parse_variable(const char **string, char *buffer, size_t len)
const char *s = *string;
// $
- if(s[0] == '$') {
+ if(*s == '$') {
size_t i = 0;
s++;
- while(*s && !isvariableterm(*s) && i < len)
- buffer[i++] = *s++;
+ if(*s == '{') {
+ // ${variable_name}
+
+ s++;
+ while (*s && *s != '}' && i < len)
+ buffer[i++] = *s++;
+
+ if(*s == '}')
+ s++;
+ }
+ else {
+ // $variable_name
+
+ while (*s && !isvariableterm(*s) && i < len)
+ buffer[i++] = *s++;
+ }
buffer[i] = '\0';
- if(buffer[0]) {
- *string = &s[0];
+ if (buffer[0]) {
+ *string = s;
return 1;
}
}