Re: [Nagios-devel] [PATCH 1/4] base/query_handler: Implement a

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

Re: [Nagios-devel] [PATCH 1/4] base/query_handler: Implement a

Post by Guest »

On 11/27/2012 05:41 PM, robin.sonefors@op5.com wrote:
> 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 I've invented for asking for help text is the "--help"
> command to the query handler - a fairly universal convention in
> unixland, and also unlikely to clash with something else.
>

Good idea. Thanks. And thanks for submitting such exemplary patches.

> 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..f9c0604 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 ((qh = qh_find_handler(buf)) != FALSE) {
> + int res = qh->handler(sd, "--help", 6);
> + 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;
> }
>


--
Andreas Ericsson andreas.ericsson@op5.se
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231

Considering the successes of the wars on alcohol, poverty, drugs and
terror, I think we should give some serious thought to declaring war
on peace.





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