X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fcollectd-nagios.c;h=271909389cfcbf716cc5d1c2270a703bd2b29c04;hb=633c3966f770e4d46651a2fe219a18d8a9907a9f;hp=d3923f1fcab46b00c29ca6f46208839d21415b2f;hpb=03326eeaf8819d87786b132b80a0e772a9c5e2b0;p=collectd.git diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c index d3923f1f..27190938 100644 --- a/src/collectd-nagios.c +++ b/src/collectd-nagios.c @@ -2,21 +2,26 @@ * collectd-nagios - src/collectd-nagios.c * Copyright (C) 2008-2010 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: - * Florian octo Forster + * Florian octo Forster **/ #if HAVE_CONFIG_H @@ -66,7 +71,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 +279,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,9 +292,31 @@ 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)) + { + if (hostname != NULL) + 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) { @@ -297,7 +326,8 @@ static int do_listval (lcc_connection_t *connection) continue; } - printf ("%s\n", id); + /* skip over the (empty) hostname and following '/' */ + printf ("\t%s\n", id + 1); } if (ret_ident != NULL)