X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectd-nagios.c;h=7fda6fc120a3aa4c94eaa640092ab2ff39724f40;hb=f0b9430b0c0f45ada6f655dd4b9c64a8cbdf8d66;hp=d6e9868c3657488f6cc2080bf51673dc97e8f8ff;hpb=ea651b1fceaf83b85aca918a89ce45818ff42f93;p=collectd.git diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index d6e9868c..7fda6fc1 100644 --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@ -66,7 +66,7 @@ # endif #endif /* NAN_ZERO_ZERO */ -#include "libcollectdclient/client.h" +#include "libcollectdclient/collectd/client.h" #define RET_OKAY 0 #define RET_WARNING 1 @@ -274,6 +274,8 @@ static int do_listval (lcc_connection_t *connection) lcc_identifier_t *ret_ident = NULL; size_t ret_ident_num = 0; + char *hostname = NULL; + int status; size_t i; @@ -285,26 +287,47 @@ static int do_listval (lcc_connection_t *connection) return (RET_UNKNOWN); } + status = lcc_sort_identifiers (connection, ret_ident, ret_ident_num); + if (status != 0) { + printf ("UNKNOWN: %s\n", lcc_strerror (connection)); + if (ret_ident != NULL) + free (ret_ident); + return (RET_UNKNOWN); + } + for (i = 0; i < ret_ident_num; ++i) { char id[1024]; if ((hostname_g != NULL) && (strcasecmp (hostname_g, ret_ident[i].host))) continue; + if ((hostname == NULL) || strcasecmp (hostname, ret_ident[i].host)) + { + free (hostname); + hostname = strdup (ret_ident[i].host); + printf ("Host: %s\n", hostname); + } + + /* empty hostname; not to be printed again */ + ret_ident[i].host[0] = '\0'; + status = lcc_identifier_to_string (connection, id, sizeof (id), ret_ident + i); if (status != 0) { printf ("ERROR: listval: Failed to convert returned " "identifier to a string: %s\n", lcc_strerror (connection)); + free (hostname); + hostname = NULL; continue; } - printf ("%s\n", id); + /* skip over the (empty) hostname and following '/' */ + printf ("\t%s\n", id + 1); } - if (ret_ident != NULL) - free (ret_ident); + free (ret_ident); + free (hostname); return (RET_OKAY); } /* int do_listval */