summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 10a65c7)
raw | patch | inline | side by side (parent: 10a65c7)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 17 Oct 2014 22:42:43 +0000 (00:42 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 17 Oct 2014 22:42:43 +0000 (00:42 +0200) |
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 24a13757833635acbeee7dc4e2e3328042202f2f..30414d24a2a0eadc70d0342a7a92f871f94e1b5f 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
sdb_object_deref(SDB_OBJ($3));
}
|
- IDENTIFIER '[' IDENTIFIER ']' cmp expression
+ IDENTIFIER '[' STRING ']' cmp expression
{
$$ = sdb_store_matcher_parse_cmp($1, $3, $5, $6);
free($1); $1 = NULL;
sdb_object_deref(SDB_OBJ($6));
}
|
- IDENTIFIER '[' IDENTIFIER ']' IS NULL_T
+ IDENTIFIER '[' STRING ']' IS NULL_T
{
sdb_store_expr_t *expr;
free($3); $3 = NULL;
}
|
- IDENTIFIER '[' IDENTIFIER ']' IS NOT NULL_T
+ IDENTIFIER '[' STRING ']' IS NOT NULL_T
{
sdb_store_expr_t *expr;
$$ = sdb_store_expr_fieldvalue(field);
}
|
- IDENTIFIER '[' IDENTIFIER ']'
+ IDENTIFIER '[' STRING ']'
{
$$ = sdb_store_expr_attrvalue($3);
free($1); $1 = NULL;
index d42044ba9e0b26899f4be3c9a5f1bf5c73e7dea7..67b97210058a5e44247f67a873794c5e364ffe42 100755 (executable)
echo "$output" | grep -F 'other.host.name' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts MATCHING attribute[architecture] = 'x42'" )"
+ -c "LOOKUP hosts MATCHING attribute['architecture'] = 'x42'" )"
echo "$output" \
| grep -F '"host1.example.com"' \
| grep -F '"host2.example.com"'
# When querying hosts that don't exist, expect a zero exit code.
output="$( run_sysdb -H "$SOCKET_FILE" \
- -c "LOOKUP hosts MATCHING attribute[invalid] = 'none'" )"
+ -c "LOOKUP hosts MATCHING attribute['invalid'] = 'none'" )"
echo $output | grep -E '^\[\]$'
stop_sysdbd
index 2e1e6d8b1a536dddffd341cde2e4f0a50611c76b..1739296ea1b4222cb9e4617c3e31df29fe5d4fa4 100644 (file)
int expected;
const char *tostring_re;
} golden_data[] = {
- { "host = 'a'", NULL, 1,
+ { "host = 'a'", NULL, 1,
"OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
- { "host = 'a'", "host = 'x'", 0, /* filter never matches */
+ { "host = 'a'", "host = 'x'", 0, /* filter never matches */
"OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
{ "host = 'a'",
- "NOT attribute[x] = ''", 1, /* filter always matches */
+ "NOT attribute['x'] = ''", 1, /* filter always matches */
"OBJ\\[host\\]\\{ NAME\\{ 'a', \\(nil\\) \\} \\}" },
- { "host =~ 'a|b'", NULL, 2,
+ { "host =~ 'a|b'", NULL, 2,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host =~ 'host'", NULL, 0,
+ { "host =~ 'host'", NULL, 0,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "host =~ '.'", NULL, 3,
+ { "host =~ '.'", NULL, 3,
"OBJ\\[host\\]\\{ NAME\\{ NULL, "PTR_RE" \\} \\}" },
- { "metric = 'm1'", NULL, 2,
+ { "metric = 'm1'", NULL, 2,
"OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
- { "metric= 'm1'", "host = 'x'", 0, /* filter never matches */
+ { "metric= 'm1'", "host = 'x'", 0, /* filter never matches */
"OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
{ "metric = 'm1'",
- "NOT attribute[x] = ''", 2, /* filter always matches */
+ "NOT attribute['x'] = ''", 2, /* filter always matches */
"OBJ\\[metric\\]\\{ NAME\\{ 'm1', \\(nil\\) } \\}" },
- { "metric =~ 'm'", NULL, 2,
+ { "metric =~ 'm'", NULL, 2,
"OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
- { "metric !~ 'm'", NULL, 1,
+ { "metric !~ 'm'", NULL, 1,
"\\(NOT, OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
- { "metric =~ 'x'", NULL, 0,
+ { "metric =~ 'x'", NULL, 0,
"OBJ\\[metric\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
- { "service = 's1'", NULL, 2,
+ { "service = 's1'", NULL, 2,
"OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
- { "service = 's1'", "host = 'x'", 0, /* filter never matches */
+ { "service = 's1'", "host = 'x'", 0, /* filter never matches */
"OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
{ "service = 's1'",
- "NOT attribute[x] = ''", 2, /* filter always matches */
+ "NOT attribute['x'] = ''", 2, /* filter always matches */
"OBJ\\[service\\]\\{ NAME\\{ 's1', \\(nil\\) } \\}" },
- { "service =~ 's'", NULL, 2,
+ { "service =~ 's'", NULL, 2,
"OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}" },
- { "service !~ 's'", NULL, 1,
+ { "service !~ 's'", NULL, 1,
"\\(NOT, OBJ\\[service\\]\\{ NAME\\{ NULL, "PTR_RE" } \\}\\)" },
- { "attribute = 'k1'", NULL, 1,
+ { "attribute = 'k1'", NULL, 1,
"OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
- { "attribute = 'k1'", "host = 'x'", 0, /* filter never matches */
+ { "attribute = 'k1'", "host = 'x'", 0, /* filter never matches */
"OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
{ "attribute = 'k1'",
- "NOT attribute[x] = ''", 1, /* filter always matches */
+ "NOT attribute['x'] = ''", 1, /* filter always matches */
"OBJ\\[attribute\\]\\{ NAME\\{ 'k1', \\(nil\\) \\} " },
- { "attribute = 'x'", NULL, 0,
+ { "attribute = 'x'", NULL, 0,
"OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\}" },
- { "attribute[k1] = 'v1'", NULL, 1,
+ { "attribute['k1'] = 'v1'", NULL, 1,
"ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}" },
- { "attribute[k1] IS NULL", NULL, 2,
+ { "attribute['k1'] IS NULL", NULL, 2,
"\\(IS NULL\\)" },
- { "attribute[x1] IS NULL", NULL, 3,
+ { "attribute['x1'] IS NULL", NULL, 3,
"\\(IS NULL\\)" },
- { "attribute[k1] IS NOT NULL", NULL, 1,
+ { "attribute['k1'] IS NOT NULL", NULL, 1,
"\\(IS NOT NULL\\)" },
- { "attribute[x1] IS NOT NULL", NULL, 0,
+ { "attribute['x1'] IS NOT NULL", NULL, 0,
"\\(IS NOT NULL\\)" },
- { "attribute[k2] < 123", NULL, 0,
+ { "attribute['k2'] < 123", NULL, 0,
"ATTR\\[k2\\]\\{ < 123 \\}" },
- { "attribute[k2] <= 123", NULL, 1,
+ { "attribute['k2'] <= 123", NULL, 1,
"ATTR\\[k2\\]\\{ <= 123 \\}" },
- { "attribute[k2] >= 123", NULL, 1,
+ { "attribute['k2'] >= 123", NULL, 1,
"ATTR\\[k2\\]\\{ >= 123 \\}" },
- { "attribute[k2] > 123", NULL, 0,
+ { "attribute['k2'] > 123", NULL, 0,
"ATTR\\[k2\\]\\{ > 123 \\}" },
- { "attribute[k2] = 123", NULL, 1,
+ { "attribute['k2'] = 123", NULL, 1,
"ATTR\\[k2\\]\\{ = 123 \\}" },
- { "attribute[k2] != 123", NULL, 2,
+ { "attribute['k2'] != 123", NULL, 2,
"\\(NOT, ATTR\\[k2\\]\\{ = 123 \\}\\)" },
- { "attribute[k1] != 'v1'", NULL, 2,
+ { "attribute['k1'] != 'v1'", NULL, 2,
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v1', \\(nil\\) \\} \\}\\)" },
- { "attribute[k1] != 'v2'", NULL, 3,
+ { "attribute['k1'] != 'v2'", NULL, 3,
"\\(NOT, ATTR\\[k1\\]\\{ VALUE\\{ 'v2', \\(nil\\) \\} \\}\\)" },
{ "attribute != 'x' "
- "AND attribute[y] !~ 'x'", NULL, 3,
+ "AND attribute['y'] !~ 'x'", NULL, 3,
"\\(AND, "
"\\(NOT, OBJ\\[attribute\\]\\{ NAME\\{ 'x', \\(nil\\) \\} \\}\\), "
"\\(NOT, ATTR\\[y\\]\\{ VALUE\\{ NULL, "PTR_RE" \\} \\}\\)\\)" },
index 7839ee8a42fa4094d1dc3b995933a1b5866ff509..8898e8b082852b5212fe307e76ece7a538dc251b 100644 (file)
/* numeric constants */
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"1234", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] != "
+ "attribute['foo'] != "
"+234", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] < "
+ "attribute['foo'] < "
"-234", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] > "
+ "attribute['foo'] > "
"12.4", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] <= "
+ "attribute['foo'] <= "
"12. + .3", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] <= "
+ "attribute['foo'] <= "
"'f' || 'oo'", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] >= "
+ "attribute['foo'] >= "
".4", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"+12e3", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"+12e-3", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"-12e+3", -1, 1, CONNECTION_LOOKUP },
/* date, time, interval constants */
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"1 Y 42D", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"1s 42D", -1, 1, CONNECTION_LOOKUP },
/*
* TODO: Something like 1Y42D should work as well but it doesn't since
* the scanner will tokenize it into {digit}{identifier} :-/
*
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"1Y42D", -1, 1, CONNECTION_LOOKUP },
*/
/* NULL */
{ "LOOKUP hosts MATCHING "
- "attribute[foo] "
+ "attribute['foo'] "
"IS NULL", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] "
+ "attribute['foo'] "
"IS NOT NULL", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
- "NOT attribute[foo] "
+ "NOT attribute['foo'] "
"IS NULL", -1, 1, CONNECTION_LOOKUP },
{ "LOOKUP hosts MATCHING "
"host IS NULL", -1, -1, 0 },
/* invalid numeric constants */
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"+-12e+3", -1, -1, 0 },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"-12e-+3", -1, -1, 0 },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"e+3", -1, -1, 0 },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"3e", -1, -1, 0 },
/* following SQL standard, we don't support hex numbers */
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"0x12", -1, -1, 0 },
/* invalid expressions */
{ "LOOKUP hosts MATCHING "
- "attribute[foo] = "
+ "attribute['foo'] = "
"1.23 + 'foo'", -1, -1, 0 },
/* comments */
"host = 'host' FILTER "
"host = 'host'", -1, -1, 0 },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] <= "
+ "attribute['foo'] <= "
"f || 'oo'", -1, -1, 0 },
{ "LOOKUP hosts MATCHING "
- "attribute[foo] <= "
+ "attribute['foo'] <= "
"'f' || oo", -1, -1, 0 },
};
int expected;
} golden_data[] = {
/* empty expressions */
- { NULL, -1, -1 },
- { "", -1, -1 },
+ { NULL, -1, -1 },
+ { "", -1, -1 },
/* valid expressions */
- { "host = 'localhost'", -1, MATCHER_NAME },
- { "host != 'localhost'", -1, MATCHER_NOT },
- { "host =~ 'host'", -1, MATCHER_NAME },
- { "host !~ 'host'", -1, MATCHER_NOT },
- { "host = 'localhost' -- foo", -1, MATCHER_NAME },
- { "host = 'host' <garbage>", 13, MATCHER_NAME },
+ { "host = 'localhost'", -1, MATCHER_NAME },
+ { "host != 'localhost'", -1, MATCHER_NOT },
+ { "host =~ 'host'", -1, MATCHER_NAME },
+ { "host !~ 'host'", -1, MATCHER_NOT },
+ { "host = 'localhost' -- foo", -1, MATCHER_NAME },
+ { "host = 'host' <garbage>", 13, MATCHER_NAME },
/* match hosts by service */
- { "service = 'name'", -1, MATCHER_NAME },
- { "service != 'name'", -1, MATCHER_NOT },
- { "service =~ 'pattern'", -1, MATCHER_NAME },
- { "service !~ 'pattern'", -1, MATCHER_NOT },
+ { "service = 'name'", -1, MATCHER_NAME },
+ { "service != 'name'", -1, MATCHER_NOT },
+ { "service =~ 'pattern'", -1, MATCHER_NAME },
+ { "service !~ 'pattern'", -1, MATCHER_NOT },
/* match hosts by attribute */
- { "attribute = 'name'", -1, MATCHER_NAME },
- { "attribute != 'name'", -1, MATCHER_NOT },
- { "attribute =~ 'pattern'", -1, MATCHER_NAME },
- { "attribute !~ 'pattern'", -1, MATCHER_NOT },
+ { "attribute = 'name'", -1, MATCHER_NAME },
+ { "attribute != 'name'", -1, MATCHER_NOT },
+ { "attribute =~ 'pattern'", -1, MATCHER_NAME },
+ { "attribute !~ 'pattern'", -1, MATCHER_NOT },
/* composite expressions */
{ "host =~ 'pattern' AND "
- "service =~ 'pattern'", -1, MATCHER_AND },
+ "service =~ 'pattern'", -1, MATCHER_AND },
{ "host =~ 'pattern' OR "
- "service =~ 'pattern'", -1, MATCHER_OR },
- { "NOT host = 'host'", -1, MATCHER_NOT },
+ "service =~ 'pattern'", -1, MATCHER_OR },
+ { "NOT host = 'host'", -1, MATCHER_NOT },
/* numeric expressions */
- { "attribute[foo] < 123", -1, MATCHER_LT },
- { "attribute[foo] <= 123", -1, MATCHER_LE },
- { "attribute[foo] = 123", -1, MATCHER_EQ },
- { "attribute[foo] >= 123", -1, MATCHER_GE },
- { "attribute[foo] > 123", -1, MATCHER_GT },
+ { "attribute['foo'] < 123", -1, MATCHER_LT },
+ { "attribute['foo'] <= 123", -1, MATCHER_LE },
+ { "attribute['foo'] = 123", -1, MATCHER_EQ },
+ { "attribute['foo'] >= 123", -1, MATCHER_GE },
+ { "attribute['foo'] > 123", -1, MATCHER_GT },
/* datetime expressions */
- { "attribute[foo] = "
- "2014-08-16", -1, MATCHER_EQ },
- { "attribute[foo] = "
- "17:23", -1, MATCHER_EQ },
- { "attribute[foo] = "
- "17:23:53", -1, MATCHER_EQ },
- { "attribute[foo] = "
- "17:23:53.123", -1, MATCHER_EQ },
- { "attribute[foo] = "
- "17:23:53.123456789", -1, MATCHER_EQ },
- { "attribute[foo] = "
- "2014-08-16 17:23", -1, MATCHER_EQ },
- { "attribute[foo] = "
- "2014-08-16 17:23:53", -1, MATCHER_EQ },
+ { "attribute['foo'] = "
+ "2014-08-16", -1, MATCHER_EQ },
+ { "attribute['foo'] = "
+ "17:23", -1, MATCHER_EQ },
+ { "attribute['foo'] = "
+ "17:23:53", -1, MATCHER_EQ },
+ { "attribute['foo'] = "
+ "17:23:53.123", -1, MATCHER_EQ },
+ { "attribute['foo'] = "
+ "17:23:53.123456789", -1, MATCHER_EQ },
+ { "attribute['foo'] = "
+ "2014-08-16 17:23", -1, MATCHER_EQ },
+ { "attribute['foo'] = "
+ "2014-08-16 17:23:53", -1, MATCHER_EQ },
/* NULL; while this is an implementation detail,
* IS NULL currently maps to an equality matcher */
- { "attribute[foo] IS NULL", -1, MATCHER_ISNULL },
- { "attribute[foo] IS NOT NULL", -1, MATCHER_ISNNULL },
+ { "attribute['foo'] IS NULL", -1, MATCHER_ISNULL },
+ { "attribute['foo'] IS NOT NULL", -1, MATCHER_ISNNULL },
/* object field matchers */
- { ".last_update < 10s", -1, MATCHER_LT },
- { ".AGE <= 1m", -1, MATCHER_LE },
- { ".interval = 10h", -1, MATCHER_EQ },
- { ".Last_Update >= 24D", -1, MATCHER_GE },
- { ".age > 1M", -1, MATCHER_GT },
- { ".age != 20Y", -1, MATCHER_NOT },
- { ".backend != 'be'", -1, MATCHER_NOT },
- { ".age <= 2 * .interval", -1, MATCHER_LE },
+ { ".last_update < 10s", -1, MATCHER_LT },
+ { ".AGE <= 1m", -1, MATCHER_LE },
+ { ".interval = 10h", -1, MATCHER_EQ },
+ { ".Last_Update >= 24D", -1, MATCHER_GE },
+ { ".age > 1M", -1, MATCHER_GT },
+ { ".age != 20Y", -1, MATCHER_NOT },
+ { ".backend != 'be'", -1, MATCHER_NOT },
+ { ".age <= 2 * .interval", -1, MATCHER_LE },
/* check operator precedence */
{ "host = 'name' OR "
"service = 'name' AND "
"attribute = 'name' OR "
- "attribute[foo] = 'bar'", -1, MATCHER_OR },
+ "attribute['foo'] = 'bar'", -1, MATCHER_OR },
{ "host = 'name' AND "
"service = 'name' AND "
"attribute = 'name' OR "
- "attribute[foo] = 'bar'", -1, MATCHER_OR },
+ "attribute['foo'] = 'bar'", -1, MATCHER_OR },
{ "host = 'name' AND "
"service = 'name' OR "
"attribute = 'name' AND "
- "attribute[foo] = 'bar'", -1, MATCHER_OR },
+ "attribute['foo'] = 'bar'", -1, MATCHER_OR },
{ "(host = 'name' OR "
"service = 'name') AND "
"(attribute = 'name' OR "
- "attribute[foo] = 'bar')", -1, MATCHER_AND },
+ "attribute['foo'] = 'bar')", -1, MATCHER_AND },
{ "NOT host = 'name' OR "
- "service = 'name'", -1, MATCHER_OR },
+ "service = 'name'", -1, MATCHER_OR },
{ "NOT host = 'name' OR "
- "NOT service = 'name'", -1, MATCHER_OR },
+ "NOT service = 'name'", -1, MATCHER_OR },
{ "NOT (host = 'name' OR "
- "NOT service = 'name')", -1, MATCHER_NOT },
+ "NOT service = 'name')", -1, MATCHER_NOT },
/* syntax errors */
- { "LIST", -1, -1 },
- { "foo &^ bar", -1, -1 },
- { ".invalid", -1, -1 },
+ { "LIST", -1, -1 },
+ { "foo &^ bar", -1, -1 },
+ { ".invalid", -1, -1 },
};
size_t i;
{ ".backend", -1, FIELD_VALUE },
/* attributes */
- { "attribute[foo]", -1, ATTR_VALUE },
+ { "attribute['foo']", -1, ATTR_VALUE },
/* arithmetic expressions */
{ ".age + .age", -1, SDB_DATA_ADD },