Code

Renamed the project to SysDB (System DataBase).
[sysdb.git] / src / backend / mk-livestatus.c
index 0edbc3d..57fda52 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * syscollector - src/backend/mk-livestatus.c
+ * SysDB - src/backend/mk-livestatus.c
  * Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>
  * All rights reserved.
  *
@@ -25,7 +25,7 @@
  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "syscollector.h"
+#include "sysdb.h"
 #include "core/plugin.h"
 #include "core/store.h"
 #include "utils/string.h"
 #include <stdlib.h>
 #include <string.h>
 
-SC_PLUGIN_MAGIC;
+SDB_PLUGIN_MAGIC;
 
 /*
  * private helper functions
  */
 
 static int
-sc_livestatus_get_host(sc_unixsock_client_t __attribute__((unused)) *client,
-               size_t n, sc_data_t *data, sc_object_t __attribute__((unused)) *user_data)
+sdb_livestatus_get_host(sdb_unixsock_client_t __attribute__((unused)) *client,
+               size_t n, sdb_data_t *data,
+               sdb_object_t __attribute__((unused)) *user_data)
 {
        char *hostname = NULL;
-       sc_time_t timestamp = 0;
+       sdb_time_t timestamp = 0;
 
-       sc_host_t host = SC_HOST_INIT;
+       sdb_host_t host = SDB_HOST_INIT;
 
        int status;
 
        assert(n == 2);
-       assert((data[0].type == SC_TYPE_STRING)
-                       && (data[1].type == SC_TYPE_DATETIME));
+       assert((data[0].type == SDB_TYPE_STRING)
+                       && (data[1].type == SDB_TYPE_DATETIME));
 
        hostname  = strdup(data[0].data.string);
        timestamp = data[1].data.datetime;
@@ -68,7 +69,7 @@ sc_livestatus_get_host(sc_unixsock_client_t __attribute__((unused)) *client,
        host.host_name = hostname;
        host.host_last_update = timestamp;
 
-       status = sc_store_host(&host);
+       status = sdb_store_host(&host);
 
        if (status < 0) {
                fprintf(stderr, "MK Livestatus backend: Failed to store/update "
@@ -84,24 +85,25 @@ sc_livestatus_get_host(sc_unixsock_client_t __attribute__((unused)) *client,
                        hostname, timestamp);
        free(hostname);
        return 0;
-} /* sc_livestatus_get_host */
+} /* sdb_livestatus_get_host */
 
 static int
-sc_livestatus_get_svc(sc_unixsock_client_t __attribute__((unused)) *client,
-               size_t n, sc_data_t *data, sc_object_t __attribute__((unused)) *user_data)
+sdb_livestatus_get_svc(sdb_unixsock_client_t __attribute__((unused)) *client,
+               size_t n, sdb_data_t *data,
+               sdb_object_t __attribute__((unused)) *user_data)
 {
        char *hostname = NULL;
        char *svcname = NULL;
-       sc_time_t timestamp = 0;
+       sdb_time_t timestamp = 0;
 
-       sc_service_t svc = SC_SVC_INIT;
+       sdb_service_t svc = SDB_SVC_INIT;
 
        int status;
 
        assert(n == 3);
-       assert((data[0].type == SC_TYPE_STRING)
-                       && (data[1].type == SC_TYPE_STRING)
-                       && (data[2].type == SC_TYPE_DATETIME));
+       assert((data[0].type == SDB_TYPE_STRING)
+                       && (data[1].type == SDB_TYPE_STRING)
+                       && (data[2].type == SDB_TYPE_DATETIME));
 
        hostname  = strdup(data[0].data.string);
        svcname   = strdup(data[1].data.string);
@@ -111,7 +113,7 @@ sc_livestatus_get_svc(sc_unixsock_client_t __attribute__((unused)) *client,
        svc.svc_name = svcname;
        svc.svc_last_update = timestamp;
 
-       status = sc_store_service(&svc);
+       status = sdb_store_service(&svc);
 
        if (status < 0) {
                fprintf(stderr, "MK Livestatus backend: Failed to store/update "
@@ -129,119 +131,119 @@ sc_livestatus_get_svc(sc_unixsock_client_t __attribute__((unused)) *client,
        free(hostname);
        free(svcname);
        return 0;
-} /* sc_livestatus_get_svc */
+} /* sdb_livestatus_get_svc */
 
 /*
  * plugin API
  */
 
 static int
-sc_livestatus_init(sc_object_t *user_data)
+sdb_livestatus_init(sdb_object_t *user_data)
 {
-       sc_unixsock_client_t *client;
+       sdb_unixsock_client_t *client;
 
        if (! user_data)
                return -1;
 
-       client = SC_OBJ_WRAPPER(user_data)->data;
-       if (sc_unixsock_client_connect(client)) {
+       client = SDB_OBJ_WRAPPER(user_data)->data;
+       if (sdb_unixsock_client_connect(client)) {
                fprintf(stderr, "MK Livestatus backend: "
                                "Failed to connect to livestatus @ %s.\n",
-                               sc_unixsock_client_path(client));
+                               sdb_unixsock_client_path(client));
                return -1;
        }
 
        fprintf(stderr, "MK Livestatus backend: Successfully "
                        "connected to livestatus @ %s.\n",
-                       sc_unixsock_client_path(client));
+                       sdb_unixsock_client_path(client));
        return 0;
-} /* sc_livestatus_init */
+} /* sdb_livestatus_init */
 
 static int
-sc_livestatus_collect(sc_object_t *user_data)
+sdb_livestatus_collect(sdb_object_t *user_data)
 {
-       sc_unixsock_client_t *client;
+       sdb_unixsock_client_t *client;
 
        int status;
 
        if (! user_data)
                return -1;
 
-       client = SC_OBJ_WRAPPER(user_data)->data;
+       client = SDB_OBJ_WRAPPER(user_data)->data;
 
-       status = sc_unixsock_client_send(client, "GET hosts\r\n"
+       status = sdb_unixsock_client_send(client, "GET hosts\r\n"
                        "Columns: name last_check");
        if (status <= 0) {
                fprintf(stderr, "MK Livestatus backend: Failed to send "
                                "'GET hosts' command to livestatus @ %s.\n",
-                               sc_unixsock_client_path(client));
+                               sdb_unixsock_client_path(client));
                return -1;
        }
 
-       sc_unixsock_client_shutdown(client, SHUT_WR);
+       sdb_unixsock_client_shutdown(client, SHUT_WR);
 
-       if (sc_unixsock_client_process_lines(client, sc_livestatus_get_host,
+       if (sdb_unixsock_client_process_lines(client, sdb_livestatus_get_host,
                                /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";",
-                               /* column count */ 2, SC_TYPE_STRING, SC_TYPE_DATETIME)) {
+                               /* column count */ 2, SDB_TYPE_STRING, SDB_TYPE_DATETIME)) {
                fprintf(stderr, "MK Livestatus backend: Failed to read response "
                                "from livestatus @ %s while reading hosts.\n",
-                               sc_unixsock_client_path(client));
+                               sdb_unixsock_client_path(client));
                return -1;
        }
 
-       if ((! sc_unixsock_client_eof(client))
-                       || sc_unixsock_client_error(client)) {
+       if ((! sdb_unixsock_client_eof(client))
+                       || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
                fprintf(stderr, "MK Livestatus backend: Failed to read host "
                                "from livestatus @ %s: %s\n",
-                               sc_unixsock_client_path(client),
-                               sc_strerror(errno, errbuf, sizeof(errbuf)));
+                               sdb_unixsock_client_path(client),
+                               sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
        }
 
-       status = sc_unixsock_client_send(client, "GET services\r\n"
+       status = sdb_unixsock_client_send(client, "GET services\r\n"
                        "Columns: host_name description last_check");
        if (status <= 0) {
                fprintf(stderr, "MK Livestatus backend: Failed to send "
                                "'GET services' command to livestatus @ %s.\n",
-                               sc_unixsock_client_path(client));
+                               sdb_unixsock_client_path(client));
                return -1;
        }
 
-       sc_unixsock_client_shutdown(client, SHUT_WR);
+       sdb_unixsock_client_shutdown(client, SHUT_WR);
 
-       if (sc_unixsock_client_process_lines(client, sc_livestatus_get_svc,
+       if (sdb_unixsock_client_process_lines(client, sdb_livestatus_get_svc,
                                /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";",
-                               /* column count */ 3, SC_TYPE_STRING, SC_TYPE_STRING,
-                               SC_TYPE_DATETIME)) {
+                               /* column count */ 3, SDB_TYPE_STRING, SDB_TYPE_STRING,
+                               SDB_TYPE_DATETIME)) {
                fprintf(stderr, "MK Livestatus backend: Failed to read response "
                                "from livestatus @ %s while reading services.\n",
-                               sc_unixsock_client_path(client));
+                               sdb_unixsock_client_path(client));
                return -1;
        }
 
-       if ((! sc_unixsock_client_eof(client))
-                       || sc_unixsock_client_error(client)) {
+       if ((! sdb_unixsock_client_eof(client))
+                       || sdb_unixsock_client_error(client)) {
                char errbuf[1024];
                fprintf(stderr, "MK Livestatus backend: Failed to read services "
                                "from livestatus @ %s: %s\n",
-                               sc_unixsock_client_path(client),
-                               sc_strerror(errno, errbuf, sizeof(errbuf)));
+                               sdb_unixsock_client_path(client),
+                               sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
        }
        return 0;
-} /* sc_livestatus_collect */
+} /* sdb_livestatus_collect */
 
 static int
-sc_livestatus_config_instance(oconfig_item_t *ci)
+sdb_livestatus_config_instance(oconfig_item_t *ci)
 {
        char *name = NULL;
        char *socket = NULL;
 
        char cb_name[1024];
 
-       sc_object_t *user_data;
-       sc_unixsock_client_t *client;
+       sdb_object_t *user_data;
+       sdb_unixsock_client_t *client;
 
        int i;
 
@@ -271,34 +273,34 @@ sc_livestatus_config_instance(oconfig_item_t *ci)
        snprintf(cb_name, sizeof(cb_name), "mk-livestatus-%s", name);
        cb_name[sizeof(cb_name) - 1] = '\0';
 
-       client = sc_unixsock_client_create(socket);
+       client = sdb_unixsock_client_create(socket);
        if (! client) {
                char errbuf[1024];
                fprintf(stderr, "MK Livestatus backend: Failed to create unixsock "
-                               "client: %s\n", sc_strerror(errno, errbuf, sizeof(errbuf)));
+                               "client: %s\n", sdb_strerror(errno, errbuf, sizeof(errbuf)));
                return -1;
        }
 
-       user_data = sc_object_create_wrapper(client,
-                       (void (*)(void *))sc_unixsock_client_destroy);
+       user_data = sdb_object_create_wrapper(client,
+                       (void (*)(void *))sdb_unixsock_client_destroy);
        if (! user_data) {
-               sc_unixsock_client_destroy(client);
+               sdb_unixsock_client_destroy(client);
                fprintf(stderr, "MK Livestatus backend: Failed to "
-                               "allocate sc_object_t\n");
+                               "allocate sdb_object_t\n");
                return -1;
        }
 
-       sc_plugin_register_init(cb_name, sc_livestatus_init, user_data);
-       sc_plugin_register_collector(cb_name, sc_livestatus_collect,
+       sdb_plugin_register_init(cb_name, sdb_livestatus_init, user_data);
+       sdb_plugin_register_collector(cb_name, sdb_livestatus_collect,
                        /* interval */ NULL, user_data);
 
        /* pass control to the list */
-       sc_object_deref(user_data);
+       sdb_object_deref(user_data);
        return 0;
-} /* sc_livestatus_config_instance */
+} /* sdb_livestatus_config_instance */
 
 static int
-sc_livestatus_config(oconfig_item_t *ci)
+sdb_livestatus_config(oconfig_item_t *ci)
 {
        int i;
 
@@ -306,29 +308,29 @@ sc_livestatus_config(oconfig_item_t *ci)
                oconfig_item_t *child = ci->children + i;
 
                if (! strcasecmp(child->key, "Instance"))
-                       sc_livestatus_config_instance(child);
+                       sdb_livestatus_config_instance(child);
                else
                        fprintf(stderr, "MK Livestatus backend: Ignoring unknown config "
                                        "option '%s'.\n", child->key);
        }
        return 0;
-} /* sc_livestatus_config */
+} /* sdb_livestatus_config */
 
 int
