From 73bd77ef84e40b43f2ff47d7adb569249e14954f Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 14:36:05 +0100 Subject: opttest.pl Fix Perl complaints --- opttest.pl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/opttest.pl b/opttest.pl index 85e3b494..96c4fb0a 100755 --- a/opttest.pl +++ b/opttest.pl @@ -1,5 +1,6 @@ #!/usr/bin/perl -w use strict; +use warnings; use Test; use vars qw($dir $file $prog $idx $state $output %progs @dirs); @@ -8,7 +9,7 @@ my $tests = 0; @dirs = qw(plugins plugins-scripts); -foreach $dir (@dirs) { +foreach my $dir (@dirs) { opendir(DIR, $dir) || die "can't opendir $dir: $!"; while ($file = readdir(DIR)) { if (-x "$dir/$file" && -f "$dir/$file") { @@ -21,7 +22,7 @@ foreach $dir (@dirs) { plan tests => $tests; -for $prog (keys %progs) { +for my $prog (keys %progs) { $state = 0; $file = `basename $prog`; -- cgit v1.2.3-74-g34f1 From cb5abf1981629234f4ee0e1b2ecda2b32ef1cb00 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 14:36:37 +0100 Subject: opttest.pl: Move to tools --- opttest.pl | 51 --------------------------------------------------- tools/opttest.pl | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 51 deletions(-) delete mode 100755 opttest.pl create mode 100755 tools/opttest.pl diff --git a/opttest.pl b/opttest.pl deleted file mode 100755 index 96c4fb0a..00000000 --- a/opttest.pl +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/perl -w -use strict; -use warnings; -use Test; - -use vars qw($dir $file $prog $idx $state $output %progs @dirs); - -my $tests = 0; - -@dirs = qw(plugins plugins-scripts); - -foreach my $dir (@dirs) { - opendir(DIR, $dir) || die "can't opendir $dir: $!"; - while ($file = readdir(DIR)) { - if (-x "$dir/$file" && -f "$dir/$file") { - $tests++; - $progs{"$dir/$file"} = $file; - } - } - closedir DIR; -} - -plan tests => $tests; - -for my $prog (keys %progs) { - $state = 0; - $file = `basename $prog`; - - $idx = 1; - $output = `$prog -h 2>&1`; - if($?) {$state++;print "$prog failed test $idx\n";} - unless ($output =~ m/$progs{$prog}/ms) { - $idx++; $state++;print "$output\n$prog failed test $idx\n"; - } - - $idx++; - `$prog --help 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} - - $idx++; - `$prog -V 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} - - $idx++; - `$prog --version 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} - - print "$prog ($idx tests) "; - ok $state,0; -} - diff --git a/tools/opttest.pl b/tools/opttest.pl new file mode 100755 index 00000000..96c4fb0a --- /dev/null +++ b/tools/opttest.pl @@ -0,0 +1,51 @@ +#!/usr/bin/perl -w +use strict; +use warnings; +use Test; + +use vars qw($dir $file $prog $idx $state $output %progs @dirs); + +my $tests = 0; + +@dirs = qw(plugins plugins-scripts); + +foreach my $dir (@dirs) { + opendir(DIR, $dir) || die "can't opendir $dir: $!"; + while ($file = readdir(DIR)) { + if (-x "$dir/$file" && -f "$dir/$file") { + $tests++; + $progs{"$dir/$file"} = $file; + } + } + closedir DIR; +} + +plan tests => $tests; + +for my $prog (keys %progs) { + $state = 0; + $file = `basename $prog`; + + $idx = 1; + $output = `$prog -h 2>&1`; + if($?) {$state++;print "$prog failed test $idx\n";} + unless ($output =~ m/$progs{$prog}/ms) { + $idx++; $state++;print "$output\n$prog failed test $idx\n"; + } + + $idx++; + `$prog --help 2>&1 > /dev/null`; + if($?) {$state++;print "$prog failed test $idx\n";} + + $idx++; + `$prog -V 2>&1 > /dev/null`; + if($?) {$state++;print "$prog failed test $idx\n";} + + $idx++; + `$prog --version 2>&1 > /dev/null`; + if($?) {$state++;print "$prog failed test $idx\n";} + + print "$prog ($idx tests) "; + ok $state,0; +} + -- cgit v1.2.3-74-g34f1 From b982e12ecfee9db869d443d2a8524182b7d09b13 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:43:40 +0100 Subject: Fix opttest script --- tools/opttest.pl | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/tools/opttest.pl b/tools/opttest.pl index 96c4fb0a..56a5c88f 100755 --- a/tools/opttest.pl +++ b/tools/opttest.pl @@ -28,22 +28,41 @@ for my $prog (keys %progs) { $idx = 1; $output = `$prog -h 2>&1`; - if($?) {$state++;print "$prog failed test $idx\n";} + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (help exit code (short form))\n"; + exit(1); + } + unless ($output =~ m/$progs{$prog}/ms) { - $idx++; $state++;print "$output\n$prog failed test $idx\n"; + $idx++; + $state++; + print "$output\n$prog failed test $idx\n"; } $idx++; `$prog --help 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (help exit code (long form))\n"; + exit(1); + } $idx++; - `$prog -V 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} + `$prog -V 2>&1 > /dev/null`; + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (version exit code (short form))\n"; + exit(1); + } $idx++; `$prog --version 2>&1 > /dev/null`; - if($?) {$state++;print "$prog failed test $idx\n";} + if(($? >> 8) != 3) { + $state++; + print "$prog failed test $idx (version exit code (long form))\n"; + exit(1); + } print "$prog ($idx tests) "; ok $state,0; -- cgit v1.2.3-74-g34f1 From faacf5525bef7140f67293125537a9f31ffd25a5 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:44:17 +0100 Subject: Fix wrong exit codes --- plugins-scripts/check_sensors.sh | 1 - plugins/negate.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) mode change 100755 => 100644 plugins-scripts/check_sensors.sh diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh old mode 100755 new mode 100644 index 866e0e0f..ba3581b1 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh @@ -20,7 +20,6 @@ print_help() { echo "This plugin checks hardware status using the lm_sensors package." echo "" support - exit "$STATE_OK" } case "$1" in diff --git a/plugins/negate.c b/plugins/negate.c index 7e52fe67..750c0bfb 100644 --- a/plugins/negate.c +++ b/plugins/negate.c @@ -133,11 +133,11 @@ static const char **process_arguments(int argc, char **argv) { break; case 'h': /* help */ print_help(); - exit(EXIT_SUCCESS); + exit(STATE_UNKNOWN); break; case 'V': /* version */ print_revision(progname, NP_VERSION); - exit(EXIT_SUCCESS); + exit(STATE_UNKNOWN); case 't': /* timeout period */ if (!is_integer(optarg)) usage2(_("Timeout interval must be a positive integer"), optarg); -- cgit v1.2.3-74-g34f1 From 0d0f4ee7e30dcd2c5f9f0c53400ed6b2a9bc14a2 Mon Sep 17 00:00:00 2001 From: Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> Date: Wed, 19 Feb 2025 19:46:37 +0100 Subject: Add a comment to opttest to explain the purpose --- tools/opttest.pl | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tools/opttest.pl b/tools/opttest.pl index 56a5c88f..98213082 100755 --- a/tools/opttest.pl +++ b/tools/opttest.pl @@ -3,6 +3,10 @@ use strict; use warnings; use Test; +# This script (when executed from the monitoring plugins top level directory) +# executes all the plugins with -h, --help, -V and --version to verify that +# all of them exit properly with the state UNKNOWN (3) + use vars qw($dir $file $prog $idx $state $output %progs @dirs); my $tests = 0; -- cgit v1.2.3-74-g34f1