Hostgroup Hiding

Andreas Ericsson ae at op5.se
Fri Oct 27 13:48:55 CEST 2006


daniel.tuecks at computacenter.com 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                   andreas.ericsson at op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the Developers mailing list