diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-10-25 10:03:18 +1300 |
---|---|---|
committer | Sven Nierlein <sven@nierlein.de> | 2017-11-15 11:42:10 +0100 |
commit | 4aa2aee51b54cb8988d87a01d1a3b9a0d90bb8bf (patch) | |
tree | 9829b80c8abd26f0c83e142298a48a9202b2c10a | |
parent | c03943635354cf1fe4d1d6e5d1a5c60acd6126db (diff) | |
download | monitoring-plugin-perl-4aa2aee.tar.gz |
Add missing `label` key to named Getopts args
If the `label` key is given as a named argument for argument
specification, if it turns out to be the first element returned in the
argument list subject to hash randomization, then this test for named
arguments fails due to the omission of the label from this alternating
group in the pattern.
When this happens, the code for an unnamed list of items was run
instead, leading to a very confusing area happening randomly:
8 parameters were passed to Monitoring::Plugin::Getopt::arg but 2 - 5 were expected
at PERL/lib/perl5/Monitoring/Plugin/Getopt.pm line 397.
Monitoring::Plugin::Getopt::arg(undef, "label", "HOSTNAME", "required", 1, "help", "Hostname of device to check", "spec", ...) called at PERL/lib/perl5/Monitoring/Plugin.pm line 161
Monitoring::Plugin::add_arg(Monitoring::Plugin=HASH(0x1f90fd8), "label", "HOSTNAME", "required", 1, "help", "Hostname of device to check", "spec", ...) called at libexec/check_example line 144
If you specified all five keys for your argument, then this happens
(roughly) one-fifth of the time.
-rw-r--r-- | lib/Monitoring/Plugin/Getopt.pm | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/Monitoring/Plugin/Getopt.pm b/lib/Monitoring/Plugin/Getopt.pm index 9452058..262e3c8 100644 --- a/lib/Monitoring/Plugin/Getopt.pm +++ b/lib/Monitoring/Plugin/Getopt.pm | |||
@@ -383,7 +383,7 @@ sub arg | |||
383 | my %args; | 383 | my %args; |
384 | 384 | ||
385 | # Named args | 385 | # Named args |
386 | if ($_[0] =~ m/^(spec|help|required|default)$/ && scalar(@_) % 2 == 0) { | 386 | if ($_[0] =~ m/^(spec|help|required|default|label)$/ && scalar(@_) % 2 == 0) { |
387 | %args = validate( @_, { | 387 | %args = validate( @_, { |
388 | spec => 1, | 388 | spec => 1, |
389 | help => 1, | 389 | help => 1, |