summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bdc8399)
raw | patch | inline | side by side (parent: bdc8399)
author | Sebastian Harl <sh@tokkee.org> | |
Wed, 16 Sep 2015 19:33:05 +0000 (21:33 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Wed, 16 Sep 2015 19:33:05 +0000 (21:33 +0200) |
That is, let the respective sdb_plugin_store* functions do that instead of
requiring each store implementation to do so.
requiring each store implementation to do so.
src/core/plugin.c | patch | blob | history | |
src/core/store.c | patch | blob | history | |
t/unit/core/store_expr_test.c | patch | blob | history | |
t/unit/core/store_json_test.c | patch | blob | history |
diff --git a/src/core/plugin.c b/src/core/plugin.c
index 235b8c7721ba97d08dc1b165c6ac0812ed7c6292..54f3f7f09f7f39f20c17fb0856db21df4fbd3e7d 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
sdb_plugin_store_service(const char *hostname, const char *name,
sdb_time_t last_update)
{
- char *cname;
-
sdb_llist_iter_t *iter;
+ sdb_data_t d;
+
+ char *cname;
int status = 0;
if ((! hostname) || (! name))
status = s;
}
sdb_llist_iter_destroy(iter);
+
+ if (! status) {
+ /* record the hostname as an attribute */
+ d.type = SDB_TYPE_STRING;
+ d.data.string = cname;
+ if (sdb_plugin_store_service_attribute(cname, name,
+ "hostname", &d, last_update))
+ status = -1;
+ }
+
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;
+ sdb_data_t d;
+
+ char *cname;
int status = 0;
if ((! hostname) || (! name))
status = s;
}
sdb_llist_iter_destroy(iter);
+
+ if (! status) {
+ /* record the hostname as an attribute */
+ d.type = SDB_TYPE_STRING;
+ d.data.string = cname;
+ if (sdb_plugin_store_metric_attribute(cname, name,
+ "hostname", &d, last_update))
+ status = -1;
+ }
+
free(cname);
return status;
} /* sdb_plugin_store_metric */
diff --git a/src/core/store.c b/src/core/store.c
index be8f9fa259406af1e31a2783560da81ca21776de..30b4d1c367cdc845714c98550501da3c1037f540 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
sdb_host_t *host;
sdb_avltree_t *services;
- sdb_data_t d;
int status = 0;
sdb_object_deref(SDB_OBJ(host));
pthread_rwlock_unlock(&st->host_lock);
-
- if (status)
- return status;
-
- /* record the hostname as an attribute */
- d.type = SDB_TYPE_STRING;
- d.data.string = SDB_OBJ(host)->name;
- if (store_service_attr(hostname, name, "hostname", &d, last_update, user_data))
- status = -1;
return status;
} /* store_service */
sdb_store_obj_t *obj = NULL;
sdb_host_t *host;
sdb_metric_t *metric;
- sdb_data_t d;
sdb_avltree_t *metrics;
if (store_metric_store(metric, store))
status = -1;
pthread_rwlock_unlock(&st->host_lock);
-
- /* record the hostname as an attribute */
- d.type = SDB_TYPE_STRING;
- d.data.string = SDB_OBJ(host)->name;
- if (store_metric_attr(hostname, name, "hostname", &d, last_update, user_data))
- status = -1;
return status;
} /* store_metric */
index d11452ae72dc072e0c5fac7330fd4b29b18e4969..3f21a82f9f21952dd684a6361d13deefac662aae 100644 (file)
# include "config.h"
#endif
-#include "core/plugin.h"
#include "core/store.h"
#include "core/store-private.h"
#include "parser/parser.h"
{ SDB_OBJECT_INIT, TYPED_EXPR, -1, &namer, NULL, ATTRS }, true,
"a", SDB_SERVICE, "s1", NULL,
{
- { SDB_TYPE_STRING, { .string = "hostname" } },
{ SDB_TYPE_STRING, { .string = "k1" } },
{ 0 },
{ 0 },
{ 0 },
- }, 2,
+ { 0 },
+ }, 1,
},
{
{ SDB_OBJECT_INIT, TYPED_EXPR, -1, &namer, NULL, ATTRS }, true,
"a", SDB_SERVICE, "s1", "age >= 0s",
{
- { SDB_TYPE_STRING, { .string = "hostname" } },
{ SDB_TYPE_STRING, { .string = "k1" } },
{ 0 },
{ 0 },
{ 0 },
- }, 2,
+ { 0 },
+ }, 1,
},
{
{ SDB_OBJECT_INIT, TYPED_EXPR, -1, &namer, NULL, ATTRS }, true,
{ SDB_OBJECT_INIT, TYPED_EXPR, -1, &namer, NULL, ATTRS }, true,
"b", SDB_METRIC, "m2", NULL,
{
- { SDB_TYPE_STRING, { .string = "hostname" } },
{ SDB_TYPE_STRING, { .string = "k1" } },
{ SDB_TYPE_STRING, { .string = "k2" } },
{ 0 },
{ 0 },
- }, 3,
+ { 0 },
+ }, 2,
},
{
{ SDB_OBJECT_INIT, TYPED_EXPR, -1, &namer, NULL, ATTRS }, true,
"b", SDB_METRIC, "m2", "age >= 0s",
{
- { SDB_TYPE_STRING, { .string = "hostname" } },
{ SDB_TYPE_STRING, { .string = "k1" } },
{ SDB_TYPE_STRING, { .string = "k2" } },
{ 0 },
{ 0 },
- }, 3,
+ { 0 },
+ }, 2,
},
{
{ SDB_OBJECT_INIT, TYPED_EXPR, -1, &namer, NULL, ATTRS }, true,
index d887c439f0bddbb4c21572402d27e9d490245d24..f8ebac913633fe025df01344c2e2ecab521874cc 100644 (file)
# include "config.h"
#endif
-#include "core/plugin.h"
#include "core/store.h"
#include "testutils.h"
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h1\", "
- "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"k3\", \"value\": 42, "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"{\"name\": \"m2\", "
"\"timeseries\": false, "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h1\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]}"
+ "\"update_interval\": \"0s\", \"backends\": []}"
"]},"
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"{\"name\": \"m1\", "
"\"timeseries\": false, "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]}"
+ "\"update_interval\": \"0s\", \"backends\": []}"
"], "
"\"services\": ["
"{\"name\": \"s1\", "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]},"
+ "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"s2\", "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"k1\", \"value\": 123, "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []},"
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"k1\", \"value\": 123, "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"{\"name\": \"m2\", "
"\"timeseries\": false, "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h1\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]}"
+ "\"update_interval\": \"0s\", \"backends\": []}"
"]}"
"]" },
{ { sdb_store_ge_matcher, SDB_FIELD_LAST_UPDATE,
"\"services\": ["
"{\"name\": \"s1\", "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]},"
+ "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"s2\", "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"k1\", \"value\": 123, "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []},"
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"k1\", \"value\": 123, "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h1\", "
- "\"last_update\": \"1970-01-01 00:00:02 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []},"
"{\"name\": \"k3\", \"value\": 42, "
"\"last_update\": \"1970-01-01 00:00:02 +0000\", "
"\"update_interval\": \"0s\", \"backends\": []}"
"{\"name\": \"m2\", "
"\"timeseries\": false, "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h1\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]}"
+ "\"update_interval\": \"0s\", \"backends\": []}"
"]},"
"{\"name\": \"h2\", \"last_update\": \"1970-01-01 00:00:03 +0000\", "
"\"update_interval\": \"0s\", \"backends\": [], "
"{\"name\": \"m1\", "
"\"timeseries\": false, "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h2\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]}"
+ "\"update_interval\": \"0s\", \"backends\": []}"
"]}"
"]" },
{ { NULL, 0, SDB_DATA_INIT },
"{\"name\": \"m2\", "
"\"timeseries\": false, "
"\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": [], "
- "\"attributes\": ["
- "{\"name\": \"hostname\", \"value\": \"h1\", "
- "\"last_update\": \"1970-01-01 00:00:01 +0000\", "
- "\"update_interval\": \"0s\", \"backends\": []}"
- "]}"
+ "\"update_interval\": \"0s\", \"backends\": []}"
"]}"
"]" },
{ { sdb_store_lt_matcher, SDB_FIELD_LAST_UPDATE,