Hi!

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.

Update

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"


s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
+.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e

In reply to Nagios::Plugin --extra-opts auto quote? by Skeeve

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.