Exploding check commands batman ...

Paul L. Allen pla at softflare.com
Fri Jul 1 16:48:45 CEST 2005


Andreas Ericsson writes: 

> I'm working on overloading the plugins a bit to support behaviour like 
> this. It will require the arguments in the check_command definition to be 
> enclosed in quotes (due to how POSIX getopt() works), but will otherwise 
> work nicely.

Sounds good. 

> I believe it's best left out of Nagios. String mangling is rather 
> expensive and error-prone. Checking if(str[0] == 0) from the command 
> executed is a fairly simple process.

Somewhat more complex for the perl plugins since they generally use
the strict pragma.  Easy for options which take string arguments and
where the string "0" is never valid or sensible: 

 $opt_x ||= $opt_x_default; 

A little extra work for options which take numeric arguments and where the
numeric value 0 is valid and sensible but some other numeric value is
the default: 

 $opt_x = $opt_x_default if ($x eq ''); 

A bigger problem for numerics if you expect the plugin to cope gracefully
if somebody manages to not pass "" as the argument for the option and the
option is therefore unitialized: 

 $opt_x = $opt_x_default if (not defined($x) or $x eq ''); 

or: 

 $opt_x .= '' # ensure $opt_x is initialized with something
 $opt_x = $opt_x_default if ($x eq ''); 

That's the price you have to pay for asking perl to do run-time checking.
Then again, the GetOpt module shouldn't be letting you get away with
specifying an option that requires an argument without giving an argument,
but I'm sure somebody will find a way. 

-- 
Paul Allen
Softflare Support 



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list