Re: [Nagios-devel] Hostgroup Hiding

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] Hostgroup Hiding

Post by Guest »

[email protected] wrote:
> Hello,
>
> I am trying to develop a patch that helps me to hide certain hostgroups from the
> status cgi. I thought of something like adding a "shouldnotseeme-" prefix to the
> hostgroup alias:
>
> define hostgroup {
> hostgroup_name shown
> alias This Host Group will be displayed
> members host1,host2,host3
> }
>
> define hostgroup {
> hostgroup_name not-shown
> alias shouldnotseeme-This Host Group will not be displayed
> members host3,host4,host5
> }
>
> First of all I must admit I am no C programmer.
> I had a look at the status.c source file. Around line 3090 I found a procedure
> show_hostgroup_overview. Now I'd like to simply check there if hstgrp->alias
> contains the string "shouldnotseeme-"
> Unfortunally I do not know how to do this.
> With PHP I think it would look like this:
>
> if (strstr($hstgrp->alias, "shouldnotseeme-") != FALSE)
> {
> // don't show this one
> ..
> }
>
> But I have no idea how to write this in C :( Can someone point me in the right
> direction. Do you think this will work at all?
>

Perhaps. Fortunately for you, PHP borrows much of its style from C, so
the above would work in C as well, although it has the side-effect (both
in PHP and C) the "shouldnotseeme-" doesn't have to be a prefix, but can
instead appear anywhere in the string.

To find it only if it is the prefix (and also make the code run a little
bit faster), you should instead use

strncmp(hostgroup->alias, "shouldnotseeme-", 15);

Some may argue that memcmp() would be faster in C. On most
architectures, this is true, but it doesn't guarantee that it will stop
at a NUL char so you could possibly run into the program crashing for you.

--
Andreas Ericsson [email protected]
OP5 AB www.op5.se
Tel: +46 8-230225 Fax: +46 8-230231





This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]
Locked