From 4f560f6144aa610163e2a3ec326e63e0751c5c3e Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Sun, 10 Mar 2013 22:57:19 +0100 Subject: [PATCH] Renamed collectd backend to collectd::unixsock. --- src/Makefile.am | 12 ++-- .../{collectd.c => collectd/unixsock.c} | 70 ++++++++++--------- src/backend/puppet-storeconfigs.c | 2 +- src/daemon/sysdbd.conf.sample | 4 +- 4 files changed, 46 insertions(+), 42 deletions(-) rename src/backend/{collectd.c => collectd/unixsock.c} (80%) diff --git a/src/Makefile.am b/src/Makefile.am index 8b438f6..a2f0de0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -51,15 +51,17 @@ sdbconfdir = $(sysconfdir)/sysdb dist_sdbconf_DATA = daemon/sysdbd.conf.sample pkgbackendlibdir = $(pkglibdir)/backend +pkgbackendcollectdlibdir = $(pkgbackendlibdir)/collectd pkgbackendlib_LTLIBRARIES = +pkgbackendcollectdlib_LTLIBRARIES = if BUILD_PLUGIN_COLLECTD -pkgbackendlib_LTLIBRARIES += backend/collectd.la -backend_collectd_la_SOURCES = backend/collectd.c -backend_collectd_la_LDFLAGS = -module -avoid-version -libsysdb_la_LIBADD += -dlopen backend/collectd.la -libsysdb_la_DEPENDENCIES += backend/collectd.la +pkgbackendcollectdlib_LTLIBRARIES += backend/collectd/unixsock.la +backend_collectd_unixsock_la_SOURCES = backend/collectd/unixsock.c +backend_collectd_unixsock_la_LDFLAGS = -module -avoid-version +libsysdb_la_LIBADD += -dlopen backend/collectd/unixsock.la +libsysdb_la_DEPENDENCIES += backend/collectd/unixsock.la endif if BUILD_PLUGIN_MKLIVESTATUS diff --git a/src/backend/collectd.c b/src/backend/collectd/unixsock.c similarity index 80% rename from src/backend/collectd.c rename to src/backend/collectd/unixsock.c index 2ace8e1..01c2f25 100644 --- a/src/backend/collectd.c +++ b/src/backend/collectd/unixsock.c @@ -1,5 +1,5 @@ /* - * SysDB - src/backend/collectd.c + * SysDB - src/backend/collectd/unixsock.c * Copyright (C) 2012 Sebastian 'tokkee' Harl * All rights reserved. * @@ -75,15 +75,15 @@ sdb_collectd_add_host(const char *hostname, sdb_time_t last_update) status = sdb_store_host(&host); if (status < 0) { - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to store/update " - "host '%s'.\n", name); + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to " + "store/update host '%s'.\n", name); return -1; } else if (status > 0) /* value too old */ return 0; - sdb_log(SDB_LOG_DEBUG, "collectd backend: Added/updated host '%s' " - "(last update timestamp = %"PRIscTIME").\n", + sdb_log(SDB_LOG_DEBUG, "collectd::unixsock backend: Added/updated " + "host '%s' (last update timestamp = %"PRIscTIME").\n", name, last_update); return 0; } /* sdb_collectd_add_host */ @@ -107,8 +107,8 @@ sdb_collectd_add_svc(const char *hostname, const char *plugin, status = sdb_store_service(&svc); if (status < 0) { - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to store/update " - "service '%s/%s'.\n", host, name); + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to " + "store/update service '%s/%s'.\n", host, name); return -1; } return 0; @@ -147,7 +147,7 @@ sdb_collectd_get_data(sdb_unixsock_client_t __attribute__((unused)) *client, if (! state->current_host) { char errbuf[1024]; - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to allocate " + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to allocate " "string buffer: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; @@ -170,7 +170,7 @@ sdb_collectd_get_data(sdb_unixsock_client_t __attribute__((unused)) *client, /* new host */ sdb_collectd_add_host(hostname, last_update); - sdb_log(SDB_LOG_DEBUG, "collectd backend: Added/updated " + sdb_log(SDB_LOG_DEBUG, "collectd::unixsock backend: Added/updated " "%i service%s (%i failed) for host '%s'.\n", state->svc_updated, state->svc_updated == 1 ? "" : "s", state->svc_failed, state->current_host); @@ -196,12 +196,12 @@ sdb_collectd_init(sdb_object_t *user_data) client = SDB_OBJ_WRAPPER(user_data)->data; if (sdb_unixsock_client_connect(client)) { - sdb_log(SDB_LOG_ERR, "collectd backend: " + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: " "Failed to connect to collectd.\n"); return -1; } - sdb_log(SDB_LOG_INFO, "collectd backend: Successfully " + sdb_log(SDB_LOG_INFO, "collectd::unixsock backend: Successfully " "connected to collectd @ %s.\n", sdb_unixsock_client_path(client)); return 0; @@ -235,16 +235,16 @@ sdb_collectd_collect(sdb_object_t *user_data) client = SDB_OBJ_WRAPPER(user_data)->data; if (sdb_unixsock_client_send(client, "LISTVAL") <= 0) { - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to send LISTVAL " - "command to collectd @ %s.\n", + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to send " + "LISTVAL command to collectd @ %s.\n", sdb_unixsock_client_path(client)); return -1; } line = sdb_unixsock_client_recv(client, buffer, sizeof(buffer)); if (! line) { - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to read status " - "of LISTVAL command from collectd @ %s.\n", + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to read " + "status of LISTVAL command from collectd @ %s.\n", sdb_unixsock_client_path(client)); return -1; } @@ -258,15 +258,15 @@ sdb_collectd_collect(sdb_object_t *user_data) errno = 0; count = strtol(line, &endptr, /* base */ 0); if (errno || (line == endptr)) { - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to parse status " - "of LISTVAL command from collectd @ %s.\n", + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to parse " + "status of LISTVAL command from collectd @ %s.\n", sdb_unixsock_client_path(client)); return -1; } if (count < 0) { - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to get value " - "list from collectd @ %s: %s\n", + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to get " + "value list from collectd @ %s: %s\n", sdb_unixsock_client_path(client), msg ? msg : line); return -1; @@ -277,14 +277,15 @@ sdb_collectd_collect(sdb_object_t *user_data) /* column count = */ 4, SDB_TYPE_DATETIME, SDB_TYPE_STRING, SDB_TYPE_STRING, SDB_TYPE_STRING)) { - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to read response " - "from collectd @ %s.\n", sdb_unixsock_client_path(client)); + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed " + "to read response from collectd @ %s.\n", + sdb_unixsock_client_path(client)); return -1; } if (state.current_host) { sdb_collectd_add_host(state.current_host, state.current_timestamp); - sdb_log(SDB_LOG_DEBUG, "collectd backend: Added/updated " + sdb_log(SDB_LOG_DEBUG, "collectd::unixsock backend: Added/updated " "%i service%s (%i failed) for host '%s'.\n", state.svc_updated, state.svc_updated == 1 ? "" : "s", state.svc_failed, state.current_host); @@ -306,8 +307,8 @@ sdb_collectd_config_instance(oconfig_item_t *ci) int i; if (oconfig_get_string(ci, &name)) { - sdb_log(SDB_LOG_ERR, "collectd backend: Instance requires a " - "single string argument\n\tUsage: \n"); + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Instance requires " + "a single string argument\n\tUsage: \n"); return -1; } @@ -317,24 +318,24 @@ sdb_collectd_config_instance(oconfig_item_t *ci) if (! strcasecmp(child->key, "Socket")) oconfig_get_string(child, &socket_path); else - sdb_log(SDB_LOG_WARNING, "collectd backend: Ignoring " + sdb_log(SDB_LOG_WARNING, "collectd::unixsock backend: Ignoring " "unknown config option '%s' inside .\n", child->key, name); } if (! socket_path) { - sdb_log(SDB_LOG_ERR, "collectd backend: Instance '%s' missing " - "the 'Socket' option.\n", name); + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Instance '%s' " + "missing the 'Socket' option.\n", name); return -1; } - snprintf(cb_name, sizeof(cb_name), "collectd-%s", name); + snprintf(cb_name, sizeof(cb_name), "collectd::unixsock::%s", name); cb_name[sizeof(cb_name) - 1] = '\0'; client = sdb_unixsock_client_create(socket_path); if (! client) { char errbuf[1024]; - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to create " + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to create " "unixsock client: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; @@ -344,7 +345,7 @@ sdb_collectd_config_instance(oconfig_item_t *ci) (void (*)(void *))sdb_unixsock_client_destroy); if (! user_data) { sdb_unixsock_client_destroy(client); - sdb_log(SDB_LOG_ERR, "collectd backend: Failed to allocate " + sdb_log(SDB_LOG_ERR, "collectd::unixsock backend: Failed to allocate " "sdb_object_t\n"); return -1; } @@ -371,7 +372,7 @@ sdb_collectd_config(oconfig_item_t *ci) if (! strcasecmp(child->key, "Instance")) sdb_collectd_config_instance(child); else - sdb_log(SDB_LOG_WARNING, "collectd backend: Ignoring " + sdb_log(SDB_LOG_WARNING, "collectd::unixsock backend: Ignoring " "unknown config option '%s'.\n", child->key); } return 0; @@ -380,16 +381,17 @@ sdb_collectd_config(oconfig_item_t *ci) int sdb_module_init(sdb_plugin_info_t *info) { - sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "collectd"); + sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "collectd::unixsock"); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC, - "backend accessing the system statistics collection daemon"); + "backend accessing the system statistics collection daemon " + "throught the UNIXSOCK interface"); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT, "Copyright (C) 2012 Sebastian 'tokkee' Harl "); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_LICENSE, "BSD"); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_VERSION, SDB_VERSION); sdb_plugin_set_info(info, SDB_PLUGIN_INFO_PLUGIN_VERSION, SDB_VERSION); - sdb_plugin_register_config("collectd", sdb_collectd_config); + sdb_plugin_register_config("collectd::unixsock", sdb_collectd_config); return 0; } /* sdb_version_extra */ diff --git a/src/backend/puppet-storeconfigs.c b/src/backend/puppet-storeconfigs.c index 5549f77..a798777 100644 --- a/src/backend/puppet-storeconfigs.c +++ b/src/backend/puppet-storeconfigs.c @@ -182,7 +182,7 @@ sdb_puppet_stcfg_collect(sdb_object_t *user_data) return -1; } return 0; -} /* sdb_collectd_collect */ +} /* sdb_puppet_stcfg_collect */ static int sdb_puppet_stcfg_config_conn(oconfig_item_t *ci) diff --git a/src/daemon/sysdbd.conf.sample b/src/daemon/sysdbd.conf.sample index 60a4656..7ca023a 100644 --- a/src/daemon/sysdbd.conf.sample +++ b/src/daemon/sysdbd.conf.sample @@ -24,7 +24,7 @@ Interval 300 # # #----------------------------------------------------------------------------# -LoadBackend "collectd" +LoadBackend "collectd::unixsock" LoadBackend "mk-livestatus" LoadBackend "puppet-storeconfigs" @@ -32,7 +32,7 @@ LoadBackend "puppet-storeconfigs" # Plugin configuration: # #----------------------------------------------------------------------------# - + Socket "/var/run/collectd-unixsock" -- 2.30.2