summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 01c3fd2)
raw | patch | inline | side by side (parent: 01c3fd2)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 12 Aug 2015 19:55:41 +0000 (21:55 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 12 Aug 2015 19:55:41 +0000 (21:55 +0200) |
This is a high-level functionality. Each store implementation should not have
to worry about it.
to worry about it.
src/core/plugin.c | patch | blob | history | |
src/core/store.c | patch | blob | history | |
src/include/core/store.h | patch | blob | history |
diff --git a/src/core/plugin.c b/src/core/plugin.c
index da8a485b960a4786b914102e9f9fbc741378170a..6b1560336b311a659c35566333d78a147d8d39c2 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
@@ -1459,6 +1459,8 @@ sdb_plugin_query(sdb_ast_node_t *ast, sdb_strbuf_t *buf, sdb_strbuf_t *errbuf)
int
sdb_plugin_store_host(const char *name, sdb_time_t last_update)
{
+ char *cname;
+
sdb_llist_iter_t *iter;
int status = 0;
return -1;
}
+ cname = sdb_plugin_cname(strdup(name));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "core: strdup failed");
+ return -1;
+ }
+
iter = sdb_llist_get_iter(writer_list);
while (sdb_llist_iter_has_next(iter)) {
writer_t *writer = WRITER(sdb_llist_iter_get_next(iter));
int s;
assert(writer);
- s = writer->impl.store_host(name, last_update, writer->w_user_data);
+ s = writer->impl.store_host(cname, last_update, writer->w_user_data);
if (((s > 0) && (status >= 0)) || (s < 0))
status = s;
}
sdb_llist_iter_destroy(iter);
+ free(cname);
return status;
} /* sdb_plugin_store_host */
sdb_plugin_store_service(const char *hostname, const char *name,
sdb_time_t last_update)
{
+ char *cname;
+
sdb_llist_iter_t *iter;
int status = 0;
return -1;
}
+ cname = sdb_plugin_cname(strdup(hostname));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "core: strdup failed");
+ return -1;
+ }
+
iter = sdb_llist_get_iter(writer_list);
while (sdb_llist_iter_has_next(iter)) {
writer_t *writer = WRITER(sdb_llist_iter_get_next(iter));
int s;
assert(writer);
- s = writer->impl.store_service(hostname, name, last_update,
+ s = writer->impl.store_service(cname, name, last_update,
writer->w_user_data);
if (((s > 0) && (status >= 0)) || (s < 0))
status = s;
}
sdb_llist_iter_destroy(iter);
+ free(cname);
return status;
} /* sdb_plugin_store_service */
sdb_plugin_store_metric(const char *hostname, const char *name,
sdb_metric_store_t *store, sdb_time_t last_update)
{
+ char *cname;
+
sdb_llist_iter_t *iter;
int status = 0;
return -1;
}
+ cname = sdb_plugin_cname(strdup(hostname));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "core: strdup failed");
+ return -1;
+ }
+
if (store && ((! store->type) || (! store->id)))
store = NULL;
writer_t *writer = WRITER(sdb_llist_iter_get_next(iter));
int s;
assert(writer);
- s = writer->impl.store_metric(hostname, name, store, last_update,
+ s = writer->impl.store_metric(cname, name, store, last_update,
writer->w_user_data);
if (((s > 0) && (status >= 0)) || (s < 0))
status = s;
}
sdb_llist_iter_destroy(iter);
+ free(cname);
return status;
} /* sdb_plugin_store_metric */
sdb_plugin_store_attribute(const char *hostname, const char *key,
const sdb_data_t *value, sdb_time_t last_update)
{
+ char *cname;
+
sdb_llist_iter_t *iter;
int status = 0;
return -1;
}
+ cname = sdb_plugin_cname(strdup(hostname));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "core: strdup failed");
+ return -1;
+ }
+
iter = sdb_llist_get_iter(writer_list);
while (sdb_llist_iter_has_next(iter)) {
writer_t *writer = WRITER(sdb_llist_iter_get_next(iter));
int s;
assert(writer);
- s = writer->impl.store_attribute(hostname, key, value, last_update,
+ s = writer->impl.store_attribute(cname, key, value, last_update,
writer->w_user_data);
if (((s > 0) && (status >= 0)) || (s < 0))
status = s;
}
sdb_llist_iter_destroy(iter);
+ free(cname);
return status;
} /* sdb_plugin_store_attribute */
sdb_plugin_store_service_attribute(const char *hostname, const char *service,
const char *key, const sdb_data_t *value, sdb_time_t last_update)
{
+ char *cname;
+
sdb_llist_iter_t *iter;
int status = 0;
@@ -1593,17 +1631,24 @@ sdb_plugin_store_service_attribute(const char *hostname, const char *service,
return -1;
}
+ cname = sdb_plugin_cname(strdup(hostname));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "core: strdup failed");
+ return -1;
+ }
+
iter = sdb_llist_get_iter(writer_list);
while (sdb_llist_iter_has_next(iter)) {
writer_t *writer = WRITER(sdb_llist_iter_get_next(iter));
int s;
assert(writer);
- s = writer->impl.store_service_attr(hostname, service,
+ s = writer->impl.store_service_attr(cname, service,
key, value, last_update, writer->w_user_data);
if (((s > 0) && (status >= 0)) || (s < 0))
status = s;
}
sdb_llist_iter_destroy(iter);
+ free(cname);
return status;
} /* sdb_plugin_store_service_attribute */
sdb_plugin_store_metric_attribute(const char *hostname, const char *metric,
const char *key, const sdb_data_t *value, sdb_time_t last_update)
{
+ char *cname;
+
sdb_llist_iter_t *iter;
int status = 0;
return -1;
}
+ cname = sdb_plugin_cname(strdup(hostname));
+ if (! cname) {
+ sdb_log(SDB_LOG_ERR, "core: strdup failed");
+ return -1;
+ }
+
iter = sdb_llist_get_iter(writer_list);
while (sdb_llist_iter_has_next(iter)) {
writer_t *writer = WRITER(sdb_llist_iter_get_next(iter));
int s;
assert(writer);
- s = writer->impl.store_metric_attr(hostname, metric,
+ s = writer->impl.store_metric_attr(cname, metric,
key, value, last_update, writer->w_user_data);
if (((s > 0) && (status >= 0)) || (s < 0))
status = s;
}
sdb_llist_iter_destroy(iter);
+ free(cname);
return status;
} /* sdb_plugin_store_metric_attribute */
diff --git a/src/core/store.c b/src/core/store.c
index bea4d2b578c421ed7706791e2aee0db95524de96..498217b394c092ce1a356a98d1f31e7bcffcdc3f 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 1);
+ host = lookup_host(st, hostname, /* canonicalize = */ 0);
attrs = get_host_children(host, SDB_ATTRIBUTE);
if (! attrs) {
sdb_log(SDB_LOG_ERR, "store: Failed to store attribute '%s' - "
store_host(const char *name, sdb_time_t last_update, sdb_object_t *user_data)
{
sdb_store_t *st = SDB_STORE(user_data);
-
- char *cname = NULL;
int status = 0;
if (! name)
return -1;
- cname = sdb_plugin_cname(strdup(name));
- if (! cname) {
- sdb_log(SDB_LOG_ERR, "store: strdup failed");
- return -1;
- }
-
pthread_rwlock_wrlock(&st->host_lock);
status = store_obj(NULL, st->hosts,
- SDB_HOST, cname, last_update, NULL);
+ SDB_HOST, name, last_update, NULL);
pthread_rwlock_unlock(&st->host_lock);
- free(cname);
return status;
} /* store_host */
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 1);
+ host = lookup_host(st, hostname, /* canonicalize = */ 0);
services = get_host_children(host, SDB_SERVICE);
sdb_object_deref(SDB_OBJ(host));
if (! services) {
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 1);
+ host = lookup_host(st, hostname, /* canonicalize = */ 0);
services = get_host_children(host, SDB_SERVICE);
if (! services) {
sdb_log(SDB_LOG_ERR, "store: Failed to store service '%s' - "
return -1;
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 1);
+ host = lookup_host(st, hostname, /* canonicalize = */ 0);
metrics = get_host_children(host, SDB_METRIC);
sdb_object_deref(SDB_OBJ(host));
if (! metrics) {
}
pthread_rwlock_wrlock(&st->host_lock);
- host = lookup_host(st, hostname, /* canonicalize = */ 1);
+ host = lookup_host(st, hostname, /* canonicalize = */ 0);
metrics = get_host_children(host, SDB_METRIC);
if (! metrics) {
sdb_log(SDB_LOG_ERR, "store: Failed to store metric '%s' - "
index 16a094adbf8e347b9278d94142a3ff4d0242632b..28b257e056b10f6912b793c95ee592afba6ed59d 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
/*
* sdb_store_host, sdb_store_service, sdb_store_metric, sdb_store_attribute,
* sdb_store_metric_attr:
- * Store an object in the specified store.
+ * Store an object in the specified store. The hostname is expected to be
+ * canonical.
*/
int
sdb_store_host(sdb_store_t *store, const char *name, sdb_time_t last_update);