-sc_module_init(sc_plugin_info_t *info)
+sdb_module_init(sdb_plugin_info_t *info)
 {
-       sc_plugin_set_info(info, SC_PLUGIN_INFO_NAME, "MK-Livestatus");
-       sc_plugin_set_info(info, SC_PLUGIN_INFO_DESC,
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_NAME, "MK-Livestatus");
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_DESC,
                        "backend accessing Nagios/Icinga/Shinken using MK Livestatus");
-       sc_plugin_set_info(info, SC_PLUGIN_INFO_COPYRIGHT,
+       sdb_plugin_set_info(info, SDB_PLUGIN_INFO_COPYRIGHT,
                        "Copyright (C) 2012 Sebastian 'tokkee' Harl <sh@tokkee.org>");
-       sc_plugin_set_info(info, SC_PLUGIN_INFO_LICENSE, "BSD");
-       sc_plugin_set_info(info, SC_PLUGIN_INFO_VERSION, SC_VERSION);
-       sc_plugin_set_info(info, SC_PLUGIN_INFO_PLUGIN_VERSION, SC_VERSION);
+       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);
 
-       sc_plugin_register_config("mk-livestatus", sc_livestatus_config);
+       sdb_plugin_register_config("mk-livestatus", sdb_livestatus_config);
        return 0;
-} /* sc_version_extra */
+} /* sdb_version_extra */
 
 /* vim: set tw=78 sw=4 ts=4 noexpandtab : */