@cryptotaxi247 / netdata-1 / commits / e1b794fef

support any character in alarm variable names

Costa Tsaousis (ktsaou) committed Oct 19, 2017 at 23:36 UTC e1b794fef42f95f8c6aefef21e70ecb28f0509ce
2 files changed +24 -9
profile/test-eval.c
+3 -2
@@ -3,11 +3,12 @@
3 * 1. build netdata (as normally)
4 * 2. cd profile/
5 * 3. compile with:
6 - * 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
7 - *
6 + * 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
7 */
8
9 +#include "config.h"
10 #include "common.h"
11 +#include "clocks.h"
12
13 void netdata_cleanup_and_exit(int ret) { exit(ret); }
14
src/eval.c
+21 -7
@@ -166,7 +166,7 @@ static inline calculated_number eval_variable(EVAL_EXPRESSION *exp, EVAL_VARIABL
166 }
167
168 if(exp->rrdcalc && health_variable_lookup(v->name, v->hash, exp->rrdcalc, &n)) {
169 - buffer_sprintf(exp->error_msg, "[ $%s = ", v->name);
169 + buffer_sprintf(exp->error_msg, "[ ${%s} = ", v->name);
170 print_parsed_as_constant(exp->error_msg, n);
171 buffer_strcat(exp->error_msg, " ] ");
172 return n;
@@ -355,7 +355,7 @@ static inline calculated_number eval_node(EVAL_EXPRESSION *exp, EVAL_NODE *op, i
355
356 static inline void print_parsed_as_variable(BUFFER *out, EVAL_VARIABLE *v, int *error) {
357 (void)error;
358 - buffer_sprintf(out, "$%s", v->name);
358 + buffer_sprintf(out, "${%s}", v->name);
359 }
360
361 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)
703 const char *s = *string;
704
705 // $
706 - if(s[0] == '$') {
706 + if(*s == '$') {
707 size_t i = 0;
708 s++;
709
710 - while(*s && !isvariableterm(*s) && i < len)
711 - buffer[i++] = *s++;
710 + if(*s == '{') {
711 + // ${variable_name}
712 +
713 + s++;
714 + while (*s && *s != '}' && i < len)
715 + buffer[i++] = *s++;
716 +
717 + if(*s == '}')
718 + s++;
719 + }
720 + else {
721 + // $variable_name
722 +
723 + while (*s && !isvariableterm(*s) && i < len)
724 + buffer[i++] = *s++;
725 + }
726
727 buffer[i] = '\0';
728
715 - if(buffer[0]) {
716 - *string = &s[0];
729 + if (buffer[0]) {
730 + *string = s;
731 return 1;
732 }
733 }