[icinga-checkins] icinga.org: icinga-mq/master: Implemented test client for events.

git at icinga.org git at icinga.org
Thu Nov 24 14:04:59 CET 2011


Module: icinga-mq
Branch: master
Commit: cbdd6429f3821dca6810c2733c626dd7f299c117
URL:    https://git.icinga.org/?p=icinga-mq.git;a=commit;h=cbdd6429f3821dca6810c2733c626dd7f299c117

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Thu Nov 24 14:04:31 2011 +0100

Implemented test client for events.

---

 imqevtclient/src/imqevtclient.c |   82 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 82 insertions(+), 0 deletions(-)

diff --git a/imqevtclient/src/imqevtclient.c b/imqevtclient/src/imqevtclient.c
new file mode 100644
index 0000000..ad76e1c
--- /dev/null
+++ b/imqevtclient/src/imqevtclient.c
@@ -0,0 +1,82 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include "libicinga.h"
+#include "imqconfig.h"
+#include "icingamq_version.h"
+
+int main(int argc, char **argv) {
+	imq_config_t *config;
+	const char *hostname, *port_str, *username, *password;
+	unsigned short port;
+	icinga_connection_t *conn;
+	icinga_event_t *event;
+	char *event_string;
+
+	fprintf(stderr, "IcingaMQ Event test client, version %s\n",
+	    ICINGAMQ_VERSION);
+
+	if (argc < 2) {
+		fprintf(stderr, "Syntax: %s <config_file>\n", argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	config = imq_parse_config(argv[1]);
+
+	if (config == NULL) {
+		fprintf(stderr, "Config file could not be parsed.\n");
+		return EXIT_FAILURE;
+	}
+
+	hostname = imq_get_config(config, "hostname");
+
+	if (hostname == NULL) {
+		fprintf(stderr, "'hostname' setting is missing in the"
+		    "config file.\n");
+		return EXIT_FAILURE;
+	}
+
+	port_str = imq_get_config(config, "port");
+
+	if (port_str == NULL) {
+		fprintf(stderr, "'port' setting is missing in the config"
+		    "file.\n");
+		return EXIT_FAILURE;
+	}
+
+	port = atoi(port_str);
+
+	username = imq_get_config(config, "username");
+
+	if (username == NULL) {
+		fprintf(stderr, "'username' setting is missing in the config"
+		    "file.\n");
+		return EXIT_FAILURE;
+	}
+
+	password = imq_get_config(config, "password");
+
+	if (password == NULL) {
+		fprintf(stderr, "'password' setting is missing in the config"
+		    "file.\n");
+		return EXIT_FAILURE;
+	}
+
+	fprintf(stderr, "Setting up IMQ connection to %s:%d...\n",
+	    hostname, port);
+
+	conn = icinga_connect(hostname, port, username, password);
+
+	if (conn == NULL)
+		return EXIT_FAILURE;
+
+	while (icinga_wait_for_event(conn, -1, &event) >= 0) {
+		event_string = cJSON_Print(event->data);
+		printf("%s\n", event_string);
+		free(event_string);
+		icinga_free_event(event);
+	}
+
+	icinga_close(conn);
+
+	return EXIT_SUCCESS;
+}





More information about the icinga-checkins mailing list