X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fbackend%2Fmk-livestatus.c;h=dea6794080ed9a284581de5b664f42d040c077a8;hb=be91931ffb7a5a9d109f3495a9803ef25f37627e;hp=f65e7589437b5073770020424de0c01f86ad5146;hpb=a6bb88e99588be4c62aa7a81bfae643b3c1888fa;p=sysdb.git diff --git a/src/backend/mk-livestatus.c b/src/backend/mk-livestatus.c index f65e758..dea6794 100644 --- a/src/backend/mk-livestatus.c +++ b/src/backend/mk-livestatus.c @@ -28,8 +28,7 @@ #include "sysdb.h" #include "core/plugin.h" #include "core/store.h" -#include "utils/error.h" -#include "utils/string.h" +#include "core/error.h" #include "utils/unixsock.h" #include "liboconfig/utils.h" @@ -67,22 +66,22 @@ sdb_livestatus_get_host(sdb_unixsock_client_t __attribute__((unused)) *client, hostname = strdup(data[0].data.string); timestamp = data[1].data.datetime; - host.host_name = hostname; - host.host_last_update = timestamp; + SDB_OBJ(&host)->name = hostname; + host._last_update = timestamp; status = sdb_store_host(&host); if (status < 0) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to " - "store/update host '%s'.\n", hostname); + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to " + "store/update host '%s'.", hostname); free(hostname); return -1; } else if (status > 0) /* value too old */ return 0; - sdb_error_set(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated " - "host '%s' (last update timestamp = %"PRIscTIME").\n", + sdb_log(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated " + "host '%s' (last update timestamp = %"PRIscTIME").", hostname, timestamp); free(hostname); return 0; @@ -111,14 +110,14 @@ sdb_livestatus_get_svc(sdb_unixsock_client_t __attribute__((unused)) *client, timestamp = data[2].data.datetime; svc.hostname = hostname; - svc.svc_name = svcname; - svc.svc_last_update = timestamp; + SDB_OBJ(&svc)->name = svcname; + svc._last_update = timestamp; status = sdb_store_service(&svc); if (status < 0) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to " - "store/update service '%s / %s'.\n", hostname, svcname); + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to " + "store/update service '%s / %s'.", hostname, svcname); free(hostname); free(svcname); return -1; @@ -126,8 +125,8 @@ sdb_livestatus_get_svc(sdb_unixsock_client_t __attribute__((unused)) *client, else if (status > 0) /* value too old */ return 0; - sdb_error_set(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated " - "service '%s / %s' (last update timestamp = %"PRIscTIME").\n", + sdb_log(SDB_LOG_DEBUG, "MK Livestatus backend: Added/updated " + "service '%s / %s' (last update timestamp = %"PRIscTIME").", hostname, svcname, timestamp); free(hostname); free(svcname); @@ -148,14 +147,14 @@ sdb_livestatus_init(sdb_object_t *user_data) client = SDB_OBJ_WRAPPER(user_data)->data; if (sdb_unixsock_client_connect(client)) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: " - "Failed to connect to livestatus @ %s.\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: " + "Failed to connect to livestatus @ %s.", sdb_unixsock_client_path(client)); return -1; } - sdb_error_set(SDB_LOG_INFO, "MK Livestatus backend: Successfully " - "connected to livestatus @ %s.\n", + sdb_log(SDB_LOG_INFO, "MK Livestatus backend: Successfully " + "connected to livestatus @ %s.", sdb_unixsock_client_path(client)); return 0; } /* sdb_livestatus_init */ @@ -175,8 +174,8 @@ sdb_livestatus_collect(sdb_object_t *user_data) status = sdb_unixsock_client_send(client, "GET hosts\r\n" "Columns: name last_check"); if (status <= 0) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to send " - "'GET hosts' command to livestatus @ %s.\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to send " + "'GET hosts' command to livestatus @ %s.", sdb_unixsock_client_path(client)); return -1; } @@ -186,8 +185,8 @@ sdb_livestatus_collect(sdb_object_t *user_data) if (sdb_unixsock_client_process_lines(client, sdb_livestatus_get_host, /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";", /* column count */ 2, SDB_TYPE_STRING, SDB_TYPE_DATETIME)) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " - "response from livestatus @ %s while reading hosts.\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " + "response from livestatus @ %s while reading hosts.", sdb_unixsock_client_path(client)); return -1; } @@ -195,8 +194,8 @@ sdb_livestatus_collect(sdb_object_t *user_data) if ((! sdb_unixsock_client_eof(client)) || sdb_unixsock_client_error(client)) { char errbuf[1024]; - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " - "host from livestatus @ %s: %s\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " + "host from livestatus @ %s: %s", sdb_unixsock_client_path(client), sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; @@ -205,8 +204,8 @@ sdb_livestatus_collect(sdb_object_t *user_data) status = sdb_unixsock_client_send(client, "GET services\r\n" "Columns: host_name description last_check"); if (status <= 0) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to send " - "'GET services' command to livestatus @ %s.\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to send " + "'GET services' command to livestatus @ %s.", sdb_unixsock_client_path(client)); return -1; } @@ -217,8 +216,8 @@ sdb_livestatus_collect(sdb_object_t *user_data) /* user data */ NULL, /* -> EOF */ -1, /* delim */ ";", /* column count */ 3, SDB_TYPE_STRING, SDB_TYPE_STRING, SDB_TYPE_DATETIME)) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " - "response from livestatus @ %s while reading services.\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " + "response from livestatus @ %s while reading services.", sdb_unixsock_client_path(client)); return -1; } @@ -226,8 +225,8 @@ sdb_livestatus_collect(sdb_object_t *user_data) if ((! sdb_unixsock_client_eof(client)) || sdb_unixsock_client_error(client)) { char errbuf[1024]; - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " - "services from livestatus @ %s: %s\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to read " + "services from livestatus @ %s: %s", sdb_unixsock_client_path(client), sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; @@ -249,8 +248,8 @@ sdb_livestatus_config_instance(oconfig_item_t *ci) int i; if (oconfig_get_string(ci, &name)) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Instance requires " - "a single string argument\n\tUsage: \n"); + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Instance requires " + "a single string argument\n\tUsage: "); return -1; } @@ -260,35 +259,35 @@ sdb_livestatus_config_instance(oconfig_item_t *ci) if (! strcasecmp(child->key, "Socket")) oconfig_get_string(child, &socket_path); else - sdb_error_set(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring " - "unknown config option '%s' inside .\n", + sdb_log(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring " + "unknown config option '%s' inside .", child->key, name); } if (! socket_path) { - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Instance '%s' " - "missing the 'Socket' option.\n", name); + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Instance '%s' " + "missing the 'Socket' option.", name); return -1; } - snprintf(cb_name, sizeof(cb_name), "mk-livestatus-%s", name); + snprintf(cb_name, sizeof(cb_name), "mk-livestatus::%s", name); cb_name[sizeof(cb_name) - 1] = '\0'; client = sdb_unixsock_client_create(socket_path); if (! client) { char errbuf[1024]; - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to create " - "unixsock client: %s\n", + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to create " + "unixsock client: %s", sdb_strerror(errno, errbuf, sizeof(errbuf))); return -1; } - user_data = sdb_object_create_wrapper(client, + user_data = sdb_object_create_wrapper("unixsock-client", client, (void (*)(void *))sdb_unixsock_client_destroy); if (! user_data) { sdb_unixsock_client_destroy(client); - sdb_error_set(SDB_LOG_ERR, "MK Livestatus backend: Failed to " - "allocate sdb_object_t\n"); + sdb_log(SDB_LOG_ERR, "MK Livestatus backend: Failed to " + "allocate sdb_object_t"); return -1; } @@ -312,8 +311,8 @@ sdb_livestatus_config(oconfig_item_t *ci) if (! strcasecmp(child->key, "Instance")) sdb_livestatus_config_instance(child); else - sdb_error_set(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring " - "unknown config option '%s'.\n", child->key); + sdb_log(SDB_LOG_WARNING, "MK Livestatus backend: Ignoring " + "unknown config option '%s'.", child->key); } return 0; } /* sdb_livestatus_config */