X-Git-Url: https://git.tokkee.org/?p=sysdb.git;a=blobdiff_plain;f=src%2Fcore%2Fstore_exec.c;h=ee1f8d046f47ad49768c4aa2a2b89a0bff9bbd80;hp=5daaa143105558c133f6649d8d44e7c24e0f9307;hb=6f4b7e7407964b05477416d1c1c4291421a5859a;hpb=089035fbe3345ebaaae1155a9301f43d1aef879c diff --git a/src/core/store_exec.c b/src/core/store_exec.c index 5daaa14..ee1f8d0 100644 --- a/src/core/store_exec.c +++ b/src/core/store_exec.c @@ -35,7 +35,6 @@ #include #include -#include #include #include @@ -60,12 +59,6 @@ lookup_tojson(sdb_store_obj_t *obj, sdb_store_matcher_t *filter, return sdb_store_json_emit_full(f, obj, filter); } /* lookup_tojson */ -static size_t -sstrlen(const char *s) -{ - return s ? strlen(s) : 0; -} /* sstrlen */ - /* * query implementations */ @@ -219,91 +212,6 @@ exec_lookup(sdb_store_t *store, sdb_strbuf_t *buf, sdb_strbuf_t *errbuf, return SDB_CONNECTION_DATA; } /* exec_lookup */ -static int -exec_store(sdb_strbuf_t *buf, sdb_strbuf_t *errbuf, sdb_ast_store_t *st) -{ - char name[sstrlen(st->hostname) + sstrlen(st->parent) + sstrlen(st->name) + 3]; - sdb_metric_store_t metric_store; - int type = st->obj_type, status = -1; - - switch (st->obj_type) { - case SDB_HOST: - strncpy(name, st->name, sizeof(name)); - status = sdb_plugin_store_host(st->name, st->last_update); - break; - - case SDB_SERVICE: - snprintf(name, sizeof(name), "%s.%s", st->hostname, st->name); - status = sdb_plugin_store_service(st->hostname, st->name, st->last_update); - break; - - case SDB_METRIC: - snprintf(name, sizeof(name), "%s.%s", st->hostname, st->name); - metric_store.type = st->store_type; - metric_store.id = st->store_id; - status = sdb_plugin_store_metric(st->hostname, st->name, - &metric_store, st->last_update); - break; - - case SDB_ATTRIBUTE: - type |= st->parent_type; - - if (st->parent) - snprintf(name, sizeof(name), "%s.%s.%s", - st->hostname, st->parent, st->name); - else - snprintf(name, sizeof(name), "%s.%s", st->hostname, st->name); - - switch (st->parent_type) { - case 0: - type |= SDB_HOST; - status = sdb_plugin_store_attribute(st->hostname, - st->name, &st->value, st->last_update); - break; - - case SDB_SERVICE: - status = sdb_plugin_store_service_attribute(st->hostname, st->parent, - st->name, &st->value, st->last_update); - break; - - case SDB_METRIC: - status = sdb_plugin_store_metric_attribute(st->hostname, st->parent, - st->name, &st->value, st->last_update); - break; - - default: - sdb_log(SDB_LOG_ERR, "store: Invalid parent type in STORE: %s", - SDB_STORE_TYPE_TO_NAME(st->parent_type)); - return -1; - } - break; - - default: - sdb_log(SDB_LOG_ERR, "store: Invalid object type in STORE: %s", - SDB_STORE_TYPE_TO_NAME(st->obj_type)); - return -1; - } - - if (status < 0) { - sdb_strbuf_sprintf(errbuf, "STORE: Failed to store %s object", - SDB_STORE_TYPE_TO_NAME(type)); - return -1; - } - - if (! status) { - sdb_strbuf_sprintf(buf, "Successfully stored %s %s", - SDB_STORE_TYPE_TO_NAME(type), name); - } - else { - char type_str[32]; - strncpy(type_str, SDB_STORE_TYPE_TO_NAME(type), sizeof(type_str)); - type_str[0] = (char)toupper((int)type_str[0]); - sdb_strbuf_sprintf(buf, "%s %s already up to date", type_str, name); - } - - return SDB_CONNECTION_OK; -} /* exec_store */ - static int exec_timeseries(sdb_store_t *store, sdb_strbuf_t *buf, sdb_strbuf_t *errbuf, const char *hostname, const char *metric, @@ -354,14 +262,6 @@ sdb_store_query_execute(sdb_store_t *store, sdb_store_query_t *q, return exec_lookup(store, buf, errbuf, SDB_AST_LOOKUP(ast)->obj_type, q->matcher, q->filter); - case SDB_AST_TYPE_STORE: - if (ast->type != SDB_AST_TYPE_STORE) { - sdb_log(SDB_LOG_ERR, "store: Invalid AST node for STORE command: %s", - SDB_AST_TYPE_TO_STRING(ast)); - return -1; - } - return exec_store(buf, errbuf, SDB_AST_STORE(ast)); - case SDB_AST_TYPE_TIMESERIES: ts_opts.start = SDB_AST_TIMESERIES(ast)->start; ts_opts.end = SDB_AST_TIMESERIES(ast)->end;