[Nagios-devel] [PATCH 1/3] base/query_handler: Implement a simple

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] [PATCH 1/3] base/query_handler: Implement a simple

Post by Guest »

From: Robin Sonefors

Because the query handlers are plentiful and nifty, they're something I
should be using, but because I'm bad at remembering things and tired of
reading the source to find out how things work, I need help.

The way I can think of to get help is to try to exercise peer pressure
on whoever writes the query handler, by telling users that there should
be a help text, and then giving them errors error messages when the
query handler doesn't have any help text.

The protocol used by the help query handler for asking other handlers
for help is simply the "help" query.

Signed-off-by: Robin Sonefors
---
base/query-handler.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)

diff --git a/base/query-handler.c b/base/query-handler.c
index 8d3cfe3..51acd63 100644
--- a/base/query-handler.c
+++ b/base/query-handler.c
@@ -257,6 +257,31 @@ void qh_deinit(const char *path)
unlink(path);
}

+static int qh_help(int sd, char *buf, unsigned int len)
+{
+ struct query_handler *qh;
+ if (!strcmp(buf, "list")) {
+ int i = 0;
+ for (qh = qhandlers; qh; qh = qh->next_qh) {
+ nsock_printf(sd, "%s\n", qh->name);
+ }
+ nsock_printf(sd, 0);
+ return 0;
+ }
+ if (strcmp(buf, "help") && ((qh = qh_find_handler(buf)) != FALSE)) {
+ int res = qh->handler(sd, "help", 4);
+ if (res > 200) {
+ nsock_printf_nul(sd, "The handler %s doesn't have any help yet.", buf);
+ }
+ return 0;
+ }
+
+ nsock_printf_nul(sd, "This is the help query handler.\n"
+ "Try \"#help list\" to see all registered handlers, or\n"
+ "\"#help \" to get help on a specific handler.");
+ return 0;
+}
+
static int qh_core(int sd, char *buf, unsigned int len)
{
char *space;
@@ -342,5 +367,8 @@ int qh_init(const char *path)
if(!qh_register_handler("core", 0, qh_core))
logit(NSLOG_INFO_MESSAGE, FALSE, "qh: core query handler registered\n");

+ if(!qh_register_handler("help", 0, qh_help))
+ logit(NSLOG_INFO_MESSAGE, FALSE, "qh: help query handler registered\n");
+
return 0;
}
--
1.7.11.7






This post was automatically imported from historical nagios-devel mailing list archives
Original poster: robin.sonefors@op5.com
Locked