From: Sebastian Harl Date: Tue, 4 Nov 2014 19:16:25 +0000 (+0100) Subject: frontend/grammar: Added support for FETCHing all object types. X-Git-Tag: sysdb-0.6.0~30 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=3eeb4d5791ab099796730f1696530bed9491760e;p=sysdb.git frontend/grammar: Added support for FETCHing all object types. --- diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index b400f9a..97be55d 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -158,7 +158,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg); %type expression -%type object_type_plural +%type object_type object_type_plural %type iterable %type field @@ -281,18 +281,27 @@ statement: * Retrieve detailed information about a single host. */ fetch_statement: - FETCH HOST_T STRING filter_clause + FETCH object_type STRING filter_clause { - /* TODO: support other types as well */ - $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, conn_fetch_t, conn_fetch_destroy)); - CONN_FETCH($$)->type = SDB_HOST; + CONN_FETCH($$)->type = $2; CONN_FETCH($$)->host = $3; CONN_FETCH($$)->name = NULL; CONN_FETCH($$)->filter = CONN_MATCHER($4); $$->cmd = CONNECTION_FETCH; } + | + FETCH object_type STRING '.' STRING filter_clause + { + $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, + conn_fetch_t, conn_fetch_destroy)); + CONN_FETCH($$)->type = $2; + CONN_FETCH($$)->host = $3; + CONN_FETCH($$)->name = $5; + CONN_FETCH($$)->filter = CONN_MATCHER($6); + $$->cmd = CONNECTION_FETCH; + } ; /* @@ -536,6 +545,14 @@ expression: } ; +object_type: + HOST_T { $$ = SDB_HOST; } + | + SERVICE_T { $$ = SDB_SERVICE; } + | + METRIC_T { $$ = SDB_METRIC; } + ; + object_type_plural: HOSTS_T { $$ = SDB_HOST; } | diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index d33917a..ec8264c 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -56,6 +56,10 @@ START_TEST(test_parse) { "FETCH host 'host'", -1, 1, CONNECTION_FETCH }, { "FETCH host 'host' FILTER " "age > 60s", -1, 1, CONNECTION_FETCH }, + { "FETCH service " + "'host'.'service'", -1, 1, CONNECTION_FETCH }, + { "FETCH metric " + "'host'.'metric'", -1, 1, CONNECTION_FETCH }, { "LIST hosts", -1, 1, CONNECTION_LIST }, { "LIST hosts -- foo", -1, 1, CONNECTION_LIST }, @@ -236,6 +240,10 @@ START_TEST(test_parse) "age > 60s", -1, -1, 0 }, { "FETCH host 'host' MATCHING " "host = 'host'", -1, -1, 0 }, + { "FETCH service 'host'",-1, -1, 0 }, + { "FETCH metric 'host'", -1, -1, 0 }, + { "FETCH host " + "'host'.'localhost'", -1, -1, 0 }, { "FETCH foo 'host'", -1, -1, 0 }, { "FETCH foo 'host' FILTER " "age > 60s", -1, -1, 0 },