diff options
author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-02-20 16:38:34 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-02-20 16:38:34 +0100 |
commit | a7b3bb968a2a8fae174d9e8e67f01e16cc0a8335 (patch) | |
tree | 2a140f3bf9d0b7f45017fc79d04a361fc4169847 | |
parent | 99a978b669cedb63e15b7df5b6ad81a9a63e9279 (diff) | |
parent | 0d0f4ee7e30dcd2c5f9f0c53400ed6b2a9bc14a2 (diff) | |
download | monitoring-plugins-a7b3bb968a2a8fae174d9e8e67f01e16cc0a8335.tar.gz |
Merge pull request #2065 from RincewindsHat/opttest_tool
Opttest tool
-rwxr-xr-x | opttest.pl | 50 | ||||
-rw-r--r--[-rwxr-xr-x] | plugins-scripts/check_sensors.sh | 1 | ||||
-rw-r--r-- | plugins/negate.c | 4 | ||||
-rwxr-xr-x | tools/opttest.pl | 74 |
4 files changed, 76 insertions, 53 deletions
diff --git a/opttest.pl b/opttest.pl deleted file mode 100755 index 85e3b494..00000000 --- a/opttest.pl +++ /dev/null | |||
@@ -1,50 +0,0 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | use strict; | ||
3 | use Test; | ||
4 | |||
5 | use vars qw($dir $file $prog $idx $state $output %progs @dirs); | ||
6 | |||
7 | my $tests = 0; | ||
8 | |||
9 | @dirs = qw(plugins plugins-scripts); | ||
10 | |||
11 | foreach $dir (@dirs) { | ||
12 | opendir(DIR, $dir) || die "can't opendir $dir: $!"; | ||
13 | while ($file = readdir(DIR)) { | ||
14 | if (-x "$dir/$file" && -f "$dir/$file") { | ||
15 | $tests++; | ||
16 | $progs{"$dir/$file"} = $file; | ||
17 | } | ||
18 | } | ||
19 | closedir DIR; | ||
20 | } | ||
21 | |||
22 | plan tests => $tests; | ||
23 | |||
24 | for $prog (keys %progs) { | ||
25 | $state = 0; | ||
26 | $file = `basename $prog`; | ||
27 | |||
28 | $idx = 1; | ||
29 | $output = `$prog -h 2>&1`; | ||
30 | if($?) {$state++;print "$prog failed test $idx\n";} | ||
31 | unless ($output =~ m/$progs{$prog}/ms) { | ||
32 | $idx++; $state++;print "$output\n$prog failed test $idx\n"; | ||
33 | } | ||
34 | |||
35 | $idx++; | ||
36 | `$prog --help 2>&1 > /dev/null`; | ||
37 | if($?) {$state++;print "$prog failed test $idx\n";} | ||
38 | |||
39 | $idx++; | ||
40 | `$prog -V 2>&1 > /dev/null`; | ||
41 | if($?) {$state++;print "$prog failed test $idx\n";} | ||
42 | |||
43 | $idx++; | ||
44 | `$prog --version 2>&1 > /dev/null`; | ||
45 | if($?) {$state++;print "$prog failed test $idx\n";} | ||
46 | |||
47 | print "$prog ($idx tests) "; | ||
48 | ok $state,0; | ||
49 | } | ||
50 | |||
diff --git a/plugins-scripts/check_sensors.sh b/plugins-scripts/check_sensors.sh index 866e0e0f..ba3581b1 100755..100644 --- a/plugins-scripts/check_sensors.sh +++ b/plugins-scripts/check_sensors.sh | |||
@@ -20,7 +20,6 @@ print_help() { | |||
20 | echo "This plugin checks hardware status using the lm_sensors package." | 20 | echo "This plugin checks hardware status using the lm_sensors package." |
21 | echo "" | 21 | echo "" |
22 | support | 22 | support |
23 | exit "$STATE_OK" | ||
24 | } | 23 | } |
25 | 24 | ||
26 | case "$1" in | 25 | 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) { | |||
133 | break; | 133 | break; |
134 | case 'h': /* help */ | 134 | case 'h': /* help */ |
135 | print_help(); | 135 | print_help(); |
136 | exit(EXIT_SUCCESS); | 136 | exit(STATE_UNKNOWN); |
137 | break; | 137 | break; |
138 | case 'V': /* version */ | 138 | case 'V': /* version */ |
139 | print_revision(progname, NP_VERSION); | 139 | print_revision(progname, NP_VERSION); |
140 | exit(EXIT_SUCCESS); | 140 | exit(STATE_UNKNOWN); |
141 | case 't': /* timeout period */ | 141 | case 't': /* timeout period */ |
142 | if (!is_integer(optarg)) | 142 | if (!is_integer(optarg)) |
143 | usage2(_("Timeout interval must be a positive integer"), optarg); | 143 | usage2(_("Timeout interval must be a positive integer"), optarg); |
diff --git a/tools/opttest.pl b/tools/opttest.pl new file mode 100755 index 00000000..98213082 --- /dev/null +++ b/tools/opttest.pl | |||
@@ -0,0 +1,74 @@ | |||
1 | #!/usr/bin/perl -w | ||
2 | use strict; | ||
3 | use warnings; | ||
4 | use Test; | ||
5 | |||
6 | # This script (when executed from the monitoring plugins top level directory) | ||
7 | # executes all the plugins with -h, --help, -V and --version to verify that | ||
8 | # all of them exit properly with the state UNKNOWN (3) | ||
9 | |||
10 | use vars qw($dir $file $prog $idx $state $output %progs @dirs); | ||
11 | |||
12 | my $tests = 0; | ||
13 | |||
14 | @dirs = qw(plugins plugins-scripts); | ||
15 | |||
16 | foreach my $dir (@dirs) { | ||
17 | opendir(DIR, $dir) || die "can't opendir $dir: $!"; | ||
18 | while ($file = readdir(DIR)) { | ||
19 | if (-x "$dir/$file" && -f "$dir/$file") { | ||
20 | $tests++; | ||
21 | $progs{"$dir/$file"} = $file; | ||
22 | } | ||
23 | } | ||
24 | closedir DIR; | ||
25 | } | ||
26 | |||
27 | plan tests => $tests; | ||
28 | |||
29 | for my $prog (keys %progs) { | ||
30 | $state = 0; | ||
31 | $file = `basename $prog`; | ||
32 | |||
33 | $idx = 1; | ||
34 | $output = `$prog -h 2>&1`; | ||
35 | if(($? >> 8) != 3) { | ||
36 | $state++; | ||
37 | print "$prog failed test $idx (help exit code (short form))\n"; | ||
38 | exit(1); | ||
39 | } | ||
40 | |||
41 | unless ($output =~ m/$progs{$prog}/ms) { | ||
42 | $idx++; | ||
43 | $state++; | ||
44 | print "$output\n$prog failed test $idx\n"; | ||
45 | } | ||
46 | |||
47 | $idx++; | ||
48 | `$prog --help 2>&1 > /dev/null`; | ||
49 | if(($? >> 8) != 3) { | ||
50 | $state++; | ||
51 | print "$prog failed test $idx (help exit code (long form))\n"; | ||
52 | exit(1); | ||
53 | } | ||
54 | |||
55 | $idx++; | ||
56 | `$prog -V 2>&1 > /dev/null`; | ||
57 | if(($? >> 8) != 3) { | ||
58 | $state++; | ||
59 | print "$prog failed test $idx (version exit code (short form))\n"; | ||
60 | exit(1); | ||
61 | } | ||
62 | |||
63 | $idx++; | ||
64 | `$prog --version 2>&1 > /dev/null`; | ||
65 | if(($? >> 8) != 3) { | ||
66 | $state++; | ||
67 | print "$prog failed test $idx (version exit code (long form))\n"; | ||
68 | exit(1); | ||
69 | } | ||
70 | |||
71 | print "$prog ($idx tests) "; | ||
72 | ok $state,0; | ||
73 | } | ||
74 | |||