summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f19bd5e)
raw | patch | inline | side by side (parent: f19bd5e)
author | Sebastian Harl <sh@tokkee.org> | |
Sat, 25 Oct 2014 20:22:45 +0000 (22:22 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Sat, 25 Oct 2014 20:22:45 +0000 (22:22 +0200) |
This matches, if all of the specified objects match the specified expression.
ALL also matches on empty object lists.
ALL also matches on empty object lists.
src/frontend/grammar.y | patch | blob | history | |
src/frontend/scanner.l | patch | blob | history | |
t/integration/matching.sh | patch | blob | history | |
t/unit/core/store_lookup_test.c | patch | blob | history |
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 8057710c76851d4819a11e9d24ad91cc18562f88..92b55ebbd509eb9d62c975a3866c5aa67ce07534 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
*/
static sdb_store_matcher_t *
-name_matcher(char *type_name, char *cmp, sdb_store_expr_t *expr);
+name_matcher(const char *type_name, const char *cmp, sdb_store_expr_t *expr);
static sdb_store_matcher_t *
-name_iter_matcher(char *type_name, char *cmp, sdb_store_expr_t *expr);
+name_iter_matcher(int m_type, const char *type_name, const char *cmp,
+ sdb_store_expr_t *expr);
/*
* public API
%token AND OR IS NOT MATCHING FILTER
%token CMP_EQUAL CMP_NEQUAL CMP_REGEX CMP_NREGEX
-%token CMP_LT CMP_LE CMP_GE CMP_GT ANY IN
+%token CMP_LT CMP_LE CMP_GE CMP_GT ALL ANY IN
%token CONCAT
%token START END
|
ANY IDENTIFIER cmp expression
{
- $$ = name_iter_matcher($2, $3, $4);
+ $$ = name_iter_matcher(MATCHER_ANY, $2, $3, $4);
+ free($2); $2 = NULL;
+ sdb_object_deref(SDB_OBJ($4));
+ }
+ |
+ ALL IDENTIFIER cmp expression
+ {
+ $$ = name_iter_matcher(MATCHER_ALL, $2, $3, $4);
free($2); $2 = NULL;
sdb_object_deref(SDB_OBJ($4));
}
} /* sdb_fe_yyerror */
static sdb_store_matcher_t *
-name_matcher(char *type_name, char *cmp, sdb_store_expr_t *expr)
+name_matcher(const char *type_name, const char *cmp, sdb_store_expr_t *expr)
{
int type = sdb_store_parse_object_type(type_name);
sdb_store_matcher_op_cb cb = sdb_store_parse_matcher_op(cmp);
} /* name_matcher */
static sdb_store_matcher_t *
-name_iter_matcher(char *type_name, char *cmp, sdb_store_expr_t *expr)
+name_iter_matcher(int m_type, const char *type_name, const char *cmp,
+ sdb_store_expr_t *expr)
{
int type = sdb_store_parse_object_type(type_name);
sdb_store_matcher_op_cb cb = sdb_store_parse_matcher_op(cmp);
sdb_store_expr_t *e;
- sdb_store_matcher_t *m, *tmp;
+ sdb_store_matcher_t *m, *tmp = NULL;
assert(cb);
/* TODO: this only works as long as queries
e = sdb_store_expr_fieldvalue(SDB_FIELD_NAME);
m = cb(e, expr);
- tmp = sdb_store_any_matcher(type, m);
+ if (m_type == MATCHER_ANY)
+ tmp = sdb_store_any_matcher(type, m);
+ else if (m_type == MATCHER_ALL)
+ tmp = sdb_store_all_matcher(type, m);
sdb_object_deref(SDB_OBJ(m));
sdb_object_deref(SDB_OBJ(e));
return tmp;
diff --git a/src/frontend/scanner.l b/src/frontend/scanner.l
index 4f09c3730be73cb4e01a4af554f147fd31eaf9e3..b581e3d613cea435dd22f4c759ea292850ae2675 100644 (file)
--- a/src/frontend/scanner.l
+++ b/src/frontend/scanner.l
const char *name;
int id;
} reserved_words[] = {
+ { "ALL", ALL },
{ "AND", AND },
{ "ANY", ANY },
{ "END", END },
index 21a730ff8da647c91b06555224efa35fa40db59d..c96f7abea9c94cc8432a3ed27ff39268b3c60cd6 100755 (executable)
output="$( run_sysdb -H "$SOCKET_FILE" \
-c "LOOKUP hosts MATCHING ANY attribute != 'architecture'" )"
echo "$output" \
- | grep -F '"localhost"'
+ | grep -F '"localhost"' \
+ | grep -F '"other.host.name"' \
+ | grep -F '"host1.example.com"' \
+ | grep -F '"host2.example.com"'
echo "$output" | grep -F 'some.host.name' && exit 1
-#echo "$output" | grep -F 'other.host.name' && exit 1
-#echo "$output" | grep -F 'host1.example.com' && exit 1
-#echo "$output" | grep -F 'host2.example.com' && exit 1
+
+output="$( run_sysdb -H "$SOCKET_FILE" \
+ -c "LOOKUP hosts MATCHING ALL attribute != 'architecture'" )"
+echo "$output" \
+ | grep -F '"some.host.name"' \
+ | grep -F '"localhost"'
+echo "$output" | grep -F 'other.host.name' && exit 1
+echo "$output" | grep -F 'host1.example.com' && exit 1
+echo "$output" | grep -F 'host2.example.com' && exit 1
output="$( run_sysdb -H "$SOCKET_FILE" \
-c "LOOKUP hosts MATCHING ANY service = 'sysdbd'" )"
index d532757d1d9e6044528f396282617a8f916986d9..8d1508641d1a59515f67f8ec516900483f44d970 100644 (file)
{ "ANY metric = 'm1'",
"NOT attribute['x'] = ''", 2 }, /* filter always matches */
{ "ANY metric =~ 'm'", NULL, 2 },
+ { "ALL metric =~ 'm'", NULL, 3 },
+ { "ALL metric =~ '1'", NULL, 2 },
+ { "ALL metric =~ '2'", NULL, 1 },
{ "ANY metric !~ 'm'", NULL, 0 },
+ { "ALL metric !~ 'm'", NULL, 1 },
{ "ANY metric =~ 'x'", NULL, 0 },
{ "ANY service = 's1'", NULL, 2 },
{ "ANY service = 's1'", "host = 'x'", 0 }, /* filter never matches */
{ "ANY attribute =~ '2'", NULL, 1 },
{ "ANY attribute = 'x'", NULL, 0 },
{ "ANY attribute =~ 'x'", NULL, 0 },
+ { "ALL attribute = 'k1'", NULL, 2 },
{ "attribute['k1'] = 'v1'", NULL, 1 },
{ "attribute['k1'] =~ 'v1'", NULL, 1 },
{ "attribute['k1'] =~ '^v1$'", NULL, 1 },