--- src/libs/zbxserver/expression.c 2013-09-03 14:07:45.000000000 +0300 +++ src/libs/zbxserver/expression.c 2013-09-12 21:07:52.957007976 +0300 @@ -167,4 +167,5 @@ double value1, value2; char *p, c; + int ret; zbx_lrtrim(expression, " "); @@ -186,4 +187,9 @@ return SUCCEED; } + else if (0 == strcmp("Undef", expression)) + { + zbx_snprintf(error, maxerrlen, "Undefined function. Exp: [%s]", expression); + return FAIL; + } /* operators with lowest priority come first */ @@ -197,13 +203,43 @@ c = *p; *p = '\0'; - - if (SUCCEED != evaluate_simple(&value1, expression, error, maxerrlen) || - SUCCEED != evaluate_simple(&value2, p + 1, error, maxerrlen)) - { - *p = c; - return FAIL; + ret = evaluate_simple(&value1, expression, error, maxerrlen); + *p = c; + if ('&' == c || '|' == c) + { /* special case: "true | undef" is "true", "false & undef" is "false" */ + if (SUCCEED == ret) + { + if ('|' == c && SUCCEED != cmp_double(value1, 0)) + { + *result = -1; /* true */ + return SUCCEED; + } + if ('&' == c && SUCCEED == cmp_double(value1, 0)) + { + *result = 0; /* false */ + return SUCCEED; + } + } + else + { + if (SUCCEED != evaluate_simple(&value2, p + 1, error, maxerrlen)) + return FAIL; + if ('|' == c && SUCCEED != cmp_double(value2, 0)) + { + *result = -1; /* true */ + return SUCCEED; + } + if ('&' == c && SUCCEED == cmp_double(value2, 0)) + { + *result = 0; /* false */ + return SUCCEED; + } + return FAIL; + } } + else if (SUCCEED != ret) + return FAIL; - *p = c; + if (SUCCEED != evaluate_simple(&value2, p + 1, error, maxerrlen)) + return FAIL; } else @@ -268,5 +304,5 @@ * Author: Alexei Vladishev * * * - * Comments: example: ({15}>10)|({123}=1) * + * Comments: example: (6.456>10)|(0=0) * * * ******************************************************************************/ @@ -3790,8 +3826,5 @@ if (SUCCEED != evaluate_function(value, &item, func->function, func->parameter, func->timespec.sec)) - { - func->error = zbx_dsprintf(func->error, "Evaluation failed for function: {%s:%s.%s(%s)}", - item.host_name, item.key, func->function, func->parameter); - } + func->value = zbx_strdup(func->value, "Undef"); else func->value = zbx_strdup(func->value, value);