Code

frontend/grammar: Added support for LISTing services and metrics.
authorSebastian Harl <sh@tokkee.org>
Tue, 30 Sep 2014 12:44:07 +0000 (05:44 -0700)
committerSebastian Harl <sh@tokkee.org>
Tue, 30 Sep 2014 12:45:10 +0000 (05:45 -0700)
src/frontend/grammar.y
t/integration/simple_query.sh
t/unit/frontend/parser_test.c

index 289d357f9239000dd6b099a58d80c9818b6b6f02..129b4613009c9d5fc12aa71d2a470c0b02feed31 100644 (file)
@@ -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;
index 8a0a92ac67a0c92e9b0f8ff122c2b71ab46136cb..900db90c01519c00c93095fd5eae902c0a906a93 100755 (executable)
@@ -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"' \
index bcd46af274c6bddd8a1d2bc6bbf8db27fcf9b2a0..4ee4d2ff621b63d43afc928e0bb0be6b74aab673 100644 (file)
@@ -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 "