summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 59e3b2d)
raw | patch | inline | side by side (parent: 59e3b2d)
author | Sebastian Harl <sh@tokkee.org> | |
Mon, 16 May 2011 13:08:41 +0000 (15:08 +0200) | ||
committer | Sebastian Harl <sh@tokkee.org> | |
Mon, 16 May 2011 13:08:41 +0000 (15:08 +0200) |
Also, output the data for each host in a separate "section", printing the
hostname as the heading and leaving it out from any further output.
This way, the strings may directly be used as options for -H and -n.
hostname as the heading and leaving it out from any further output.
This way, the strings may directly be used as options for -H and -n.
src/collectd-nagios.c | patch | blob | history |
diff --git a/src/collectd-nagios.c b/src/collectd-nagios.c
index d6e9868c3657488f6cc2080bf51673dc97e8f8ff..88a53023fb788a7c1439d2e41bf00e71b1a0b377 100644 (file)
--- a/src/collectd-nagios.c
+++ b/src/collectd-nagios.c
lcc_identifier_t *ret_ident = NULL;
size_t ret_ident_num = 0;
+ char *hostname = NULL;
+
int status;
size_t i;
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) {
continue;
}
- printf ("%s\n", id);
+ /* skip over the (empty) hostname and following '/' */
+ printf ("\t%s\n", id + 1);
}
if (ret_ident != NULL)