Code

frontend/grammar: Added support for FETCHing all object types.
authorSebastian Harl <sh@tokkee.org>
Tue, 4 Nov 2014 19:16:25 +0000 (20:16 +0100)
committerSebastian Harl <sh@tokkee.org>
Tue, 4 Nov 2014 19:16:25 +0000 (20:16 +0100)
src/frontend/grammar.y
t/unit/frontend/parser_test.c

index b400f9acc51736fc43ebed4cb7a02ea6b03036af..97be55d0c7dfa5b397fade235888bafe4f505a27 100644 (file)
@@ -158,7 +158,7 @@ sdb_fe_yyerror(YYLTYPE *lval, sdb_fe_yyscan_t scanner, const char *msg);
 
 %type <expr> expression
 
-%type <integer> object_type_plural
+%type <integer> object_type object_type_plural
 %type <integer> iterable
 %type <integer> 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; }
        |
index d33917a3bd4311b1f6fdf78d67057f8597f95bae..ec8264c82b6c495bd1e9ff2f0a250d7e32cc8280 100644 (file)
@@ -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 },