From: Sebastian Harl Date: Tue, 30 Sep 2014 12:44:07 +0000 (-0700) Subject: frontend/grammar: Added support for LISTing services and metrics. X-Git-Tag: sysdb-0.5.0~24 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=6330f15bb3b4be4826a50ab6ec2d70e248198f03;p=sysdb.git frontend/grammar: Added support for LISTing services and metrics. --- diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y index 289d357..129b461 100644 --- a/src/frontend/grammar.y +++ b/src/frontend/grammar.y @@ -249,8 +249,8 @@ fetch_statement: list_statement: LIST IDENTIFIER filter_clause { - /* TODO: support other types as well */ - if (strcasecmp($2, "hosts")) { + int type = sdb_store_parse_object_type_plural($2); + if (type < 0) { char errmsg[strlen($2) + 32]; snprintf(errmsg, sizeof(errmsg), YY_("unknown data-source %s"), $2); @@ -262,7 +262,7 @@ list_statement: $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL, conn_list_t, conn_list_destroy)); - CONN_LIST($$)->type = SDB_HOST; + CONN_LIST($$)->type = type; CONN_LIST($$)->filter = CONN_MATCHER($3); $$->cmd = CONNECTION_LIST; free($2); $2 = NULL; diff --git a/t/integration/simple_query.sh b/t/integration/simple_query.sh index 8a0a92a..900db90 100755 --- a/t/integration/simple_query.sh +++ b/t/integration/simple_query.sh @@ -70,6 +70,20 @@ echo "$output" \ | grep -F '"other.host.name"' \ | grep -F '"some.host.name"' +output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST services' )" +echo "$output" \ + | grep -F '"host1.example.com"' \ + | grep -F '"host2.example.com"' \ + | grep -F '"localhost"' \ + | grep -F '"other.host.name"' \ + | grep -F '"some.host.name"' \ + | grep -F '"mock service"' \ + | grep -F '"other service"' \ + | grep -F '"database"' \ + | grep -F '"example service one"' \ + | grep -F '"example service two"' \ + | grep -F '"example service three"' + output="$( run_sysdb -H "$SOCKET_FILE" -c "FETCH host 'host1.example.com'" )" echo "$output" \ | grep -F '"host1.example.com"' \ diff --git a/t/unit/frontend/parser_test.c b/t/unit/frontend/parser_test.c index bcd46af..4ee4d2f 100644 --- a/t/unit/frontend/parser_test.c +++ b/t/unit/frontend/parser_test.c @@ -62,6 +62,12 @@ START_TEST(test_parse) { "LIST hosts; INVALID", 11, 1, CONNECTION_LIST }, { "LIST hosts FILTER " "host = 'host'", -1, 1, CONNECTION_LIST }, + { "LIST services", -1, 1, CONNECTION_LIST }, + { "LIST services FILTER " + "service = 'svc'", -1, 1, CONNECTION_LIST }, + { "LIST metrics", -1, 1, CONNECTION_LIST }, + { "LIST metrics FILTER " + "metric = 'metric'", -1, 1, CONNECTION_LIST }, { "LOOKUP hosts", -1, 1, CONNECTION_LOOKUP }, { "LOOKUP hosts MATCHING "