summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8a9f437)
raw | patch | inline | side by side (parent: 8a9f437)
author | Sebastian Harl <sh@tokkee.org> | |
Tue, 30 Sep 2014 12:40:53 +0000 (05:40 -0700) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Tue, 30 Sep 2014 12:45:03 +0000 (05:45 -0700) |
When listing objects other than hosts, the returned JSON list will include the
respective type listed below each host object.
respective type listed below each host object.
index a874751299ea0818635c4e542705a6fea6bb8983..dd4bcced2b4c99fa63c781654218c1f68ff761d7 100644 (file)
typedef struct {
sdb_conn_node_t super;
+ int type;
conn_matcher_t *filter;
} conn_list_t;
#define CONN_LIST(obj) ((conn_list_t *)(obj))
diff --git a/src/frontend/grammar.y b/src/frontend/grammar.y
index 58363df01dbebe37b861394f09632d47397b850a..289d357f9239000dd6b099a58d80c9818b6b6f02 100644 (file)
--- a/src/frontend/grammar.y
+++ b/src/frontend/grammar.y
$$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
conn_list_t, conn_list_destroy));
+ CONN_LIST($$)->type = SDB_HOST;
CONN_LIST($$)->filter = CONN_MATCHER($3);
$$->cmd = CONNECTION_LIST;
free($2); $2 = NULL;
diff --git a/src/frontend/query.c b/src/frontend/query.c
index f55975edda8c55188410cfbfc68acab9d19dcd66..0ee734c4ee24428d98efa324b4a1237054fad62d 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
#include "frontend/connection-private.h"
#include "frontend/parser.h"
#include "utils/error.h"
+#include "utils/proto.h"
#include "utils/strbuf.h"
#include <errno.h>
int
sdb_fe_list(sdb_conn_t *conn)
{
+ int type = SDB_HOST;
+
if ((! conn) || (conn->cmd != CONNECTION_LIST))
return -1;
- return sdb_fe_exec_list(conn, /* filter = */ NULL);
+
+ if (conn->cmd_len == sizeof(uint32_t))
+ type = sdb_proto_get_int(conn->buf, 0);
+ else if (conn->cmd_len) {
+ sdb_log(SDB_LOG_ERR, "frontend: Invalid command length %d for "
+ "LIST command", conn->cmd_len);
+ sdb_strbuf_sprintf(conn->errbuf, "LIST: Invalid command length %d",
+ conn->cmd_len);
+ return -1;
+ }
+ return sdb_fe_exec_list(conn, type, /* filter = */ NULL);
} /* sdb_fe_list */
int
case CONNECTION_LIST:
if (CONN_LIST(node)->filter)
filter = CONN_LIST(node)->filter->matcher;
- return sdb_fe_exec_list(conn, filter);
+ return sdb_fe_exec_list(conn, CONN_LIST(node)->type, filter);
case CONNECTION_LOOKUP:
if (CONN_LOOKUP(node)->matcher)
m = CONN_LOOKUP(node)->matcher->matcher;
{
sdb_strbuf_t *buf;
sdb_store_obj_t *host;
- uint32_t type = htonl(CONNECTION_FETCH);
+ uint32_t res_type = htonl(CONNECTION_FETCH);
host = sdb_store_get_host(name);
if (! host) {
return -1;
}
- sdb_strbuf_memcpy(buf, &type, sizeof(uint32_t));
+ sdb_strbuf_memcpy(buf, &res_type, sizeof(uint32_t));
if (sdb_store_host_tojson(host, buf, filter, /* flags = */ 0)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to serialize "
"host '%s' to JSON", name);
} /* sdb_fe_exec_fetch */
int
-sdb_fe_exec_list(sdb_conn_t *conn, sdb_store_matcher_t *filter)
+sdb_fe_exec_list(sdb_conn_t *conn, int type, sdb_store_matcher_t *filter)
{
sdb_strbuf_t *buf;
- uint32_t type = htonl(CONNECTION_LIST);
+ uint32_t res_type = htonl(CONNECTION_LIST);
+
+ int flags;
+
+ if (type == SDB_HOST)
+ flags = SDB_SKIP_ALL;
+ else if (type == SDB_SERVICE)
+ flags = SDB_SKIP_ALL & (~SDB_SKIP_SERVICES);
+ else if (type == SDB_METRIC)
+ flags = SDB_SKIP_ALL & (~SDB_SKIP_METRICS);
+ else {
+ sdb_log(SDB_LOG_ERR, "frontend: Invalid object type %d "
+ "for LIST command", type);
+ sdb_strbuf_sprintf(conn->errbuf,
+ "LIST: Invalid object type %d", type);
+ return -1;
+ }
buf = sdb_strbuf_create(1024);
if (! buf) {
return -1;
}
- sdb_strbuf_memcpy(buf, &type, sizeof(uint32_t));
- if (sdb_store_tojson(buf, filter, /* flags = */ SDB_SKIP_ALL)) {
+ sdb_strbuf_memcpy(buf, &res_type, sizeof(uint32_t));
+ if (sdb_store_tojson(buf, filter, flags)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to serialize "
"store to JSON");
sdb_strbuf_sprintf(conn->errbuf, "Out of memory");
sdb_store_matcher_t *filter)
{
tojson_data_t data = { NULL, filter, 0 };
- uint32_t type = htonl(CONNECTION_LOOKUP);
+ uint32_t res_type = htonl(CONNECTION_LOOKUP);
data.buf = sdb_strbuf_create(1024);
if (! data.buf) {
return -1;
}
- sdb_strbuf_memcpy(data.buf, &type, sizeof(uint32_t));
+ sdb_strbuf_memcpy(data.buf, &res_type, sizeof(uint32_t));
sdb_strbuf_append(data.buf, "[");
/* Let the JSON serializer handle the filter instead of the scanner. Else,
sdb_timeseries_opts_t *opts)
{
sdb_strbuf_t *buf;
- uint32_t type = htonl(CONNECTION_TIMESERIES);
+ uint32_t res_type = htonl(CONNECTION_TIMESERIES);
buf = sdb_strbuf_create(1024);
if (! buf) {
return -1;
}
- sdb_strbuf_memcpy(buf, &type, sizeof(uint32_t));
+ sdb_strbuf_memcpy(buf, &res_type, sizeof(uint32_t));
if (sdb_store_fetch_timeseries(hostname, metric, opts, buf)) {
sdb_log(SDB_LOG_ERR, "frontend: Failed to fetch time-series");
sdb_strbuf_sprintf(conn->errbuf, "Failed to fetch time-series");
index e963c94e58d0b7f30aa445b38504cdf3a554fbcd..8189470d4347721dab0aebeeb526e0e32ec90e07 100644 (file)
/*
* sdb_fe_exec_list:
* Execute the 'LIST' command. Send a complete listing of the store,
- * serialized as JSON, to the client. If specified, only objects matching the
- * filter will be included. See sdb_store_tojson for details.
+ * serialized as JSON, to the client. The listing includes all hosts and the
+ * specified object type. If specified, only objects matching the filter will
+ * be included. See sdb_store_tojson for details.
*
* Returns:
* - 0 on success
* - a negative value else
*/
int
-sdb_fe_exec_list(sdb_conn_t *conn, sdb_store_matcher_t *filter);
+sdb_fe_exec_list(sdb_conn_t *conn, int type, sdb_store_matcher_t *filter);
/*
* sdb_fe_exec_lookup:
index 91dd3609ce4307de6ff8ae54a01f68dfbbd2055b..de45f736b02b310e69b6aac0e45cb4c530eb19fb 100644 (file)
/*
* CONNECTION_LIST:
- * Execute the 'LIST' command in the server.
+ * Execute the 'LIST' command in the server. The message body may include
+ * the type of the objects to be included in addition to all hosts,
+ * encoded as a 32bit integer in network byte-order.
*/
CONNECTION_LIST,