[Nagiosplug-devel] Nagios:Plugin feedback
Thomas Guyot-Sionnest
dermoth at aei.ca
Fri Jan 19 06:09:51 CET 2007
On 18/01/07 10:46 PM, Gavin Carr wrote:
> On Thu, Jan 18, 2007 at 02:13:53PM -0800, Thomas Guyot-Sionnest wrote:
>>
>> Would look like this (Not 100% sure about the syntax, I'm not a Perl guru ):
>> $p->add_arg(
>> spec => 'name|n=s',
>> help => qq{-n, --name=<name>)
>> check => &namecheck
>> failure => "Name argument must me a name"
>> );
>
> My feeling is that we wouldn't add datatype stuff to Nagios::Plugin,
> largely because it's pretty well covered already in other CPAN modules.
>
> The idea of adding explicit checks to arguments is interesting though.
> I'll have to think about that. If we did this, we'd presumably want
> an interface that would allow multiple checks and messages though, I
> guess?
Oh BTW I meant :
check => &$namecheck
Though I think you can also do this (right?):
check => sub { yada yada yada; if true return 1; return 0 }
I'm not good at that kind of Perl programming, but can you check
whenever you get a scalar or an array?
A good compromise would be:
if $failure is a scalar, then just test the sub ($check). if test fails
(return 0) exit with $failure text.
if $failure is an array, test the sub ($ret being the return code). If
$failure[$ret] is defined, exit with failure[$ret] text
I.e.:
$p->add_arg(
spec => 'name|n=s',
help => qq{-n, --name=<name>)
check => sub { if bad return 1; if invalid return 2; return 0 },
failure => (undef, 'Bad name', 'Invalid name'),
);
What do you think? Do you have a better idea?
Thomas
More information about the Devel
mailing list