Skip to content

Commit 4aa2aee

Browse files
tejrsni
authored andcommitted
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.
1 parent c039436 commit 4aa2aee

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

lib/Monitoring/Plugin/Getopt.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ sub arg
383383
my %args;
384384

385385
# 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) {
387387
%args = validate( @_, {
388388
spec => 1,
389389
help => 1,

0 commit comments

Comments
 (0)