summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e045343)
raw | patch | inline | side by side (parent: e045343)
author | Sebastian Harl <sh@tokkee.org> | |
Thu, 21 May 2015 22:47:24 +0000 (00:47 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Thu, 21 May 2015 22:47:24 +0000 (00:47 +0200) |
That is, all store updates will now directly go through the plugin API and be
distributed to all store-writer plugins from there.
distributed to all store-writer plugins from there.
13 files changed:
diff --git a/src/core/store.c b/src/core/store.c
index 1396669e4b58e53dd427f76ec5119f1ab1d7d669..22e965ff1858c9891cbf862e3f1af7e91d50a6c8 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
sdb_avltree_clear(global_store->hosts);
} /* sdb_store_clear */
-int
-sdb_store_host(const char *name, sdb_time_t last_update)
-{
- return sdb_plugin_store_host(name, last_update);
-} /* sdb_store_host */
-
-int
-sdb_store_attribute(const char *hostname,
- const char *key, const sdb_data_t *value,
- sdb_time_t last_update)
-{
- return sdb_plugin_store_attribute(hostname, key, value, last_update);
-} /* sdb_store_attribute */
-
-int
-sdb_store_service(const char *hostname, const char *name,
- sdb_time_t last_update)
-{
- return sdb_plugin_store_service(hostname, name, last_update);
-} /* sdb_store_service */
-
-int
-sdb_store_service_attr(const char *hostname, const char *service,
- const char *key, const sdb_data_t *value, sdb_time_t last_update)
-{
- return sdb_plugin_store_service_attribute(hostname, service,
- key, value, last_update);
-} /* sdb_store_service_attr */
-
-int
-sdb_store_metric(const char *hostname, const char *name,
- sdb_metric_store_t *store, sdb_time_t last_update)
-{
- return sdb_plugin_store_metric(hostname, name, store, last_update);
-} /* sdb_store_metric */
-
-int
-sdb_store_metric_attr(const char *hostname, const char *metric,
- const char *key, const sdb_data_t *value, sdb_time_t last_update)
-{
- return sdb_plugin_store_metric_attribute(hostname, metric,
- key, value, last_update);
-} /* sdb_store_metric_attr */
-
bool
sdb_store_has_host(const char *name)
{
diff --git a/src/core/store_exec.c b/src/core/store_exec.c
index 6c68dc5fd1d4b9fce1486dea01ff2e44d97e96ab..436b36e4aeb25f1784257eeef5a818100e805aca 100644 (file)
--- a/src/core/store_exec.c
+++ b/src/core/store_exec.c
*/
#include "core/object.h"
+#include "core/plugin.h"
#include "core/store-private.h"
#include "frontend/connection.h"
#include "parser/ast.h"
switch (st->obj_type) {
case SDB_HOST:
strncpy(name, st->name, sizeof(name));
- status = sdb_store_host(st->name, st->last_update);
+ 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_store_service(st->hostname, st->name, st->last_update);
+ 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_store_metric(st->hostname, st->name,
+ status = sdb_plugin_store_metric(st->hostname, st->name,
&metric_store, st->last_update);
break;
switch (st->parent_type) {
case 0:
type |= SDB_HOST;
- status = sdb_store_attribute(st->hostname,
+ status = sdb_plugin_store_attribute(st->hostname,
st->name, &st->value, st->last_update);
break;
case SDB_SERVICE:
- status = sdb_store_service_attr(st->hostname, st->parent,
+ status = sdb_plugin_store_service_attribute(st->hostname, st->parent,
st->name, &st->value, st->last_update);
break;
case SDB_METRIC:
- status = sdb_store_metric_attr(st->hostname, st->parent,
+ status = sdb_plugin_store_metric_attribute(st->hostname, st->parent,
st->name, &st->value, st->last_update);
break;
index 4a0960c1cbe0055f77c1c1c6d64a9f32aa566b82..15f435fefdc6136a83fdb2e53a004a5cac82e8a9 100644 (file)
--- a/src/include/core/store.h
+++ b/src/include/core/store.h
/*
* A store writer describes the interface for plugins implementing a store.
+ *
+ * Any of the call-back functions shall return:
+ * - 0 on success
+ * - a positive value if the new entry is older than the currently stored
+ * entry (in this case, no update will happen)
+ * - a negative value on error
*/
typedef struct {
+ /*
+ * store_host:
+ * Add/update a host in the store. If the host, identified by its
+ * canonicalized name, already exists, it will be updated according to the
+ * specified name and timestamp. Else, a new entry will be created in the
+ * store.
+ */
int (*store_host)(const char *name, sdb_time_t last_update,
sdb_object_t *user_data);
+
+ /*
+ * store_service:
+ * Add/update a service in the store. If the service, identified by its
+ * name, already exists for the specified host, it will be updated
+ * according to the specified name and timestamp. If the referenced host
+ * does not exist, an error will be reported. Else, a new entry will be
+ * created in the store.
+ */
int (*store_service)(const char *hostname, const char *name,
sdb_time_t last_update, sdb_object_t *user_data);
+
+ /*
+ * store_metric:
+ * Add/update a metric in the store. If the metric, identified by its
+ * name, already exists for the specified host, it will be updated
+ * according to the specified attributes. If the referenced host does not
+ * exist, an error will be reported. Else, a new entry will be created in
+ * the store.
+ */
int (*store_metric)(const char *hostname, const char *name,
sdb_metric_store_t *store, sdb_time_t last_update,
sdb_object_t *user_data);
+
+ /*
+ * store_attribute:
+ * Add/update a host's attribute in the store. If the attribute,
+ * identified by its key, already exists for the specified host, it will
+ * be updated to the specified values. If the referenced host does not
+ * exist, an error will be reported. Else, a new entry will be created in
+ * the store.
+ */
int (*store_attribute)(const char *hostname,
const char *key, const sdb_data_t *value, sdb_time_t last_update,
sdb_object_t *user_data);
+
+ /*
+ * store_service_attr:
+ * Add/update a service's attribute in the store. If the attribute,
+ * identified by its key, already exists for the specified service, it
+ * will be updated to the specified value. If the references service (for
+ * the specified host) does not exist, an error will be reported.
+ */
int (*store_service_attr)(const char *hostname, const char *service,
const char *key, const sdb_data_t *value, sdb_time_t last_update,
sdb_object_t *user_data);
+
+ /*
+ * store_metric_attr:
+ * Add/update a metric's attribute in the store. If the attribute,
+ * identified by its key, already exists for the specified metric, it will
+ * be updated to the specified value. If the references metric (for the
+ * specified host) does not exist, an error will be reported.
+ */
int (*store_metric_attr)(const char *hostname, const char *metric,
const char *key, const sdb_data_t *value, sdb_time_t last_update,
sdb_object_t *user_data);
void
sdb_store_clear(void);
-/*
- * sdb_store_host:
- * Add/update a host in the store. If the host, identified by its
- * canonicalized name, already exists, it will be updated according to the
- * specified name and timestamp. Else, a new entry will be created in the
- * store. Any memory required for storing the entry will be allocated an
- * managed by the store itself.
- *
- * Returns:
- * - 0 on success
- * - a positive value if the new entry is older than the currently stored
- * entry (in this case, no update will happen)
- * - a negative value on error
- */
-int
-sdb_store_host(const char *name, sdb_time_t last_update);
-
/*
* sdb_store_has_host:
* sdb_store_get_host:
sdb_store_obj_t *
sdb_store_get_host(const char *name);
-/*
- * sdb_store_attribute:
- * Add/update a host's attribute in the store. If the attribute, identified by
- * its key, already exists for the specified host, it will be updated to the
- * specified values. If the referenced host does not exist, an error will be
- * reported. Else, a new entry will be created in the store. Any memory
- * required for storing the entry will be allocated and managed by the store
- * itself.
- *
- * Returns:
- * - 0 on success
- * - a positive value if the new entry is older than the currently stored
- * entry (in this case, no update will happen)
- * - a negative value on error
- */
-int
-sdb_store_attribute(const char *hostname,
- const char *key, const sdb_data_t *value,
- sdb_time_t last_update);
-
-/*
- * sdb_store_service:
- * Add/update a service in the store. If the service, identified by its name,
- * already exists for the specified host, it will be updated according to the
- * specified 'service' object. If the referenced host does not exist, an error
- * will be reported. Else, a new entry will be created in the store. Any
- * memory required for storing the entry will be allocated an managed by the
- * store itself.
- *
- * Returns:
- * - 0 on success
- * - a positive value if the new entry is older than the currently stored
- * entry (in this case, no update will happen)
- * - a negative value on error
- */
-int
-sdb_store_service(const char *hostname, const char *name,
- sdb_time_t last_update);
-
-/*
- * sdb_store_service_attr:
- * Add/update a service's attribute in the store. If the attribute, identified
- * by its key, already exists for the specified service, it will be updated to
- * the specified value. If the references service (for the specified host)
- * does not exist, an error will be reported. Any memory required for storing
- * the entry will be allocated and managed by the store itself.
- *
- * Returns:
- * - 0 on success
- * - a positive value if the new entry is older than the currently stored
- * entry (in this case, no update will happen)
- * - a negative value on error
- */
-int
-sdb_store_service_attr(const char *hostname, const char *service,
- const char *key, const sdb_data_t *value, sdb_time_t last_update);
-
-/*
- * sdb_store_metric:
- * Add/update a metric in the store. If the metric, identified by its name,
- * already exists for the specified host, it will be updated according to the
- * specified 'metric' object. If the referenced host does not exist, an error
- * will be reported. Else, a new entry will be created in the store. Any
- * memory required for storing the entry will be allocated an managed by the
- * store itself.
- *
- * If specified, the metric store describes where to access the metric's data.
- *
- * Returns:
- * - 0 on success
- * - a positive value if the new entry is older than the currently stored
- * entry (in this case, no update will happen)
- * - a negative value on error
- */
-int
-sdb_store_metric(const char *hostname, const char *name,
- sdb_metric_store_t *store, sdb_time_t last_update);
-
-/*
- * sdb_store_metric_attr:
- * Add/update a metric's attribute in the store. If the attribute, identified
- * by its key, already exists for the specified metric, it will be updated to
- * the specified value. If the references metric (for the specified host)
- * does not exist, an error will be reported. Any memory required for storing
- * the entry will be allocated and managed by the store itself.
- *
- * Returns:
- * - 0 on success
- * - a positive value if the new entry is older than the currently stored
- * entry (in this case, no update will happen)
- * - a negative value on error
- */
-int
-sdb_store_metric_attr(const char *hostname, const char *metric,
- const char *key, const sdb_data_t *value, sdb_time_t last_update);
-
/*
* sdb_store_fetch_timeseries:
* Fetch the time-series described by the specified host's metric and
index 8af5327624e135c15796b5e86c1bc6a7878cbedd..65b05845814ec6e66601cda58bc829a279956f37 100644 (file)
return -1;
}
- status = sdb_store_host(hostname, last_update);
+ status = sdb_plugin_store_host(hostname, last_update);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to "
if (ud->ts_base) {
snprintf(metric_id, sizeof(metric_id), "%s/%s/%s.rrd",
ud->ts_base, hostname, name);
- status = sdb_store_metric(hostname, name, &store, last_update);
+ status = sdb_plugin_store_metric(hostname, name, &store, last_update);
}
else
- status = sdb_store_metric(hostname, name, NULL, last_update);
+ status = sdb_plugin_store_metric(hostname, name, NULL, last_update);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to "
"store/update metric '%s/%s'.", hostname, name);
++plugin_instance;
data.data.string = plugin_instance;
- sdb_store_metric_attr(hostname, name,
+ sdb_plugin_store_metric_attribute(hostname, name,
"plugin_instance", &data, last_update);
}
++type_instance;
data.data.string = type_instance;
- sdb_store_metric_attr(hostname, name,
+ sdb_plugin_store_metric_attribute(hostname, name,
"type_instance", &data, last_update);
}
data.data.string = plugin;
- sdb_store_metric_attr(hostname, name, "plugin", &data, last_update);
+ sdb_plugin_store_metric_attribute(hostname, name, "plugin", &data, last_update);
data.data.string = type;
- sdb_store_metric_attr(hostname, name, "type", &data, last_update);
+ sdb_plugin_store_metric_attribute(hostname, name, "type", &data, last_update);
return 0;
} /* add_metrics */
index 98f7f57f18b30c23f0c56e889aa4e924900fcf75..e5561868f9d52647a8a93a298863bbf6a1454981 100644 (file)
return true;
sdb_data_t value = { SDB_TYPE_STRING, { .string = str } };
- sdb_store_attribute(hostname, k.c_str(), &value, now);
+ sdb_plugin_store_attribute(hostname, k.c_str(), &value, now);
return true;
} /* fact_iter */
std::string s = ss.str();
hostname = s.c_str();
- sdb_store_host(hostname, now);
+ sdb_plugin_store_host(hostname, now);
facts.each(fact_iter);
sdb_log(SDB_LOG_DEBUG, "facter backend: Processed %zu facts "
"for host '%s'", facts.size(), hostname);
index 7d9e320bc79c1f05524608c4d617e8ee786d6cd6..d1126db92a2e02f14835056f1d994b6c3fa2e8f5 100644 (file)
hostname = data[0].data.string;
timestamp = data[1].data.datetime;
- status = sdb_store_host(hostname, timestamp);
+ status = sdb_plugin_store_host(hostname, timestamp);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
svcname = data[1].data.string;
timestamp = data[2].data.datetime;
- status = sdb_store_service(hostname, svcname, timestamp);
+ status = sdb_plugin_store_service(hostname, svcname, timestamp);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to "
diff --git a/src/plugins/backend/puppet/store-configs.c b/src/plugins/backend/puppet/store-configs.c
index 95dd5499eea60ed090c5db712a04e732b4d370f5..800e81bdb0e4c2b2192acdd21ad62b8addd4f37b 100644 (file)
hostname = data[0].data.string;
timestamp = data[1].data.datetime;
- status = sdb_store_host(hostname, timestamp);
+ status = sdb_plugin_store_host(hostname, timestamp);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
value.data.string = data[2].data.string;
last_update = data[3].data.datetime;
- status = sdb_store_attribute(hostname, key, &value, last_update);
+ status = sdb_plugin_store_attribute(hostname, key, &value, last_update);
if (status < 0) {
sdb_log(SDB_LOG_ERR, "puppet::store-configs backend: Failed to "
index 5a9718de9d7c0d2698e977a8033096673a8027ea..87c86a84f08d4f896ca50d79cc6c38d7879b8367 100644 (file)
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(hostnames); ++i) {
- if ((check = sdb_store_host(hostnames[i], sdb_gettime()))) {
+ if ((check = sdb_plugin_store_host(hostnames[i], sdb_gettime()))) {
sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store host: "
"status %d", check);
exit(1);
}
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
- if ((check = sdb_store_metric(metrics[i].hostname,
+ if ((check = sdb_plugin_store_metric(metrics[i].hostname,
metrics[i].metric, &metrics[i].store,
sdb_gettime()))) {
sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store metric: "
}
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) {
- if ((check = sdb_store_service(services[i].hostname,
+ if ((check = sdb_plugin_store_service(services[i].hostname,
services[i].service, sdb_gettime()))) {
sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store service: "
"status %d", check);
sdb_data_t datum = { SDB_TYPE_STRING, { .string = NULL } };
datum.data.string = strdup(attributes[i].value);
- if ((check = sdb_store_attribute(attributes[i].hostname,
+ if ((check = sdb_plugin_store_attribute(attributes[i].hostname,
attributes[i].name, &datum, sdb_gettime()))) {
sdb_log(SDB_LOG_ERR, "mock::plugin: Failed to store attribute: "
"status %d", check);
index b15809a589bc890dd36ff5c8809bdf71b75cfd84..153e52f1c84bb393bcd560541485ee71e5af8044 100644 (file)
# include "config.h"
#endif
+#include "core/plugin.h"
#include "core/store.h"
#include "core/store-private.h"
#include "parser/parser.h"
sdb_store_init();
for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) {
- int status = sdb_store_host(hosts[i], 1);
+ int status = sdb_plugin_store_host(hosts[i], 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
- int status = sdb_store_metric(metrics[i].host,
+ int status = sdb_plugin_store_metric(metrics[i].host,
metrics[i].metric, /* store */ NULL, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) {
- int status = sdb_store_service(services[i].host,
+ int status = sdb_plugin_store_service(services[i].host,
services[i].service, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) {
- int status = sdb_store_attribute(attrs[i].host,
+ int status = sdb_plugin_store_attribute(attrs[i].host,
attrs[i].name, &attrs[i].value, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(svc_attrs); ++i) {
- int status = sdb_store_service_attr(svc_attrs[i].host,
+ int status = sdb_plugin_store_service_attribute(svc_attrs[i].host,
svc_attrs[i].service, svc_attrs[i].name,
&svc_attrs[i].value, 1);
ck_assert(status == 0);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metric_attrs); ++i) {
- int status = sdb_store_metric_attr(metric_attrs[i].host,
+ int status = sdb_plugin_store_metric_attribute(metric_attrs[i].host,
metric_attrs[i].metric, metric_attrs[i].name,
&metric_attrs[i].value, 1);
ck_assert(status == 0);
index ebb2daf1d22ec7cee81e267d97ca476612b5abe9..baecf8053d1986576ee2cd4b42e7bcad3e010248 100644 (file)
# include "config.h"
#endif
+#include "core/plugin.h"
#include "core/store.h"
#include "testutils.h"
sdb_store_init();
- sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND);
- sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_host("h1", 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_host("h2", 3 * SDB_INTERVAL_SECOND);
datum.type = SDB_TYPE_STRING;
datum.data.string = "v1";
- sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
datum.data.string = "v2";
- sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
datum.data.string = "v3";
- sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
/* make sure that older updates don't overwrite existing values */
datum.data.string = "fail";
- sdb_store_attribute("h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
- sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
- sdb_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
- sdb_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
- sdb_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
- sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND);
- sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND);
datum.type = SDB_TYPE_INTEGER;
datum.data.integer = 42;
- sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric_attribute("h1", "m1", "k3",
+ &datum, 2 * SDB_INTERVAL_SECOND);
datum.data.integer = 123;
- sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service_attribute("h2", "s2", "k1",
+ &datum, 2 * SDB_INTERVAL_SECOND);
datum.data.integer = 4711;
- sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service_attribute("h2", "s2", "k2",
+ &datum, 1 * SDB_INTERVAL_SECOND);
/* don't overwrite k1 */
datum.data.integer = 666;
- sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service_attribute("h2", "s2", "k1",
+ &datum, 2 * SDB_INTERVAL_SECOND);
} /* populate */
static int
index 913e6b78a0905bb803a5d7073e3cc27c4a457904..49f2268a24d0758dc5165934bb5c75d7908a9947 100644 (file)
# include "config.h"
#endif
+#include "core/plugin.h"
#include "core/store.h"
#include "core/store-private.h"
#include "parser/parser.h"
sdb_store_init();
for (i = 0; i < SDB_STATIC_ARRAY_LEN(hosts); ++i) {
- int status = sdb_store_host(hosts[i], 1);
+ int status = sdb_plugin_store_host(hosts[i], 1);
fail_unless(status == 0,
- "sdb_store_host(%s, 1) = %d; expected: 0",
+ "sdb_plugin_store_host(%s, 1) = %d; expected: 0",
hosts[i], status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(metrics); ++i) {
- int status = sdb_store_metric(metrics[i].host,
+ int status = sdb_plugin_store_metric(metrics[i].host,
metrics[i].metric, /* store */ NULL, 1);
fail_unless(status == 0,
- "sdb_store_metric(%s, %s, NULL, 1) = %d; expected: 0",
+ "sdb_plugin_store_metric(%s, %s, NULL, 1) = %d; expected: 0",
metrics[i].host, metrics[i].metric, status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(services); ++i) {
- int status = sdb_store_service(services[i].host,
+ int status = sdb_plugin_store_service(services[i].host,
services[i].service, 1);
fail_unless(status == 0,
- "sdb_store_service(%s, %s, 1) = %d; expected: 0",
+ "sdb_plugin_store_service(%s, %s, 1) = %d; expected: 0",
services[i].host, services[i].service, status);
}
for (i = 0; i < SDB_STATIC_ARRAY_LEN(attrs); ++i) {
- int status = sdb_store_attribute(attrs[i].host,
+ int status = sdb_plugin_store_attribute(attrs[i].host,
attrs[i].name, &attrs[i].value, 1);
fail_unless(status == 0,
- "sdb_store_attribute(%s, %s, <val>, 1) = %d; expected: 0",
+ "sdb_plugin_store_attribute(%s, %s, <val>, 1) = %d; expected: 0",
attrs[i].host, attrs[i].name, status);
}
} /* populate */
index 8308f3334f39d7c2c8cd71362f5903eab399c412..ed6f5d9b149944e31c4412c4c6103dd9a9f25320 100644 (file)
--- a/t/unit/core/store_test.c
+++ b/t/unit/core/store_test.c
# include "config.h"
#endif
+#include "core/plugin.h"
#include "core/store.h"
#include "core/store-private.h"
#include "testutils.h"
{
sdb_data_t datum;
- sdb_store_init();
-
- sdb_store_host("h1", 1);
- sdb_store_host("h2", 3);
+ sdb_plugin_store_host("h1", 1);
+ sdb_plugin_store_host("h2", 3);
datum.type = SDB_TYPE_STRING;
datum.data.string = "v1";
- sdb_store_attribute("h1", "k1", &datum, 1);
+ sdb_plugin_store_attribute("h1", "k1", &datum, 1);
datum.data.string = "v2";
- sdb_store_attribute("h1", "k2", &datum, 2);
+ sdb_plugin_store_attribute("h1", "k2", &datum, 2);
datum.data.string = "v3";
- sdb_store_attribute("h1", "k3", &datum, 2);
+ sdb_plugin_store_attribute("h1", "k3", &datum, 2);
/* make sure that older updates don't overwrite existing values */
datum.data.string = "fail";
- sdb_store_attribute("h1", "k2", &datum, 1);
- sdb_store_attribute("h1", "k3", &datum, 2);
+ sdb_plugin_store_attribute("h1", "k2", &datum, 1);
+ sdb_plugin_store_attribute("h1", "k3", &datum, 2);
- sdb_store_metric("h1", "m1", /* store */ NULL, 2);
- sdb_store_metric("h1", "m2", /* store */ NULL, 1);
- sdb_store_metric("h2", "m1", /* store */ NULL, 1);
+ sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2);
+ sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1);
+ sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1);
- sdb_store_service("h2", "s1", 1);
- sdb_store_service("h2", "s2", 2);
+ sdb_plugin_store_service("h2", "s1", 1);
+ sdb_plugin_store_service("h2", "s2", 2);
datum.type = SDB_TYPE_INTEGER;
datum.data.integer = 42;
- sdb_store_metric_attr("h1", "m1", "k3", &datum, 2);
+ sdb_plugin_store_metric_attribute("h1", "m1", "k3", &datum, 2);
datum.data.integer = 123;
- sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+ sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2);
datum.data.integer = 4711;
- sdb_store_service_attr("h2", "s2", "k2", &datum, 1);
+ sdb_plugin_store_service_attribute("h2", "s2", "k2", &datum, 1);
/* don't overwrite k1 */
datum.data.integer = 666;
- sdb_store_service_attr("h2", "s2", "k1", &datum, 2);
+ sdb_plugin_store_service_attribute("h2", "s2", "k1", &datum, 2);
} /* populate */
START_TEST(test_store_host)
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_host(golden_data[i].name,
+ status = sdb_plugin_store_host(golden_data[i].name,
golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_host(%s, %d) = %d; expected: %d",
+ "sdb_plugin_store_host(%s, %d) = %d; expected: %d",
golden_data[i].name, (int)golden_data[i].last_update,
status, golden_data[i].expected);
}
size_t i;
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_hosts); ++i) {
- int status = sdb_store_host(golden_hosts[i], 1);
+ int status = sdb_plugin_store_host(golden_hosts[i], 1);
fail_unless(status >= 0,
- "sdb_store_host(%s) = %d; expected: >=0",
+ "sdb_plugin_store_host(%s) = %d; expected: >=0",
golden_hosts[i], status);
}
size_t i;
- sdb_store_host("l", 1);
- sdb_store_host("m", 1);
+ sdb_plugin_store_host("l", 1);
+ sdb_plugin_store_host("m", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
sdb_data_t datum;
int status;
datum.type = SDB_TYPE_STRING;
datum.data.string = golden_data[i].value;
- status = sdb_store_attribute(golden_data[i].host,
+ status = sdb_plugin_store_attribute(golden_data[i].host,
golden_data[i].key, &datum,
golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
+ "sdb_plugin_store_attribute(%s, %s, %s, %d) = %d; expected: %d",
golden_data[i].host, golden_data[i].key, golden_data[i].value,
golden_data[i].last_update, status, golden_data[i].expected);
}
size_t i;
- sdb_store_host("m", 1);
- sdb_store_host("l", 1);
+ sdb_plugin_store_host("m", 1);
+ sdb_plugin_store_host("l", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_metric(golden_data[i].host,
+ status = sdb_plugin_store_metric(golden_data[i].host,
golden_data[i].metric, golden_data[i].store,
golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_metric(%s, %s, %p, %d) = %d; expected: %d",
+ "sdb_plugin_store_metric(%s, %s, %p, %d) = %d; expected: %d",
golden_data[i].host, golden_data[i].metric,
golden_data[i].store, golden_data[i].last_update,
status, golden_data[i].expected);
size_t i;
- sdb_store_host("m", 1);
- sdb_store_host("l", 1);
- sdb_store_metric("m", "m1", NULL, 1);
- sdb_store_metric("l", "m1", NULL, 1);
- sdb_store_metric("l", "m2", NULL, 1);
+ sdb_plugin_store_host("m", 1);
+ sdb_plugin_store_host("l", 1);
+ sdb_plugin_store_metric("m", "m1", NULL, 1);
+ sdb_plugin_store_metric("l", "m1", NULL, 1);
+ sdb_plugin_store_metric("l", "m2", NULL, 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_metric_attr(golden_data[i].host,
+ status = sdb_plugin_store_metric_attribute(golden_data[i].host,
golden_data[i].metric, golden_data[i].attr,
&golden_data[i].value, golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_metric_attr(%s, %s, %s, %d, %d) = %d; "
+ "sdb_plugin_store_metric_attribute(%s, %s, %s, %d, %d) = %d; "
"expected: %d", golden_data[i].host, golden_data[i].metric,
golden_data[i].attr, golden_data[i].value.data.integer,
golden_data[i].last_update, status, golden_data[i].expected);
size_t i;
- sdb_store_host("m", 1);
- sdb_store_host("l", 1);
+ sdb_plugin_store_host("m", 1);
+ sdb_plugin_store_host("l", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_service(golden_data[i].host,
+ status = sdb_plugin_store_service(golden_data[i].host,
golden_data[i].svc, golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_service(%s, %s, %d) = %d; expected: %d",
+ "sdb_plugin_store_service(%s, %s, %d) = %d; expected: %d",
golden_data[i].host, golden_data[i].svc,
golden_data[i].last_update, status, golden_data[i].expected);
}
size_t i;
- sdb_store_host("m", 1);
- sdb_store_host("l", 1);
- sdb_store_service("m", "s1", 1);
- sdb_store_service("l", "s1", 1);
- sdb_store_service("l", "s2", 1);
+ sdb_plugin_store_host("m", 1);
+ sdb_plugin_store_host("l", 1);
+ sdb_plugin_store_service("m", "s1", 1);
+ sdb_plugin_store_service("l", "s1", 1);
+ sdb_plugin_store_service("l", "s2", 1);
for (i = 0; i < SDB_STATIC_ARRAY_LEN(golden_data); ++i) {
int status;
- status = sdb_store_service_attr(golden_data[i].host,
+ status = sdb_plugin_store_service_attribute(golden_data[i].host,
golden_data[i].svc, golden_data[i].attr,
&golden_data[i].value, golden_data[i].last_update);
fail_unless(status == golden_data[i].expected,
- "sdb_store_service_attr(%s, %s, %s, %d, %d) = %d; "
+ "sdb_plugin_store_service_attribute(%s, %s, %s, %d, %d) = %d; "
"expected: %d", golden_data[i].host, golden_data[i].svc,
golden_data[i].attr, golden_data[i].value.data.integer,
golden_data[i].last_update, status, golden_data[i].expected);
sdb_time_t now = sdb_gettime();
int check;
- sdb_store_host("host", 10);
- sdb_store_host("host", 20);
- sdb_store_attribute("host", "attr", &get_field_data[_i].value, 10);
- sdb_store_attribute("host", "attr", &get_field_data[_i].value, 20);
+ sdb_plugin_store_host("host", 10);
+ sdb_plugin_store_host("host", 20);
+ sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 10);
+ sdb_plugin_store_attribute("host", "attr", &get_field_data[_i].value, 20);
if (get_field_data[_i].hostname) {
obj = sdb_store_get_host(get_field_data[_i].hostname);
sdb_store_obj_t *host;
/* 10 us interval */
- sdb_store_host("host", 10);
- sdb_store_host("host", 20);
- sdb_store_host("host", 30);
- sdb_store_host("host", 40);
+ sdb_plugin_store_host("host", 10);
+ sdb_plugin_store_host("host", 20);
+ sdb_plugin_store_host("host", 30);
+ sdb_plugin_store_host("host", 40);
host = sdb_store_get_host("host");
fail_unless(host != NULL,
"INTERNAL ERROR: store doesn't have host after adding it");
fail_unless(host->interval == 10,
- "sdb_store_host() did not calculate interval correctly: "
+ "sdb_plugin_store_host() did not calculate interval correctly: "
"got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 10);
/* multiple updates for the same timestamp don't modify the interval */
- sdb_store_host("host", 40);
- sdb_store_host("host", 40);
- sdb_store_host("host", 40);
- sdb_store_host("host", 40);
+ sdb_plugin_store_host("host", 40);
+ sdb_plugin_store_host("host", 40);
+ sdb_plugin_store_host("host", 40);
+ sdb_plugin_store_host("host", 40);
fail_unless(host->interval == 10,
- "sdb_store_host() changed interval when doing multiple updates "
+ "sdb_plugin_store_host() changed interval when doing multiple updates "
"using the same timestamp; got: %"PRIsdbTIME"; "
"expected: %"PRIsdbTIME, host->interval, 10);
/* multiple updates using an timestamp don't modify the interval */
- sdb_store_host("host", 20);
- sdb_store_host("host", 20);
- sdb_store_host("host", 20);
- sdb_store_host("host", 20);
+ sdb_plugin_store_host("host", 20);
+ sdb_plugin_store_host("host", 20);
+ sdb_plugin_store_host("host", 20);
+ sdb_plugin_store_host("host", 20);
fail_unless(host->interval == 10,
- "sdb_store_host() changed interval when doing multiple updates "
+ "sdb_plugin_store_host() changed interval when doing multiple updates "
"using an old timestamp; got: %"PRIsdbTIME"; expected: %"PRIsdbTIME,
host->interval, 10);
/* new interval: 20 us */
- sdb_store_host("host", 60);
+ sdb_plugin_store_host("host", 60);
fail_unless(host->interval == 11,
- "sdb_store_host() did not calculate interval correctly: "
+ "sdb_plugin_store_host() did not calculate interval correctly: "
"got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
/* new interval: 40 us */
- sdb_store_host("host", 100);
+ sdb_plugin_store_host("host", 100);
fail_unless(host->interval == 13,
- "sdb_store_host() did not calculate interval correctly: "
+ "sdb_plugin_store_host() did not calculate interval correctly: "
"got: %"PRIsdbTIME"; expected: %"PRIsdbTIME, host->interval, 11);
sdb_object_deref(SDB_OBJ(host));
index d7e5b30cbd7f7c2a4122c4851233eca306fbda23..7fb73a453f33dc7bf84a8989557f8c9470f93b10 100644 (file)
# include "config.h"
#endif
+#include "core/plugin.h"
#include "frontend/connection.h"
#include "frontend/connection-private.h"
#include "testutils.h"
sdb_store_init();
- sdb_store_host("h1", 1 * SDB_INTERVAL_SECOND);
- sdb_store_host("h2", 3 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_host("h1", 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_host("h2", 3 * SDB_INTERVAL_SECOND);
datum.type = SDB_TYPE_STRING;
datum.data.string = "v1";
- sdb_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k1", &datum, 1 * SDB_INTERVAL_SECOND);
datum.data.string = "v2";
- sdb_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k2", &datum, 2 * SDB_INTERVAL_SECOND);
datum.data.string = "v3";
- sdb_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_attribute("h1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
- sdb_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
- sdb_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
- sdb_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric("h1", "m1", /* store */ NULL, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric("h1", "m2", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric("h2", "m1", /* store */ NULL, 1 * SDB_INTERVAL_SECOND);
datum.type = SDB_TYPE_INTEGER;
datum.data.integer = 42;
- sdb_store_metric_attr("h1", "m1", "k3", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_metric_attribute("h1", "m1", "k3",
+ &datum, 2 * SDB_INTERVAL_SECOND);
- sdb_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND);
- sdb_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service("h2", "s1", 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service("h2", "s2", 2 * SDB_INTERVAL_SECOND);
datum.data.integer = 123;
- sdb_store_service_attr("h2", "s2", "k1", &datum, 2 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service_attribute("h2", "s2", "k1",
+ &datum, 2 * SDB_INTERVAL_SECOND);
datum.data.integer = 4711;
- sdb_store_service_attr("h2", "s2", "k2", &datum, 1 * SDB_INTERVAL_SECOND);
+ sdb_plugin_store_service_attribute("h2", "s2", "k2",
+ &datum, 1 * SDB_INTERVAL_SECOND);
} /* populate */
#define HOST_H1 \