Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

Nagios::Plugin --extra-opts auto quote?

by Skeeve (Vicar)
on May 23, 2012 at 12:27 UTC ( #972026=perlquestion: print w/replies, xml ) Need Help??
Skeeve has asked for the wisdom of the Perl Monks concerning the following question:


I'm doing my first Nagios plugin based on Nagios::Plugins and I noticed that it automatically supports --extra-opts.

So I did my first attempt with this feature as it seem to well fit my needs.

unfortunately I observed 2 strange behaviours:

  1. I had an argument "msg|message" and this led to some weird parsing of the extra opts. My config file was like this:

    [experiment] percent=1 message=%d OK

    The result was percent was undefined and msg was set to "--percent".

    When I changed the argument to "message|msg", it worked. Now percent is set to 1 and message is set to '"%d OK"'.

    And this leads to my second strange behaviour:

  2. Every value, which contains spaces, is automatically quoted. So instead of having just

    %d OK
    I get
    "%d OK"
    . and I think this is a bug.


Some code to play with:

use strict; use warnings; use Nagios::Plugin; use Data::Dumper; my $n=Nagios::Plugin->new(version=>1,usage=>""); $n->add_arg("percent","",undef,0); $n->add_arg("msg|message=s","",undef,0); $n->getopts(); print Dumper $n->opts

Output is (shortened)

$VAR1 = bless( { : : 'msg' => '--percent', 'verbose' => 0, 'usage' => undef, 'percent' => undef, : }, 'Nagios::Plugin::Getopt' );

Which is wrong. If you change "msg|message=s" to "message|msg=s" the output will be almost correct:

$VAR1 = bless( { : : 'percent' => 1, 'version' => undef, 'message' => '"%d OK"', }, 'Nagios::Plugin::Getopt' );

More Updates

Quoting isn't done properly, I think. When I use this configuration file:

[experiment] percent=1 message="%d" OK

I get a very unusual quoted string: ""%d" OK"


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://972026]
Approved by marto
[usemodperl]: i even tried to run perl again from inside script with qx and the working one liner: nada

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2018-06-23 12:10 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (125 votes). Check out past polls.