summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f05f6df)
raw | patch | inline | side by side (parent: f05f6df)
author | Sebastian Harl <sh@tokkee.org> | |
Fri, 16 Jan 2015 21:10:46 +0000 (22:10 +0100) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Fri, 16 Jan 2015 21:10:46 +0000 (22:10 +0100) |
src/core/plugin.c | patch | blob | history | |
src/core/store.c | patch | blob | history | |
src/include/core/plugin.h | patch | blob | history |
diff --git a/src/core/plugin.c b/src/core/plugin.c
index 4de1c3a4d93f3a8f502844bc67d4fe5801889b6b..7404b036392ecd5c76899009dd7f515ff9d87d8e 100644 (file)
--- a/src/core/plugin.c
+++ b/src/core/plugin.c
return ts;
} /* sdb_plugin_fetch_timeseries */
+int
+sdb_plugin_store_host(const char *name, sdb_time_t last_update)
+{
+ sdb_llist_iter_t *iter;
+ int status = 0;
+
+ if (! name)
+ return -1;
+
+ iter = sdb_llist_get_iter(writer_list);
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_plugin_writer_t *writer;
+ writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
+ assert(writer);
+ if (writer->impl.store_host(name, last_update, writer->user_data))
+ status = -1;
+ }
+ sdb_llist_iter_destroy(iter);
+ return status;
+} /* sdb_plugin_store_host */
+
+int
+sdb_plugin_store_service(const char *hostname, const char *name,
+ sdb_time_t last_update)
+{
+ sdb_llist_iter_t *iter;
+ int status = 0;
+
+ if ((! hostname) || (! name))
+ return -1;
+
+ iter = sdb_llist_get_iter(writer_list);
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_plugin_writer_t *writer;
+ writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
+ assert(writer);
+ if (writer->impl.store_service(hostname, name, last_update,
+ writer->user_data))
+ status = -1;
+ }
+ sdb_llist_iter_destroy(iter);
+ return status;
+} /* sdb_plugin_store_service */
+
+int
+sdb_plugin_store_metric(const char *hostname, const char *name,
+ sdb_metric_store_t *store, sdb_time_t last_update)
+{
+ sdb_llist_iter_t *iter;
+ int status = 0;
+
+ if ((! hostname) || (! name))
+ return -1;
+
+ if ((! store->type) || (! store->id))
+ store = NULL;
+
+ iter = sdb_llist_get_iter(writer_list);
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_plugin_writer_t *writer;
+ writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
+ assert(writer);
+ if (writer->impl.store_metric(hostname, name, store, last_update,
+ writer->user_data))
+ status = -1;
+ }
+ sdb_llist_iter_destroy(iter);
+ return status;
+} /* sdb_plugin_store_metric */
+
+int
+sdb_plugin_store_attribute(const char *hostname, const char *key,
+ const sdb_data_t *value, sdb_time_t last_update)
+{
+ sdb_llist_iter_t *iter;
+ int status = 0;
+
+ if ((! hostname) || (! key) || (! value))
+ return -1;
+
+ iter = sdb_llist_get_iter(writer_list);
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_plugin_writer_t *writer;
+ writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
+ assert(writer);
+ if (writer->impl.store_attribute(hostname, key, value, last_update,
+ writer->user_data))
+ status = -1;
+ }
+ sdb_llist_iter_destroy(iter);
+ return status;
+} /* sdb_plugin_store_attribute */
+
+int
+sdb_plugin_store_service_attribute(const char *hostname, const char *service,
+ const char *key, const sdb_data_t *value, sdb_time_t last_update)
+{
+ sdb_llist_iter_t *iter;
+ int status = 0;
+
+ if ((! hostname) || (! service) || (! key) || (! value))
+ return -1;
+
+ iter = sdb_llist_get_iter(writer_list);
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_plugin_writer_t *writer;
+ writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
+ assert(writer);
+ if (writer->impl.store_service_attr(hostname, service,
+ key, value, last_update, writer->user_data))
+ status = -1;
+ }
+ sdb_llist_iter_destroy(iter);
+ return status;
+} /* sdb_plugin_store_service_attribute */
+
+int
+sdb_plugin_store_metric_attribute(const char *hostname, const char *metric,
+ const char *key, const sdb_data_t *value, sdb_time_t last_update)
+{
+ sdb_llist_iter_t *iter;
+ int status = 0;
+
+ if ((! hostname) || (! metric) || (! key) || (! value))
+ return -1;
+
+ iter = sdb_llist_get_iter(writer_list);
+ while (sdb_llist_iter_has_next(iter)) {
+ sdb_plugin_writer_t *writer;
+ writer = SDB_PLUGIN_WRITER(sdb_llist_iter_get_next(iter));
+ assert(writer);
+ if (writer->impl.store_metric_attr(hostname, metric,
+ key, value, last_update, writer->user_data))
+ status = -1;
+ }
+ sdb_llist_iter_destroy(iter);
+ return status;
+} /* sdb_plugin_store_metric_attribute */
+
/* vim: set tw=78 sw=4 ts=4 noexpandtab : */
diff --git a/src/core/store.c b/src/core/store.c
index 98b3a96d28ee6186518ba1f9bd5a16ef2a84e22f..e6aeaf63e86f3c8a6d56e7682f065801396e481d 100644 (file)
--- a/src/core/store.c
+++ b/src/core/store.c
status = store_obj(NULL, hosts, SDB_HOST, cname, last_update, NULL);
pthread_rwlock_unlock(&host_lock);
+ if (sdb_plugin_store_host(name, last_update))
+ status = -1;
+
free(cname);
return status;
} /* sdb_store_host */
sdb_object_deref(SDB_OBJ(host));
pthread_rwlock_unlock(&host_lock);
+
+ if (sdb_plugin_store_attribute(hostname, key, value, last_update))
+ status = -1;
return status;
} /* sdb_store_attribute */
sdb_object_deref(SDB_OBJ(host));
pthread_rwlock_unlock(&host_lock);
+
+ if (sdb_plugin_store_service(hostname, name, last_update))
+ status = -1;
return status;
} /* sdb_store_service */
sdb_object_deref(SDB_OBJ(svc));
pthread_rwlock_unlock(&host_lock);
+
+ if (sdb_plugin_store_service_attribute(hostname, service,
+ key, value, last_update))
+ status = -1;
return status;
} /* sdb_store_service_attr */
status = -1;
}
pthread_rwlock_unlock(&host_lock);
+
+ if (sdb_plugin_store_metric(hostname, name, store, last_update))
+ status = -1;
return status;
} /* sdb_store_metric */
sdb_object_deref(SDB_OBJ(m));
pthread_rwlock_unlock(&host_lock);
+
+ if (sdb_plugin_store_metric_attribute(hostname, metric,
+ key, value, last_update))
+ status = -1;
return status;
} /* sdb_store_metric_attr */
index e09bf0f346c42143948843e4e0ef84326f4ee870..f48980aa4820326d298e12da642e0454c942fb19 100644 (file)
sdb_plugin_fetch_timeseries(const char *type, const char *id,
sdb_timeseries_opts_t *opts);
+/*
+ * sdb_plugin_store_host, sdb_plugin_store_service, sdb_plugin_store_metric,
+ * sdb_plugin_store_attribute, sdb_plugin_store_service_attribute,
+ * sdb_plugin_store_metric_attribute:
+ * Store an object in the database by sending it to all registered store
+ * writer plugins.
+ *
+ * Returns:
+ * - 0 on success
+ * - a negative value else
+ */
+int
+sdb_plugin_store_host(const char *name, sdb_time_t last_update);
+int
+sdb_plugin_store_service(const char *hostname, const char *name,
+ sdb_time_t last_update);
+int
+sdb_plugin_store_metric(const char *hostname, const char *name,
+ sdb_metric_store_t *store, sdb_time_t last_update);
+int
+sdb_plugin_store_attribute(const char *hostname, const char *key,
+ const sdb_data_t *value, sdb_time_t last_update);
+int
+sdb_plugin_store_service_attribute(const char *hostname, const char *service,
+ const char *key, const sdb_data_t *value, sdb_time_t last_update);
+int
+sdb_plugin_store_metric_attribute(const char *hostname, const char *metric,
+ const char *key, const sdb_data_t *value, sdb_time_t last_update);
+
#ifdef __cplusplus
} /* extern "C" */
#endif