diff --git a/src/frontend/query.c b/src/frontend/query.c
index 1c5b1f293b76b83bff5f39dfde1b5baf0edcb5bd..2c80be76f84f5ee8ca98560cebf293219c238e31 100644 (file)
--- a/src/frontend/query.c
+++ b/src/frontend/query.c
sdb_fe_fetch(sdb_conn_t *conn)
{
char name[conn->cmd_len + 1];
sdb_fe_fetch(sdb_conn_t *conn)
{
char name[conn->cmd_len + 1];
- int type;
+ uint32_t type;
if ((! conn) || (conn->cmd != SDB_CONNECTION_FETCH))
return -1;
if ((! conn) || (conn->cmd != SDB_CONNECTION_FETCH))
return -1;
return -1;
}
return -1;
}
- type = sdb_proto_unmarshal_int(SDB_STRBUF_STR(conn->buf));
+ sdb_proto_unmarshal_int32(SDB_STRBUF_STR(conn->buf), &type);
strncpy(name, sdb_strbuf_string(conn->buf) + sizeof(uint32_t),
conn->cmd_len - sizeof(uint32_t));
name[sizeof(name) - 1] = '\0';
/* TODO: support other types besides hosts */
strncpy(name, sdb_strbuf_string(conn->buf) + sizeof(uint32_t),
conn->cmd_len - sizeof(uint32_t));
name[sizeof(name) - 1] = '\0';
/* TODO: support other types besides hosts */
- return sdb_fe_exec_fetch(conn, type, name, NULL, /* filter = */ NULL);
+ return sdb_fe_exec_fetch(conn, (int)type, name, NULL, /* filter = */ NULL);
} /* sdb_fe_fetch */
int
sdb_fe_list(sdb_conn_t *conn)
{
} /* sdb_fe_fetch */
int
sdb_fe_list(sdb_conn_t *conn)
{
- int type = SDB_HOST;
+ uint32_t type = SDB_HOST;
if ((! conn) || (conn->cmd != SDB_CONNECTION_LIST))
return -1;
if (conn->cmd_len == sizeof(uint32_t))
if ((! conn) || (conn->cmd != SDB_CONNECTION_LIST))
return -1;
if (conn->cmd_len == sizeof(uint32_t))
- type = sdb_proto_unmarshal_int(SDB_STRBUF_STR(conn->buf));
+ sdb_proto_unmarshal_int32(SDB_STRBUF_STR(conn->buf), &type);
else if (conn->cmd_len) {
sdb_log(SDB_LOG_ERR, "frontend: Invalid command length %d for "
"LIST command", conn->cmd_len);
else if (conn->cmd_len) {
sdb_log(SDB_LOG_ERR, "frontend: Invalid command length %d for "
"LIST command", conn->cmd_len);
conn->cmd_len);
return -1;
}
conn->cmd_len);
return -1;
}
- return sdb_fe_exec_list(conn, type, /* filter = */ NULL);
+ return sdb_fe_exec_list(conn, (int)type, /* filter = */ NULL);
} /* sdb_fe_list */
int
} /* sdb_fe_list */
int
const char *matcher;
size_t matcher_len;
const char *matcher;
size_t matcher_len;
- int type;
+ uint32_t type;
int status;
conn_matcher_t m_node = {
int status;
conn_matcher_t m_node = {
conn->cmd_len);
return -1;
}
conn->cmd_len);
return -1;
}
- type = sdb_proto_unmarshal_int(SDB_STRBUF_STR(conn->buf));
+ sdb_proto_unmarshal_int32(SDB_STRBUF_STR(conn->buf), &type);
matcher = sdb_strbuf_string(conn->buf) + sizeof(uint32_t);
matcher_len = conn->cmd_len - sizeof(uint32_t);
matcher = sdb_strbuf_string(conn->buf) + sizeof(uint32_t);
matcher_len = conn->cmd_len - sizeof(uint32_t);
return -1;
}
return -1;
}
- node.type = type;
+ node.type = (int)type;
m_node.matcher = m;
/* run analyzer separately; parse_matcher is missing
m_node.matcher = m;
/* run analyzer separately; parse_matcher is missing
status = -1;
}
else
status = -1;
}
else
- status = sdb_fe_exec_lookup(conn, type, m, /* filter = */ NULL);
+ status = sdb_fe_exec_lookup(conn, (int)type, m, /* filter = */ NULL);
sdb_object_deref(SDB_OBJ(m));
return status;
} /* sdb_fe_lookup */
sdb_object_deref(SDB_OBJ(m));
return status;
} /* sdb_fe_lookup */
filter = CONN_LOOKUP(node)->filter->matcher;
return sdb_fe_exec_lookup(conn,
CONN_LOOKUP(node)->type, m, filter);
filter = CONN_LOOKUP(node)->filter->matcher;
return sdb_fe_exec_lookup(conn,
CONN_LOOKUP(node)->type, m, filter);
+ case SDB_CONNECTION_STORE_HOST:
+ {
+ conn_store_host_t *n = CONN_STORE_HOST(node);
+ sdb_proto_host_t host = { n->last_update, n->name };
+ return sdb_fe_store_host(conn, &host);
+ }
+ case SDB_CONNECTION_STORE_SERVICE:
+ {
+ conn_store_svc_t *n = CONN_STORE_SVC(node);
+ sdb_proto_service_t svc = { n->last_update, n->hostname, n->name };
+ return sdb_fe_store_service(conn, &svc);
+ }
+ case SDB_CONNECTION_STORE_METRIC:
+ {
+ conn_store_metric_t *n = CONN_STORE_METRIC(node);
+ sdb_proto_metric_t metric = {
+ n->last_update, n->hostname, n->name,
+ n->store_type, n->store_id
+ };
+ return sdb_fe_store_metric(conn, &metric);
+ }
+ case SDB_CONNECTION_STORE_ATTRIBUTE:
+ {
+ conn_store_attr_t *n = CONN_STORE_ATTR(node);
+ sdb_proto_attribute_t attr = {
+ n->last_update, n->parent_type, n->hostname, n->parent,
+ n->key, n->value
+ };
+ return sdb_fe_store_attribute(conn, &attr);
+ }
case SDB_CONNECTION_TIMESERIES:
return sdb_fe_exec_timeseries(conn,
CONN_TS(node)->hostname, CONN_TS(node)->metric,
case SDB_CONNECTION_TIMESERIES:
return sdb_fe_exec_timeseries(conn,
CONN_TS(node)->hostname, CONN_TS(node)->metric,
SDB_STORE_TYPE_TO_NAME(type), hostname, name);
return -1;
}
SDB_STORE_TYPE_TO_NAME(type), hostname, name);
return -1;
}
+ if (type == SDB_HOST)
+ name = hostname;
host = sdb_store_get_host(hostname);
if ((! host) || (filter
host = sdb_store_get_host(hostname);
if ((! host) || (filter
sdb_strbuf_sprintf(conn->errbuf, "Failed to fetch %s %s: "
"host %s not found", SDB_STORE_TYPE_TO_NAME(type),
name, hostname);
sdb_strbuf_sprintf(conn->errbuf, "Failed to fetch %s %s: "
"host %s not found", SDB_STORE_TYPE_TO_NAME(type),
name, hostname);
+ sdb_object_deref(SDB_OBJ(host));
return -1;
}
if (type == SDB_HOST) {
return -1;
}
if (type == SDB_HOST) {
sdb_strbuf_sprintf(conn->errbuf, "Failed to fetch %s %s.%s: "
"%s not found", SDB_STORE_TYPE_TO_NAME(type),
hostname, name, name);
sdb_strbuf_sprintf(conn->errbuf, "Failed to fetch %s %s.%s: "
"%s not found", SDB_STORE_TYPE_TO_NAME(type),
hostname, name, name);
+ if (obj)
+ sdb_object_deref(SDB_OBJ(obj));
+ sdb_object_deref(SDB_OBJ(host));
return -1;
}
sdb_object_deref(SDB_OBJ(host));
}
return -1;
}
sdb_object_deref(SDB_OBJ(host));
}
+ host = NULL;
buf = sdb_strbuf_create(1024);
if (! buf) {
buf = sdb_strbuf_create(1024);
if (! buf) {