[PATCH 3/3] nerd: Implement query handler help

robin.sonefors at op5.com robin.sonefors at op5.com
Wed Nov 28 15:37:23 CET 2012


From: Robin Sonefors <robin.sonefors at op5.com>

This help is dynamically generated, as requested by Andreas Ericsson.

Signed-off-by: Robin Sonefors <robin.sonefors at op5.com>
---
 base/nerd.c      | 27 +++++++++++++++++++++++----
 include/nagios.h |  2 +-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/base/nerd.c b/base/nerd.c
index 897a5da..108b35b 100644
--- a/base/nerd.c
+++ b/base/nerd.c
@@ -24,6 +24,7 @@
 
 struct nerd_channel {
 	const char *name; /* name of this channel */
+	const char *description; /* user-presentable string to document the purpouse of this channel */
 	unsigned int id; /* channel id (might vary between invocations) */
 	unsigned int required_options; /* event_broker_options required for this channel */
 	unsigned int num_callbacks;
@@ -361,7 +362,7 @@ static int nerd_deinit(void)
 	return 0;
 }
 
-int nerd_mkchan(const char *name, int (*handler)(int, void *), unsigned int callbacks)
+int nerd_mkchan(const char *name, const char *description, int (*handler)(int, void *), unsigned int callbacks)
 {
 	struct nerd_channel *chan, **ptr;
 	int i;
@@ -378,6 +379,7 @@ int nerd_mkchan(const char *name, int (*handler)(int, void *), unsigned int call
 		return -1;
 
 	chan->name = name;
+	chan->description = description;
 	chan->handler = handler;
 	for(i = 0; callbacks && i < NEBCALLBACK_NUMITEMS; i++) {
 		if(!(callbacks & (1 << i)))
@@ -400,6 +402,17 @@ static int nerd_qh_handler(int sd, char *request, unsigned int len)
 	struct nerd_channel *chan;
 	int action;
 
+	if (!strcmp(request, "help")) {
+		int i;
+		nsock_printf(sd, "Manage subscriptions to NERD channels.\n"
+			"Valid commands are 'subscribe' and 'unsubscribe' to a specified channel.\n"
+			"The avalible channels are:");
+		for (i = 0; i < num_channels; i++) {
+			nsock_printf(sd, "\n  %-15s %s", channels[i]->name, channels[i]->description);
+		}
+		return 0;
+	}
+
 	while(request[len] == 0 || request[len] == '\n')
 		request[len--] = 0;
 	chan_name = strchr(request, ' ');
@@ -445,9 +458,15 @@ int nerd_init(void)
 
 	neb_add_core_module(&nerd_mod);
 
-	chan_host_checks_id = nerd_mkchan("hostchecks", chan_host_checks, nebcallback_flag(NEBCALLBACK_HOST_CHECK_DATA));
-	chan_service_checks_id = nerd_mkchan("servicechecks", chan_service_checks, nebcallback_flag(NEBCALLBACK_SERVICE_CHECK_DATA));
-	chan_opath_checks_id = nerd_mkchan("opathchecks", chan_opath_checks, nebcallback_flag(NEBCALLBACK_HOST_CHECK_DATA) | nebcallback_flag(NEBCALLBACK_SERVICE_CHECK_DATA));
+	chan_host_checks_id = nerd_mkchan("hostchecks",
+			"Get information about host checks as they're executed",
+			chan_host_checks, nebcallback_flag(NEBCALLBACK_HOST_CHECK_DATA));
+	chan_service_checks_id = nerd_mkchan("servicechecks",
+			"Get information about service checks as they're executed",
+			chan_service_checks, nebcallback_flag(NEBCALLBACK_SERVICE_CHECK_DATA));
+	chan_opath_checks_id = nerd_mkchan("opathchecks",
+			"Get all host and service check information in gource format",
+			chan_opath_checks, nebcallback_flag(NEBCALLBACK_HOST_CHECK_DATA) | nebcallback_flag(NEBCALLBACK_SERVICE_CHECK_DATA));
 
 	logit(NSLOG_INFO_MESSAGE, TRUE, "NERD initialized and ready to rock!\n");
 	return 0;
diff --git a/include/nagios.h b/include/nagios.h
index dbfe027..82cd81f 100644
--- a/include/nagios.h
+++ b/include/nagios.h
@@ -434,7 +434,7 @@ extern const char *check_result_source(check_result *cr);
 
 /*** Nagios Event Radio Dispatcher functions ***/
 extern int nerd_init(void);
-extern int nerd_mkchan(const char *name, int (*handler)(int, void *), unsigned int callbacks);
+extern int nerd_mkchan(const char *name, const char *description, int (*handler)(int, void *), unsigned int callbacks);
 
 /*** Query Handler functions, types and macros*/
 typedef int (*qh_handler)(int, char *, unsigned int);
-- 
1.7.11.7


------------------------------------------------------------------------------
Keep yourself connected to Go Parallel: 
INSIGHTS What's next for parallel hardware, programming and related areas?
Interviews and blogs by thought leaders keep you ahead of the curve.
http://goparallel.sourceforge.net




More information about the Developers mailing list