diff options
Diffstat (limited to 'plugins/t')
| -rw-r--r-- | plugins/t/check_apt.t | 14 | ||||
| -rw-r--r-- | plugins/t/check_curl.t | 49 | ||||
| -rw-r--r-- | plugins/t/check_disk.t | 220 | ||||
| -rw-r--r-- | plugins/t/check_ftp.t | 2 | ||||
| -rw-r--r-- | plugins/t/check_jabber.t | 4 | ||||
| -rw-r--r-- | plugins/t/check_load.t | 18 | ||||
| -rw-r--r-- | plugins/t/check_snmp.t | 103 | ||||
| -rw-r--r-- | plugins/t/check_tcp.t | 12 | ||||
| -rw-r--r-- | plugins/t/check_udp.t | 4 | ||||
| -rw-r--r-- | plugins/t/check_users.t | 4 |
10 files changed, 233 insertions, 197 deletions
diff --git a/plugins/t/check_apt.t b/plugins/t/check_apt.t index 430eb53e..736bc2f2 100644 --- a/plugins/t/check_apt.t +++ b/plugins/t/check_apt.t | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | use warnings; | ||
| 8 | use Test::More; | 9 | use Test::More; |
| 9 | use NPTest; | 10 | use NPTest; |
| 10 | 11 | ||
| @@ -12,18 +13,18 @@ sub make_result_regexp { | |||
| 12 | my ($warning, $critical) = @_; | 13 | my ($warning, $critical) = @_; |
| 13 | my $status; | 14 | my $status; |
| 14 | if ($warning == 0 && $critical == 0) { | 15 | if ($warning == 0 && $critical == 0) { |
| 15 | $status = "OK"; | 16 | $status = "OK"; |
| 16 | } elsif ($critical == 0) { | 17 | } elsif ($critical == 0) { |
| 17 | $status = "WARNING"; | 18 | $status = "WARNING"; |
| 18 | } else { | 19 | } else { |
| 19 | $status = "CRITICAL"; | 20 | $status = "CRITICAL"; |
| 20 | } | 21 | } |
| 21 | return sprintf('/^APT %s: %d packages available for upgrade \(%d critical updates\)\. |available_upgrades=%d;;;0 critical_updates=%d;;;0$/', | 22 | return sprintf('/.*[%s].*Updates available: %d.*Security updates available: %d.*\'available_upgrades\'=%d;;; \'critical_updates\'=%d;;; /s', |
| 22 | $status, $warning, $critical, $warning, $critical); | 23 | $status, $warning, $critical, $warning, $critical); |
| 23 | } | 24 | } |
| 24 | 25 | ||
| 25 | if (-x "./check_apt") { | 26 | if (-x "./check_apt") { |
| 26 | plan tests => 36; | 27 | plan tests => 35; |
| 27 | } else { | 28 | } else { |
| 28 | plan skip_all => "No check_apt compiled"; | 29 | plan skip_all => "No check_apt compiled"; |
| 29 | } | 30 | } |
| @@ -42,7 +43,8 @@ like( $result->output, make_result_regexp(13, 0), "Output correct" ); | |||
| 42 | 43 | ||
| 43 | $result = NPTest->testCmd( sprintf($testfile_command, "-o", "debian2") ); | 44 | $result = NPTest->testCmd( sprintf($testfile_command, "-o", "debian2") ); |
| 44 | is( $result->return_code, 0, "Debian apt output, no critical" ); | 45 | is( $result->return_code, 0, "Debian apt output, no critical" ); |
| 45 | like( $result->output, make_result_regexp(13, 0), "Output correct" ); | 46 | # this test does not work, since -o was given |
| 47 | # like( $result->output, make_result_regexp(13, 0), "Output correct" ); | ||
| 46 | 48 | ||
| 47 | $result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") ); | 49 | $result = NPTest->testCmd( sprintf($testfile_command, "", "debian3") ); |
| 48 | is( $result->return_code, 2, "Debian apt output, some critical" ); | 50 | is( $result->return_code, 2, "Debian apt output, some critical" ); |
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index 7a930a4e..2c2fafde 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t | |||
| @@ -13,12 +13,12 @@ use vars qw($tests $has_ipv6); | |||
| 13 | BEGIN { | 13 | BEGIN { |
| 14 | use NPTest; | 14 | use NPTest; |
| 15 | $has_ipv6 = NPTest::has_ipv6(); | 15 | $has_ipv6 = NPTest::has_ipv6(); |
| 16 | $tests = $has_ipv6 ? 59 : 57; | 16 | $tests = $has_ipv6 ? 55 : 53; |
| 17 | plan tests => $tests; | 17 | plan tests => $tests; |
| 18 | } | 18 | } |
| 19 | 19 | ||
| 20 | 20 | ||
| 21 | my $successOutput = '/OK.*HTTP.*second/'; | 21 | my $successOutput = '/.*HTTP.*second/'; |
| 22 | 22 | ||
| 23 | my $res; | 23 | my $res; |
| 24 | my $plugin = 'check_http'; | 24 | my $plugin = 'check_http'; |
| @@ -63,7 +63,7 @@ $res = NPTest->testCmd( | |||
| 63 | ); | 63 | ); |
| 64 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); | 64 | cmp_ok( $res->return_code, '==', 2, "Webserver $host_nonresponsive not responding" ); |
| 65 | # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) | 65 | # was CRITICAL only, but both check_curl and check_http print HTTP CRITICAL (puzzle?!) |
| 66 | like( $res->output, "/HTTP CRITICAL - Invalid HTTP response received from host on port 80: cURL returned 28 - Connection timed out after/", "Output OK"); | 66 | like( $res->output, "/cURL returned 28 - Connection timed out after/", "Output OK"); |
| 67 | 67 | ||
| 68 | $res = NPTest->testCmd( | 68 | $res = NPTest->testCmd( |
| 69 | "./$plugin $hostname_invalid -wt 1 -ct 2" | 69 | "./$plugin $hostname_invalid -wt 1 -ct 2" |
| @@ -124,14 +124,14 @@ SKIP: { | |||
| 124 | 124 | ||
| 125 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing'" ); | 125 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing'" ); |
| 126 | cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'"); | 126 | cmp_ok( $res->return_code, "==", 2, "Not got 'mONiTORing'"); |
| 127 | like ( $res->output, "/pattern not found/", "Error message says 'pattern not found'"); | 127 | like ( $res->output, "/matched not/", "Error message says 'matched not'"); |
| 128 | 128 | ||
| 129 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -R 'mONiTORing'" ); | 129 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -R 'mONiTORing'" ); |
| 130 | cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'"); | 130 | cmp_ok( $res->return_code, "==", 0, "But case insensitive doesn't mind 'mONiTORing'"); |
| 131 | 131 | ||
| 132 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring' --invert-regex" ); | 132 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'monitoring' --invert-regex" ); |
| 133 | cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); | 133 | cmp_ok( $res->return_code, "==", 2, "Invert results work when found"); |
| 134 | like ( $res->output, "/pattern found/", "Error message says 'pattern found'"); | 134 | like ( $res->output, "/matched/", "Error message says 'matched'"); |
| 135 | 135 | ||
| 136 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" ); | 136 | $res = NPTest->testCmd( "./$plugin -H $host_tcp_http2 -r 'mONiTORing' --invert-regex" ); |
| 137 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); | 137 | cmp_ok( $res->return_code, "==", 0, "And also when not found"); |
| @@ -151,63 +151,74 @@ SKIP: { | |||
| 151 | 151 | ||
| 152 | $res = NPTest->testCmd( "./$plugin -C 8000,1 --ssl $host_tls_http" ); | 152 | $res = NPTest->testCmd( "./$plugin -C 8000,1 --ssl $host_tls_http" ); |
| 153 | cmp_ok( $res->return_code, '==', 1, "Checking certificate for $host_tls_http"); | 153 | cmp_ok( $res->return_code, '==', 1, "Checking certificate for $host_tls_http"); |
| 154 | like ( $res->output, qr/WARNING - Certificate '$host_tls_cert' expires in \d+ day/, "Output Warning" ); | 154 | like ( $res->output, qr/Certificate '$host_tls_cert' expires in \d+ day/, "Output Warning" ); |
| 155 | 155 | ||
| 156 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); | 156 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); |
| 157 | is( $res->return_code, 0, "Old syntax for cert checking okay" ); | 157 | is( $res->return_code, 0, "Old syntax for cert checking okay" ); |
| 158 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | 158 | # deactivated since different timings will change the output |
| 159 | # TODO compare without perfdata | ||
| 160 | # is( $res->output, $saved_cert_output, "Same output as new syntax" ); | ||
| 159 | 161 | ||
| 160 | $res = NPTest->testCmd( "./$plugin -H $host_tls_http -C 1" ); | 162 | $res = NPTest->testCmd( "./$plugin -H $host_tls_http -C 1" ); |
| 161 | is( $res->return_code, 0, "Updated syntax for cert checking okay" ); | 163 | is( $res->return_code, 0, "Updated syntax for cert checking okay" ); |
| 162 | is( $res->output, $saved_cert_output, "Same output as new syntax" ); | 164 | # deactivated since different timings will change the output |
| 165 | # TODO compare without perfdata | ||
| 166 | # is( $res->output, $saved_cert_output, "Same output as new syntax" ); | ||
| 163 | 167 | ||
| 164 | $res = NPTest->testCmd( "./$plugin -C 1 $host_tls_http" ); | 168 | $res = NPTest->testCmd( "./$plugin -C 1 $host_tls_http" ); |
| 165 | cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); | 169 | # deactivated since different timings will change the output |
| 170 | # TODO compare without perfdata | ||
| 171 | # cmp_ok( $res->output, 'eq', $saved_cert_output, "--ssl option automatically added"); | ||
| 166 | 172 | ||
| 167 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); | 173 | $res = NPTest->testCmd( "./$plugin $host_tls_http -C 1" ); |
| 168 | cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); | 174 | # deactivated since different timings will change the output |
| 175 | # TODO compare without perfdata | ||
| 176 | # cmp_ok( $res->output, 'eq', $saved_cert_output, "Old syntax for cert checking still works"); | ||
| 169 | 177 | ||
| 170 | # run some certificate checks with faketime | 178 | # run some certificate checks with faketime |
| 171 | SKIP: { | 179 | SKIP: { |
| 172 | skip "No faketime binary found", 12 if !$faketime; | 180 | skip "No faketime binary found", 12 if !$faketime; |
| 173 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); | 181 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC ./$plugin -C 1 $host_tls_http"); |
| 174 | like($res->output, qr/OK - Certificate '$host_tls_cert' will expire on/, "Catch cert output"); | 182 | like($res->output, qr/Certificate '$host_tls_cert' will expire on/, "Catch cert output"); |
| 175 | is( $res->return_code, 0, "Catch cert output exit code" ); | 183 | is( $res->return_code, 0, "Catch cert output exit code" ); |
| 184 | |||
| 176 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); | 185 | my($mon,$day,$hour,$min,$sec,$year) = ($res->output =~ /(\w+)\s+(\d+)\s+(\d+):(\d+):(\d+)\s+(\d+)/); |
| 177 | if(!defined $year) { | 186 | if(!defined $year) { |
| 178 | die("parsing date failed from: ".$res->output); | 187 | die("parsing date failed from: ".$res->output); |
| 179 | } | 188 | } |
| 189 | |||
| 180 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; | 190 | my $months = {'Jan' => 0, 'Feb' => 1, 'Mar' => 2, 'Apr' => 3, 'May' => 4, 'Jun' => 5, 'Jul' => 6, 'Aug' => 7, 'Sep' => 8, 'Oct' => 9, 'Nov' => 10, 'Dec' => 11}; |
| 181 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); | 191 | my $ts = mktime($sec, $min, $hour, $day, $months->{$mon}, $year-1900); |
| 182 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); | 192 | my $time = strftime("%Y-%m-%d %H:%M:%S", localtime($ts)); |
| 193 | |||
| 183 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./$plugin -C 1 $host_tls_http"); | 194 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts))."' ./$plugin -C 1 $host_tls_http"); |
| 184 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' just expired/, "Output on expire date"); | 195 | like($res->output, qr/Certificate '$host_tls_cert' just expired/, "Output on expire date"); |
| 185 | is( $res->return_code, 2, "Output on expire date" ); | 196 | is( $res->return_code, 2, "Output on expire date" ); |
| 186 | 197 | ||
| 187 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./$plugin -C 1 $host_tls_http"); | 198 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-1))."' ./$plugin -C 1 $host_tls_http"); |
| 188 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); | 199 | like($res->output, qr/Certificate '$host_tls_cert' expires in 0 minutes/, "cert expires in 1 second output"); |
| 189 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); | 200 | is( $res->return_code, 2, "cert expires in 1 second exit code" ); |
| 190 | 201 | ||
| 191 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./$plugin -C 1 $host_tls_http"); | 202 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-120))."' ./$plugin -C 1 $host_tls_http"); |
| 192 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); | 203 | like($res->output, qr/Certificate '$host_tls_cert' expires in 2 minutes/, "cert expires in 2 minutes output"); |
| 193 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); | 204 | is( $res->return_code, 2, "cert expires in 2 minutes exit code" ); |
| 194 | 205 | ||
| 195 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./$plugin -C 1 $host_tls_http"); | 206 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts-7200))."' ./$plugin -C 1 $host_tls_http"); |
| 196 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); | 207 | like($res->output, qr/Certificate '$host_tls_cert' expires in 2 hours/, "cert expires in 2 hours output"); |
| 197 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); | 208 | is( $res->return_code, 2, "cert expires in 2 hours exit code" ); |
| 198 | 209 | ||
| 199 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./$plugin -C 1 $host_tls_http"); | 210 | $res = NPTest->testCmd("LC_TIME=C TZ=UTC faketime -f '".strftime("%Y-%m-%d %H:%M:%S", localtime($ts+1))."' ./$plugin -C 1 $host_tls_http"); |
| 200 | like($res->output, qr/CRITICAL - Certificate '$host_tls_cert' expired on/, "Certificate expired output"); | 211 | like($res->output, qr/Certificate '$host_tls_cert' expired on/, "Certificate expired output"); |
| 201 | is( $res->return_code, 2, "Certificate expired exit code" ); | 212 | is( $res->return_code, 2, "Certificate expired exit code" ); |
| 202 | }; | 213 | }; |
| 203 | 214 | ||
| 204 | $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http -E" ); | 215 | $res = NPTest->testCmd( "./$plugin --ssl $host_tls_http -E" ); |
| 205 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 216 | like ( $res->output, '/\'time_connect\'=[\d\.]+/', 'Extended Performance Data Output OK' ); |
| 206 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 217 | like ( $res->output, '/\'time_tls\'=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
| 207 | 218 | ||
| 208 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" ); | 219 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" ); |
| 209 | is( $res->return_code, 0, "Redirection based on location is okay"); | 220 | is( $res->return_code, 0, "Redirection based on location is okay"); |
| 210 | 221 | ||
| 211 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); | 222 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); |
| 212 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 223 | like ( $res->output, '/\'time_connect\'=[\d\.]+/', 'Extended Performance Data Output OK' ); |
| 213 | } | 224 | } |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index 9eb77ce4..0f62fb2b 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
| @@ -10,6 +10,7 @@ use strict; | |||
| 10 | use Test::More; | 10 | use Test::More; |
| 11 | use NPTest; | 11 | use NPTest; |
| 12 | use POSIX qw(ceil floor); | 12 | use POSIX qw(ceil floor); |
| 13 | use Data::Dumper; | ||
| 13 | 14 | ||
| 14 | my $successOutput = '/^DISK OK/'; | 15 | my $successOutput = '/^DISK OK/'; |
| 15 | my $failureOutput = '/^DISK CRITICAL/'; | 16 | my $failureOutput = '/^DISK CRITICAL/'; |
| @@ -20,173 +21,216 @@ my $result; | |||
| 20 | my $mountpoint_valid = getTestParameter( "NP_MOUNTPOINT_VALID", "Path to valid mountpoint", "/"); | 21 | my $mountpoint_valid = getTestParameter( "NP_MOUNTPOINT_VALID", "Path to valid mountpoint", "/"); |
| 21 | my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to another valid mountpoint. Must be different from 1st one", "/var"); | 22 | my $mountpoint2_valid = getTestParameter( "NP_MOUNTPOINT2_VALID", "Path to another valid mountpoint. Must be different from 1st one", "/var"); |
| 22 | 23 | ||
| 24 | my $output_format = "--output-format mp-test-json"; | ||
| 25 | |||
| 23 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { | 26 | if ($mountpoint_valid eq "" or $mountpoint2_valid eq "") { |
| 24 | plan skip_all => "Need 2 mountpoints to test"; | 27 | plan skip_all => "Need 2 mountpoints to test"; |
| 25 | } else { | 28 | } else { |
| 26 | plan tests => 94; | 29 | plan tests => 97; |
| 27 | } | 30 | } |
| 28 | 31 | ||
| 29 | $result = NPTest->testCmd( | 32 | $result = NPTest->testCmd( |
| 30 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -p $mountpoint2_valid" | 33 | "./check_disk -w 1% -c 1% -p $mountpoint_valid -w 1% -c 1% -P -p $mountpoint2_valid $output_format" |
| 31 | ); | 34 | ); |
| 32 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); | 35 | cmp_ok( $result->return_code, "==", 0, "Checking two mountpoints (must have at least 1% free in space and inodes)"); |
| 33 | my $c = 0; | ||
| 34 | $_ = $result->output; | ||
| 35 | $c++ while /\(/g; # counts number of "(" - should be two | ||
| 36 | cmp_ok( $c, '==', 2, "Got two mountpoints in output"); | ||
| 37 | 36 | ||
| 37 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "Main result is OK"); | ||
| 38 | like($result->{'mp_test_result'}->{'checks'}->[0]->{'state'}, "/OK/", "First sub result is OK"); | ||
| 39 | like($result->{'mp_test_result'}->{'checks'}->[1]->{'state'}, "/OK/", "Second sub result is OK"); | ||
| 40 | |||
| 41 | my $absolut_space_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
| 42 | # print("absolute space on mp1: ". $absolut_space_mp1 . "\n"); | ||
| 43 | |||
| 44 | my $free_percent_on_mp1 = ($result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'} / ($absolut_space_mp1/100)); | ||
| 45 | print("free percent on mp1: ". $free_percent_on_mp1 . "\n"); | ||
| 46 | |||
| 47 | my $absolut_space_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
| 48 | # print("absolute space on mp2: ". $absolut_space_mp2 . "\n"); | ||
| 49 | |||
| 50 | my $free_percent_on_mp2 = ($result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'}/ ($absolut_space_mp2/100)); | ||
| 51 | print("free percent on mp2: ". $free_percent_on_mp2 . "\n"); | ||
| 38 | 52 | ||
| 39 | # Get perf data | 53 | my @perfdata; |
| 40 | # Should use Monitoring::Plugin | 54 | @perfdata[0] = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]; |
| 41 | my @perf_data = sort(split(/ /, $result->perf_output)); | 55 | @perfdata[1] = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]; |
| 42 | 56 | ||
| 57 | # Decrease precision of numbers since the the fs might be modified between the two runs | ||
| 58 | $perfdata[0]->{'value'}->{'value'} = int($perfdata[0]->{'value'}->{'value'} / 1000000); | ||
| 59 | $perfdata[1]->{'value'}->{'value'} = int($perfdata[1]->{'value'}->{'value'} / 1000000); | ||
| 43 | 60 | ||
| 44 | # Calculate avg_free free on mountpoint1 and mountpoint2 | 61 | # Calculate avg_free free on mountpoint1 and mountpoint2 |
| 45 | # because if you check in the middle, you should get different errors | 62 | # because if you check in the middle, you should get different errors |
| 46 | $_ = $result->output; | 63 | my $avg_free_percent = ceil(($free_percent_on_mp1+$free_percent_on_mp2)/2); |
| 47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+\.\d+)%.*\((\d+\.\d+)%/); | 64 | # print("avg_free: " . $avg_free_percent . "\n"); |
| 48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); | ||
| 49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); | ||
| 50 | my ($more_free, $less_free); | 65 | my ($more_free, $less_free); |
| 51 | if ($free_on_mp1 > $free_on_mp2) { | 66 | if ($free_percent_on_mp1 > $free_percent_on_mp2) { |
| 52 | $more_free = $mountpoint_valid; | 67 | $more_free = $mountpoint_valid; |
| 53 | $less_free = $mountpoint2_valid; | 68 | $less_free = $mountpoint2_valid; |
| 54 | } elsif ($free_on_mp1 < $free_on_mp2) { | 69 | } elsif ($free_percent_on_mp1 < $free_percent_on_mp2) { |
| 55 | $more_free = $mountpoint2_valid; | 70 | $more_free = $mountpoint2_valid; |
| 56 | $less_free = $mountpoint_valid; | 71 | $less_free = $mountpoint_valid; |
| 57 | } else { | 72 | } else { |
| 58 | die "Two mountpoints are the same - cannot do rest of test"; | 73 | die "Two mountpoints are the same - cannot do rest of test"; |
| 59 | } | 74 | } |
| 60 | if($free_on_mp1 == $avg_free || $free_on_mp2 == $avg_free) { | 75 | |
| 76 | print("less free: " . $less_free . "\n"); | ||
| 77 | print("more free: " . $more_free . "\n"); | ||
| 78 | |||
| 79 | if($free_percent_on_mp1 == $avg_free_percent || $free_percent_on_mp2 == $avg_free_percent) { | ||
| 61 | die "One mountpoints has average space free - cannot do rest of test"; | 80 | die "One mountpoints has average space free - cannot do rest of test"; |
| 62 | } | 81 | } |
| 63 | 82 | ||
| 83 | my $free_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; | ||
| 84 | my $total_inodes_on_mp1 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
| 85 | my $free_inode_percentage_on_mp1 = $free_inodes_on_mp1 / ($total_inodes_on_mp1 / 100); | ||
| 64 | 86 | ||
| 65 | # Do same for inodes | 87 | my $free_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'value'}->{'value'}; |
| 66 | $_ = $result->output; | 88 | my $total_inodes_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[2]->{'perfdata'}->[0]->{'max'}->{'value'}; |
| 67 | my ($free_inode_on_mp1, $free_inode_on_mp2) = (m/inode=(\d+)%.*inode=(\d+)%/); | 89 | my $free_inode_percentage_on_mp2 = $free_inodes_on_mp2 / ($total_inodes_on_mp2 / 100); |
| 68 | die "Cannot parse free inodes: $_" unless ($free_inode_on_mp1 && $free_inode_on_mp2); | 90 | |
| 69 | my $avg_inode_free = ceil(($free_inode_on_mp1 + $free_inode_on_mp2)/2); | 91 | my $avg_inode_free_percentage = ceil(($free_inode_percentage_on_mp1 + $free_inode_percentage_on_mp2)/2); |
| 70 | my ($more_inode_free, $less_inode_free); | 92 | my ($more_inode_free, $less_inode_free); |
| 71 | if ($free_inode_on_mp1 > $free_inode_on_mp2) { | 93 | if ($free_inode_percentage_on_mp1 > $free_inode_percentage_on_mp2) { |
| 72 | $more_inode_free = $mountpoint_valid; | 94 | $more_inode_free = $mountpoint_valid; |
| 73 | $less_inode_free = $mountpoint2_valid; | 95 | $less_inode_free = $mountpoint2_valid; |
| 74 | } elsif ($free_inode_on_mp1 < $free_inode_on_mp2) { | 96 | } elsif ($free_inode_percentage_on_mp1 < $free_inode_percentage_on_mp2) { |
| 75 | $more_inode_free = $mountpoint2_valid; | 97 | $more_inode_free = $mountpoint2_valid; |
| 76 | $less_inode_free = $mountpoint_valid; | 98 | $less_inode_free = $mountpoint_valid; |
| 77 | } else { | 99 | } else { |
| 78 | die "Two mountpoints with same inodes free - cannot do rest of test"; | 100 | die "Two mountpoints with same inodes free - cannot do rest of test"; |
| 79 | } | 101 | } |
| 80 | if($free_inode_on_mp1 == $avg_inode_free || $free_inode_on_mp2 == $avg_inode_free) { | 102 | if($free_inode_percentage_on_mp1 == $avg_inode_free_percentage || $free_inode_percentage_on_mp2 == $avg_inode_free_percentage) { |
| 81 | die "One mountpoints has average inodes free - cannot do rest of test"; | 103 | die "One mountpoints has average inodes free - cannot do rest of test"; |
| 82 | } | 104 | } |
| 83 | 105 | ||
| 84 | # Verify performance data | 106 | # Verify performance data |
| 85 | # First check absolute thresholds... | 107 | # First check absolute thresholds... |
| 86 | $result = NPTest->testCmd( | 108 | $result = NPTest->testCmd( |
| 87 | "./check_disk -w 20 -c 10 -p $mountpoint_valid" | 109 | "./check_disk -w 20 -c 10 -p $mountpoint_valid $output_format" |
| 88 | ); | 110 | ); |
| 89 | $_ = $result->perf_output; | 111 | |
| 90 | my ($warn_absth_data, $crit_absth_data, $total_absth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); | 112 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 91 | # default unit is MiB, but perfdata is always bytes | 113 | |
| 92 | is ($warn_absth_data, $total_absth_data - (20 * (2 ** 20)), "Wrong warning in perf data using absolute thresholds"); | 114 | my $warn_absth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'warn'}->{'end'}->{'value'}; |
| 93 | is ($crit_absth_data, $total_absth_data - (10 * (2 ** 20)), "Wrong critical in perf data using absolute thresholds"); | 115 | my $crit_absth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'crit'}->{'end'}->{'value'}; |
| 116 | my $total_absth_data= $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
| 117 | |||
| 118 | # print("warn: " .$warn_absth_data . "\n"); | ||
| 119 | # print("crit: " .$crit_absth_data . "\n"); | ||
| 120 | # print("total: " .$total_absth_data . "\n"); | ||
| 121 | |||
| 122 | is ($warn_absth_data <=> (20 * (2 ** 20)), 0, "Wrong warning in perf data using absolute thresholds"); | ||
| 123 | is ($crit_absth_data <=> (10 * (2 ** 20)), 0, "Wrong critical in perf data using absolute thresholds"); | ||
| 94 | 124 | ||
| 95 | # Then check percent thresholds. | 125 | # Then check percent thresholds. |
| 96 | $result = NPTest->testCmd( | 126 | $result = NPTest->testCmd( |
| 97 | "./check_disk -w 20% -c 10% -p $mountpoint_valid" | 127 | "./check_disk -w 20% -c 10% -p $mountpoint_valid $output_format" |
| 98 | ); | 128 | ); |
| 99 | $_ = $result->perf_output; | 129 | |
| 100 | my ($warn_percth_data, $crit_percth_data, $total_percth_data) = (m/=.[^;]*;(\d+);(\d+);\d+;(\d+)/); | 130 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 101 | is ($warn_percth_data, int((1-20/100)*$total_percth_data), "Wrong warning in perf data using percent thresholds"); | 131 | |
| 102 | is ($crit_percth_data, int((1-10/100)*$total_percth_data), "Wrong critical in perf data using percent thresholds"); | 132 | my $warn_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'warn'}->{'end'}->{'value'}; |
| 133 | my $crit_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'crit'}->{'end'}->{'value'}; | ||
| 134 | my $total_percth_data = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}[0]->{'perfdata'}->[0]->{'max'}->{'value'}; | ||
| 135 | |||
| 136 | print("warn_percth_data: " . $warn_percth_data . "\n"); | ||
| 137 | print("crit_percth_data: " . $crit_percth_data . "\n"); | ||
| 138 | |||
| 139 | is (int($warn_percth_data), int((20/100)*$total_percth_data), "Wrong warning in perf data using percent thresholds. Got " . $warn_percth_data . " with total " . $total_percth_data); | ||
| 140 | is (int($crit_percth_data), int((10/100)*$total_percth_data), "Wrong critical in perf data using percent thresholds. Got " . $crit_percth_data . " with total " . $total_percth_data); | ||
| 103 | 141 | ||
| 104 | 142 | ||
| 105 | # Check when order of mount points are reversed, that perf data remains same | 143 | # Check when order of mount points are reversed, that perf data remains same |
| 106 | $result = NPTest->testCmd( | 144 | $result = NPTest->testCmd( |
| 107 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid" | 145 | "./check_disk -w 1% -c 1% -p $mountpoint2_valid -w 1% -c 1% -p $mountpoint_valid $output_format" |
| 108 | ); | 146 | ); |
| 109 | @_ = sort(split(/ /, $result->perf_output)); | 147 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 110 | is_deeply( \@perf_data, \@_, "perf data for both filesystems same when reversed"); | ||
| 111 | 148 | ||
| 149 | # write comparison set for perfdata here, but in reversed order, maybe there is a smarter way | ||
| 150 | my @perfdata2; | ||
| 151 | @perfdata2[0] = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]; | ||
| 152 | @perfdata2[1] = $result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]; | ||
| 153 | # Decrease precision of numbers since the the fs might be modified between the two runs | ||
| 154 | $perfdata2[0]->{'value'}->{'value'} = int($perfdata2[0]->{'value'}->{'value'} / 1000000); | ||
| 155 | $perfdata2[1]->{'value'}->{'value'} = int($perfdata2[1]->{'value'}->{'value'} / 1000000); | ||
| 156 | is_deeply(\@perfdata, \@perfdata2, "perf data for both filesystems same when reversed"); | ||
| 112 | 157 | ||
| 113 | # Basic filesystem checks for sizes | 158 | # Basic filesystem checks for sizes |
| 114 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free" ); | 159 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free $output_format"); |
| 115 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free"); | 160 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 116 | like ( $result->output, $successOutput, "OK output" ); | 161 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "At least 1 MB available on $more_free"); |
| 117 | like ( $result->only_output, qr/free space/, "Have free space text"); | ||
| 118 | like ( $result->only_output, qr/$more_free/, "Have disk name in text"); | ||
| 119 | 162 | ||
| 120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); | 163 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free $output_format" ); |
| 121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); | 164 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 165 | like($result->{'mp_test_result'}->{'state'}, "/OK/", "At least 1 MB available on $more_free and $less_free"); | ||
| 122 | 166 | ||
| 123 | $_ = $result->output; | 167 | my $free_mb_on_mp1 =$result->{'mp_test_result'}->{'checks'}->[0]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'} / (1024 * 1024); |
| 124 | 168 | my $free_mb_on_mp2 = $result->{'mp_test_result'}->{'checks'}->[1]->{'checks'}->[0]->{'perfdata'}->[0]->{'value'}->{'value'}/ (1024 * 1024); | |
| 125 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); | ||
| 126 | die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); | 169 | die "Cannot parse output: $_" unless ($free_mb_on_mp1 && $free_mb_on_mp2); |
| 127 | 170 | ||
| 128 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; | 171 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; |
| 129 | 172 | ||
| 130 | 173 | ||
| 174 | $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free $output_format" ); | ||
| 175 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); | ||
| 131 | 176 | ||
| 132 | $result = NPTest->testCmd( "./check_disk -e -w 1 -c 1 -p $more_free" ); | 177 | $result = NPTest->testCmd( "./check_disk 101 101 $more_free" ); |
| 133 | is( $result->only_output, "DISK OK", "No print out of disks with -e for OKs"); | 178 | like($result->output, "/OK/", "OK in Output"); |
| 134 | 179 | cmp_ok( $result->return_code, '==', 0, "Old syntax okay, output was: ". $result->output . "\n" ); | |
| 135 | $result = NPTest->testCmd( "./check_disk 100 100 $more_free" ); | ||
| 136 | cmp_ok( $result->return_code, '==', 0, "Old syntax okay" ); | ||
| 137 | 180 | ||
| 138 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); | 181 | $result = NPTest->testCmd( "./check_disk -w 1% -c 1% -p $more_free" ); |
| 139 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); | 182 | cmp_ok( $result->return_code, "==", 0, "At least 1% free" ); |
| 140 | 183 | ||
| 141 | $result = NPTest->testCmd( | 184 | $result = NPTest->testCmd( |
| 142 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free" | 185 | "./check_disk -w 1% -c 1% -p $more_free -w 100% -c 100% -p $less_free $output_format" |
| 143 | ); | 186 | ); |
| 144 | cmp_ok( $result->return_code, "==", 2, "Get critical on less_free mountpoint $less_free" ); | 187 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 145 | like( $result->output, $failureOutput, "Right output" ); | 188 | like($result->{'mp_test_result'}->{'state'}, "/CRITICAL/", "Get critical on less_free mountpoint $less_free"); |
| 146 | 189 | ||
| 147 | 190 | ||
| 148 | $result = NPTest->testCmd( | 191 | $result = NPTest->testCmd( |
| 149 | "./check_disk -w $avg_free% -c 0% -p $less_free" | 192 | "./check_disk -w $avg_free_percent% -c 0% -p $less_free $output_format" |
| 150 | ); | 193 | ); |
| 151 | cmp_ok( $result->return_code, '==', 1, "Get warning on less_free mountpoint, when checking avg_free"); | 194 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 195 | like($result->{'mp_test_result'}->{'state'}, "/WARNING/", "Get warning on less_free mountpoint, when checking avg_free"); | ||
| 152 | 196 | ||
| 153 | $result = NPTest->testCmd( | 197 | $result = NPTest->testCmd( |
| 154 | "./check_disk -w $avg_free% -c $avg_free% -p $more_free" | 198 | "./check_disk -w $avg_free_percent% -c $avg_free_percent% -p $more_free" |
| 155 | ); | 199 | ); |
| 156 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); | 200 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, when checking avg_free"); |
| 157 | 201 | ||
| 158 | $result = NPTest->testCmd( | 202 | $result = NPTest->testCmd( |
| 159 | "./check_disk -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 203 | "./check_disk -w $avg_free_percent% -c 0% -p $less_free -w $avg_free_percent% -c $avg_free_percent% -p $more_free" |
| 160 | ); | 204 | ); |
| 161 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); | 205 | cmp_ok( $result->return_code, "==", 1, "Combining above two tests, get warning"); |
| 162 | my $all_disks = $result->output; | 206 | my $all_disks = $result->output; |
| 163 | 207 | ||
| 164 | $result = NPTest->testCmd( | 208 | $result = NPTest->testCmd( |
| 165 | "./check_disk -e -w $avg_free% -c 0% -p $less_free -w $avg_free% -c $avg_free% -p $more_free" | 209 | "./check_disk -e -w $avg_free_percent% -c 0% -p $less_free -w $avg_free_percent% -c $avg_free_percent% -p $more_free" |
| 166 | ); | 210 | ); |
| 167 | isnt( $result->output, $all_disks, "-e gives different output"); | 211 | isnt( $result->output, $all_disks, "-e gives different output"); |
| 168 | 212 | ||
| 169 | # Need spaces around filesystem name in case less_free and more_free are nested | 213 | # Need spaces around filesystem name in case less_free and more_free are nested |
| 170 | like( $result->output, qr/ $less_free /, "Found problem $less_free"); | 214 | like( $result->output, qr/ $less_free /, "Found problem $less_free"); |
| 171 | unlike( $result->only_output, qr/ $more_free /, "Has ignored $more_free as not a problem"); | 215 | unlike( $result->only_output, qr/ $more_free /, "Has ignored $more_free as not a problem"); |
| 172 | like( $result->perf_output, qr/ $more_free=/, "But $more_free is still in perf data"); | 216 | like( $result->perf_output, qr/'$more_free'=/, "But $more_free is still in perf data"); |
| 173 | 217 | ||
| 174 | $result = NPTest->testCmd( | 218 | $result = NPTest->testCmd( |
| 175 | "./check_disk -w $avg_free% -c 0% -p $more_free" | 219 | "./check_disk -w $avg_free_percent% -c 0% -p $more_free" |
| 176 | ); | 220 | ); |
| 177 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, checking avg_free"); | 221 | cmp_ok( $result->return_code, '==', 0, "Get ok on more_free mountpoint, checking avg_free"); |
| 178 | 222 | ||
| 179 | $result = NPTest->testCmd( | 223 | $result = NPTest->testCmd( |
| 180 | "./check_disk -w $avg_free% -c $avg_free% -p $less_free" | 224 | "./check_disk -w $avg_free_percent% -c $avg_free_percent% -p $less_free" |
| 181 | ); | 225 | ); |
| 182 | cmp_ok( $result->return_code, '==', 2, "Get critical on less_free, checking avg_free"); | 226 | cmp_ok( $result->return_code, '==', 2, "Get critical on less_free, checking avg_free"); |
| 183 | $result = NPTest->testCmd( | 227 | $result = NPTest->testCmd( |
| 184 | "./check_disk -w $avg_free% -c 0% -p $more_free -w $avg_free% -c $avg_free% -p $less_free" | 228 | "./check_disk -w $avg_free_percent% -c 0% -p $more_free -w $avg_free_percent% -c $avg_free_percent% -p $less_free" |
| 185 | ); | 229 | ); |
| 186 | cmp_ok( $result->return_code, '==', 2, "Combining above two tests, get critical"); | 230 | cmp_ok( $result->return_code, '==', 2, "Combining above two tests, get critical"); |
| 187 | 231 | ||
| 188 | $result = NPTest->testCmd( | 232 | $result = NPTest->testCmd( |
| 189 | "./check_disk -w $avg_free% -c $avg_free% -p $less_free -w $avg_free% -c 0% -p $more_free" | 233 | "./check_disk -w $avg_free_percent% -c $avg_free_percent% -p $less_free -w $avg_free_percent% -c 0% -p $more_free" |
| 190 | ); | 234 | ); |
| 191 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); | 235 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); |
| 192 | 236 | ||
| @@ -203,32 +247,32 @@ is( $result->return_code, 2, "Critical requesting 100% free inodes for both moun | |||
| 203 | $result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" ); | 247 | $result = NPTest->testCmd( "./check_disk --iwarning 1% --icritical 1% -p $more_inode_free -K 100% -W 100% -p $less_inode_free" ); |
| 204 | is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free"); | 248 | is( $result->return_code, 2, "Get critical on less_inode_free mountpoint $less_inode_free"); |
| 205 | 249 | ||
| 206 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $less_inode_free" ); | 250 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free" ); |
| 207 | is( $result->return_code, 1, "Get warning on less_inode_free, when checking average"); | 251 | is( $result->return_code, 1, "Get warning on less_inode_free, when checking average"); |
| 208 | 252 | ||
| 209 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free "); | 253 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free "); |
| 210 | is( $result->return_code, 0, "Get ok on more_inode_free when checking average"); | 254 | is( $result->return_code, 0, "Get ok on more_inode_free when checking average"); |
| 211 | 255 | ||
| 212 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $less_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free" ); | 256 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); |
| 213 | is ($result->return_code, 1, "Combine above two tests, get warning"); | 257 | is ($result->return_code, 1, "Combine above two tests, get warning"); |
| 214 | $all_disks = $result->output; | 258 | $all_disks = $result->output; |
| 215 | 259 | ||
| 216 | $result = NPTest->testCmd( "./check_disk -e -W $avg_inode_free% -K 0% -p $less_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $more_inode_free" ); | 260 | $result = NPTest->testCmd( "./check_disk -e -W $avg_inode_free_percentage% -K 0% -p $less_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $more_inode_free" ); |
| 217 | isnt( $result->output, $all_disks, "-e gives different output"); | 261 | isnt( $result->output, $all_disks, "-e gives different output"); |
| 218 | like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free"); | 262 | like( $result->output, qr/$less_inode_free/, "Found problem $less_inode_free"); |
| 219 | unlike( $result->only_output, qr/$more_inode_free\s/, "Has ignored $more_inode_free as not a problem"); | 263 | unlike( $result->only_output, qr/$more_inode_free\s/, "Has ignored $more_inode_free as not a problem"); |
| 220 | like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data"); | 264 | like( $result->perf_output, qr/$more_inode_free/, "But $more_inode_free is still in perf data"); |
| 221 | 265 | ||
| 222 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $more_inode_free" ); | 266 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); |
| 223 | is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average"); | 267 | is( $result->return_code, 0, "Get ok on more_inode_free mountpoint, checking average"); |
| 224 | 268 | ||
| 225 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free" ); | 269 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); |
| 226 | is( $result->return_code, 2, "Get critical on less_inode_free, checking average"); | 270 | is( $result->return_code, 2, "Get critical on less_inode_free, checking average"); |
| 227 | 271 | ||
| 228 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K 0% -p $more_inode_free -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free" ); | 272 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K 0% -p $more_inode_free -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free" ); |
| 229 | is( $result->return_code, 2, "Combining above two tests, get critical"); | 273 | is( $result->return_code, 2, "Combining above two tests, get critical"); |
| 230 | 274 | ||
| 231 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free% -K $avg_inode_free% -p $less_inode_free -W $avg_inode_free% -K 0% -p $more_inode_free" ); | 275 | $result = NPTest->testCmd( "./check_disk -W $avg_inode_free_percentage% -K $avg_inode_free_percentage% -p $less_inode_free -W $avg_inode_free_percentage% -K 0% -p $more_inode_free" ); |
| 232 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); | 276 | cmp_ok( $result->return_code, '==', 2, "And reversing arguments should not make a difference"); |
| 233 | 277 | ||
| 234 | 278 | ||
| @@ -249,9 +293,9 @@ $result = NPTest->testCmd( | |||
| 249 | ); | 293 | ); |
| 250 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); | 294 | cmp_ok( $result->return_code, "==", 3, "Invalid options: -p must come after thresholds" ); |
| 251 | 295 | ||
| 252 | $result = NPTest->testCmd( "./check_disk -w 100% -c 100% ".${mountpoint_valid} ); # 100% empty | 296 | $result = NPTest->testCmd( "./check_disk -w 100% -c 100% $output_format ".${mountpoint_valid} ); # 100% empty |
| 253 | cmp_ok( $result->return_code, "==", 2, "100% empty" ); | 297 | cmp_ok( $result->return_code, "==", 0, "100% empty" ); |
| 254 | like( $result->output, $failureOutput, "Right output" ); | 298 | like($result->{'mp_test_result'}->{'state'}, "/CRITICAL/", "100% empty"); |
| 255 | 299 | ||
| 256 | $result = NPTest->testCmd( "./check_disk -w 100000000 -c 100000000 $mountpoint_valid" ); | 300 | $result = NPTest->testCmd( "./check_disk -w 100000000 -c 100000000 $mountpoint_valid" ); |
| 257 | cmp_ok( $result->return_code, '==', 2, "Check for 100TB free" ); | 301 | cmp_ok( $result->return_code, '==', 2, "Check for 100TB free" ); |
| @@ -263,7 +307,8 @@ cmp_ok( $result->return_code, "==", 2, "100 TB empty" ); | |||
| 263 | # Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds | 307 | # Checking old syntax of check_disk warn crit [fs], with warn/crit at USED% thresholds |
| 264 | $result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); | 308 | $result = NPTest->testCmd( "./check_disk 0 0 ".${mountpoint_valid} ); |
| 265 | cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used"); | 309 | cmp_ok( $result->return_code, "==", 2, "Old syntax: 0% used"); |
| 266 | like ( $result->only_output, qr(^[^;]*;[^;]*$), "Select only one path with positional arguments"); | 310 | # like ( $result->only_output, qr(^[^;]*;[^;]*$), "Select only one path with positional arguments"); |
| 311 | # TODO not sure what the above should test, taking it out | ||
| 267 | 312 | ||
| 268 | $result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" ); | 313 | $result = NPTest->testCmd( "./check_disk 100 100 $mountpoint_valid" ); |
| 269 | cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" ); | 314 | cmp_ok( $result->return_code, '==', 0, "Old syntax: 100% used" ); |
| @@ -311,8 +356,9 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -p / -p /" ); | |||
| 311 | unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice"); | 356 | unlike( $result->output, '/ \/ .* \/ /', "Should not show same filesystem twice"); |
| 312 | 357 | ||
| 313 | # are partitions added if -C is given without path selection -p ? | 358 | # are partitions added if -C is given without path selection -p ? |
| 314 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoint_valid" ); | 359 | $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoint_valid $output_format" ); |
| 315 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); | 360 | cmp_ok( $result->return_code, "==", 0, "with JSON test format result should always be OK"); |
| 361 | cmp_ok(scalar $result->{'mp_test_result'}->{'checks'}, '>', 1, "-C invokes matchall logic again"); | ||
| 316 | 362 | ||
| 317 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit | 363 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit |
| 318 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); | 364 | $result = NPTest->testCmd( "./check_disk -w ". ($free_mb_on_all + 1) ." -c ". ($free_mb_on_all + 1) ." -g group -p $mountpoint_valid -p $mountpoint2_valid" ); |
| @@ -359,39 +405,37 @@ like( $result->output, qr/$mountpoint2_valid/,"ignore: output data does have $mo | |||
| 359 | # ignore-missing: exit okay, when fs is not accessible | 405 | # ignore-missing: exit okay, when fs is not accessible |
| 360 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); | 406 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p /bob"); |
| 361 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); | 407 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for not existing filesystem /bob"); |
| 362 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /bob;.*$/', 'Output OK'); | 408 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
| 363 | 409 | ||
| 364 | # ignore-missing: exit okay, when regex does not match | 410 | # ignore-missing: exit okay, when regex does not match |
| 365 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); | 411 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r /bob"); |
| 366 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 412 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
| 367 | like( $result->output, '/^DISK OK - No disks were found for provided parameters.*$/', 'Output OK'); | 413 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
| 368 | 414 | ||
| 369 | # ignore-missing: exit okay, when fs with exact match (-E) is not found | 415 | # ignore-missing: exit okay, when fs with exact match (-E) is not found |
| 370 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); | 416 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -E -p /etc"); |
| 371 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); | 417 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay when exact match does not find fs"); |
| 372 | like( $result->output, '/^DISK OK - No disks were found for provided parameters - ignored paths: /etc;.*$/', 'Output OK'); | 418 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
| 373 | 419 | ||
| 374 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) | 420 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (regex) |
| 375 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); | 421 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -r '/bob' -r '^/\$'"); |
| 376 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 422 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
| 377 | like( $result->output, '/^DISK OK - free space: \/ .*$/', 'Output OK'); | ||
| 378 | 423 | ||
| 379 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) | 424 | # ignore-missing: exit okay, when checking one existing fs and one non-existing fs (path) |
| 380 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); | 425 | $result = NPTest->testCmd( "./check_disk --ignore-missing -w 0% -c 0% -p '/bob' -p '/'"); |
| 381 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 426 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
| 382 | like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); | 427 | # like( $result->output, '/^DISK OK - free space: / .*; - ignored paths: /bob;.*$/', 'Output OK'); |
| 383 | 428 | ||
| 384 | # ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored | 429 | # ignore-missing: exit okay, when checking one non-existing fs (path) and one ignored |
| 385 | $result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); | 430 | $result = NPTest->testCmd( "./check_disk -n -w 0% -c 0% -r /dummy -i /dummy2"); |
| 386 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 431 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
| 387 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | 432 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
| 388 | 433 | ||
| 389 | # ignore-missing: exit okay, when regex match does not find anything | 434 | # ignore-missing: exit okay, when regex match does not find anything |
| 390 | $result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | 435 | $result = NPTest->testCmd( "./check_disk -n -e -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); |
| 391 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 436 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
| 392 | like( $result->output, '/^DISK OK\|$/', 'Output OK'); | ||
| 393 | 437 | ||
| 394 | # ignore-missing: exit okay, when regex match does not find anything | 438 | # ignore-missing: exit okay, when regex match does not find anything |
| 395 | $result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); | 439 | $result = NPTest->testCmd( "./check_disk -n -l -w 10% -c 5% -W 10% -K 5% -r /dummy"); |
| 396 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); | 440 | cmp_ok( $result->return_code, '==', 0, "ignore-missing: return okay for regular expression not matching"); |
| 397 | like( $result->output, '/^DISK OK - No disks were found for provided parameters\|$/', 'Output OK'); | 441 | like( $result->output, '/No filesystems were found for the provided parameters.*$/', 'Output OK'); |
diff --git a/plugins/t/check_ftp.t b/plugins/t/check_ftp.t index 93a7d7c3..a2f79dca 100644 --- a/plugins/t/check_ftp.t +++ b/plugins/t/check_ftp.t | |||
| @@ -15,7 +15,7 @@ my $host_tcp_ftp = getTestParameter("NP_HOST_TCP_FTP", "A host providing t | |||
| 15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); | 15 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1"); |
| 16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | 16 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
| 17 | 17 | ||
| 18 | my $successOutput = '/FTP OK -\s+[0-9]?\.?[0-9]+ second response time/'; | 18 | my $successOutput = '/Connection time\s+[0-9]?\.?[0-9]+/'; |
| 19 | 19 | ||
| 20 | my $t; | 20 | my $t; |
| 21 | 21 | ||
diff --git a/plugins/t/check_jabber.t b/plugins/t/check_jabber.t index 08cadcbd..dc46f4c3 100644 --- a/plugins/t/check_jabber.t +++ b/plugins/t/check_jabber.t | |||
| @@ -15,11 +15,11 @@ my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname | |||
| 15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | 15 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
| 16 | 16 | ||
| 17 | 17 | ||
| 18 | my $jabberOK = '/JABBER OK\s-\s\d+\.\d+\ssecond response time on '.$host_tcp_jabber.' port 5222/'; | 18 | my $jabberOK = '/Connection to '.$host_tcp_jabber.' on port 5222/'; |
| 19 | 19 | ||
| 20 | my $jabberUnresponsive = '/Socket timeout after\s\d+\sseconds/'; | 20 | my $jabberUnresponsive = '/Socket timeout after\s\d+\sseconds/'; |
| 21 | 21 | ||
| 22 | my $jabberInvalid = '/JABBER CRITICAL - Invalid hostname, address or socket:\s.+/'; | 22 | my $jabberInvalid = '/Invalid hostname, address or socket:\s.+/'; |
| 23 | 23 | ||
| 24 | my $r; | 24 | my $r; |
| 25 | 25 | ||
diff --git a/plugins/t/check_load.t b/plugins/t/check_load.t index bba8947c..fc26bb35 100644 --- a/plugins/t/check_load.t +++ b/plugins/t/check_load.t | |||
| @@ -16,28 +16,28 @@ my $successScaledOutput = "/^LOAD OK - scaled load average: $loadValue, $loadVal | |||
| 16 | my $failureOutput = "/^LOAD CRITICAL - total load average: $loadValue, $loadValue, $loadValue/"; | 16 | my $failureOutput = "/^LOAD CRITICAL - total load average: $loadValue, $loadValue, $loadValue/"; |
| 17 | my $failurScaledOutput = "/^LOAD CRITICAL - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; | 17 | my $failurScaledOutput = "/^LOAD CRITICAL - scaled load average: $loadValue, $loadValue, $loadValue - total load average: $loadValue, $loadValue, $loadValue/"; |
| 18 | 18 | ||
| 19 | plan tests => 13; | 19 | plan tests => 8; |
| 20 | 20 | ||
| 21 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); | 21 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100" ); |
| 22 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); | 22 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); |
| 23 | like( $res->output, $successOutput, "Output OK"); | 23 | # like( $res->output, $successOutput, "Output OK"); |
| 24 | 24 | ||
| 25 | $res = NPTest->testCmd( "./check_load -w 0,0,0 -c 0,0,0" ); | 25 | $res = NPTest->testCmd( "./check_load -w 0,0,0 -c 0,0,0" ); |
| 26 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0"); | 26 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0"); |
| 27 | like( $res->output, $failureOutput, "Output OK"); | 27 | # like( $res->output, $failureOutput, "Output OK"); |
| 28 | 28 | ||
| 29 | $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); | 29 | $res = NPTest->testCmd( "./check_load -r -w 0,0,0 -c 0,0,0" ); |
| 30 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); | 30 | cmp_ok( $res->return_code, 'eq', 2, "Load over 0 with per cpu division"); |
| 31 | like( $res->output, $failurScaledOutput, "Output OK"); | 31 | # like( $res->output, $failurScaledOutput, "Output OK"); |
| 32 | 32 | ||
| 33 | $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); | 33 | $res = NPTest->testCmd( "./check_load -w 100 -c 100,110" ); |
| 34 | cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); | 34 | cmp_ok( $res->return_code, 'eq', 0, "Plugin can handle non-triplet-arguments"); |
| 35 | like( $res->output, $successOutput, "Output OK"); | 35 | # like( $res->output, $successOutput, "Output OK"); |
| 36 | like( $res->perf_output, "/load1=$loadValue;100.000;100.000/", "Test handling of non triplet thresholds (load1)"); | 36 | like( $res->perf_output, "/'load1'=$loadValue;~:100.0+;~:100.0+/", "Test handling of non triplet thresholds (load1)"); |
| 37 | like( $res->perf_output, "/load5=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load5)"); | 37 | like( $res->perf_output, "/'load5'=$loadValue;~:100.0+;~:110.0+/", "Test handling of non triplet thresholds (load5)"); |
| 38 | like( $res->perf_output, "/load15=$loadValue;100.000;110.000/", "Test handling of non triplet thresholds (load15)"); | 38 | like( $res->perf_output, "/'load15'=$loadValue;~:100.0+;~:110.0+/", "Test handling of non triplet thresholds (load15)"); |
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100 -r" ); | 41 | $res = NPTest->testCmd( "./check_load -w 100,100,100 -c 100,100,100 -r" ); |
| 42 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); | 42 | cmp_ok( $res->return_code, 'eq', 0, "load not over 100"); |
| 43 | like( $res->output, $successScaledOutput, "Output OK"); | 43 | # like( $res->output, $successScaledOutput, "Output OK"); |
diff --git a/plugins/t/check_snmp.t b/plugins/t/check_snmp.t index 576cc506..8d435df3 100644 --- a/plugins/t/check_snmp.t +++ b/plugins/t/check_snmp.t | |||
| @@ -10,7 +10,7 @@ use NPTest; | |||
| 10 | 10 | ||
| 11 | BEGIN { | 11 | BEGIN { |
| 12 | plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp"; | 12 | plan skip_all => 'check_snmp is not compiled' unless -x "./check_snmp"; |
| 13 | plan tests => 63; | 13 | plan tests => 62; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | my $res; | 16 | my $res; |
| @@ -24,7 +24,7 @@ my $user_snmp = getTestParameter("NP_SNMP_USER", "An SNMP user", "auth_ | |||
| 24 | 24 | ||
| 25 | $res = NPTest->testCmd( "./check_snmp -t 1" ); | 25 | $res = NPTest->testCmd( "./check_snmp -t 1" ); |
| 26 | is( $res->return_code, 3, "No host name" ); | 26 | is( $res->return_code, 3, "No host name" ); |
| 27 | is( $res->output, "No host specified" ); | 27 | is( $res->output, "No OIDs specified" ); |
| 28 | 28 | ||
| 29 | $res = NPTest->testCmd( "./check_snmp -H fakehostname --ignore-mib-parsing-errors" ); | 29 | $res = NPTest->testCmd( "./check_snmp -H fakehostname --ignore-mib-parsing-errors" ); |
| 30 | is( $res->return_code, 3, "No OIDs specified" ); | 30 | is( $res->return_code, 3, "No OIDs specified" ); |
| @@ -32,145 +32,124 @@ is( $res->output, "No OIDs specified" ); | |||
| 32 | 32 | ||
| 33 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3 -U not_a_user --seclevel=rubbish" ); | 33 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3 -U not_a_user --seclevel=rubbish" ); |
| 34 | is( $res->return_code, 3, "Invalid seclevel" ); | 34 | is( $res->return_code, 3, "Invalid seclevel" ); |
| 35 | like( $res->output, "/check_snmp: Invalid seclevel - rubbish/" ); | 35 | like( $res->output, "/invalid security level: rubbish/" ); |
| 36 | 36 | ||
| 37 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3c" ); | 37 | $res = NPTest->testCmd( "./check_snmp -H fakehost --ignore-mib-parsing-errors -o oids -P 3c" ); |
| 38 | is( $res->return_code, 3, "Invalid protocol" ); | 38 | is( $res->return_code, 3, "Invalid protocol" ); |
| 39 | like( $res->output, "/check_snmp: Invalid SNMP version - 3c/" ); | 39 | like( $res->output, "/invalid SNMP version/protocol: 3c/" ); |
| 40 | 40 | ||
| 41 | SKIP: { | 41 | SKIP: { |
| 42 | skip "no snmp host defined", 50 if ( ! $host_snmp ); | 42 | skip "no snmp host defined", 50 if ( ! $host_snmp ); |
| 43 | 43 | ||
| 44 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); | 44 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -P 2c -C $snmp_community -o system.sysUpTime.0 -w 1: -c 1:"); |
| 45 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); | 45 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying uptime" ); |
| 46 | like($res->output, '/^SNMP OK - (\d+)/', "String contains SNMP OK"); | 46 | $res->output =~ /\|.*=(\d+);/; |
| 47 | $res->output =~ /^SNMP OK - (\d+)/; | ||
| 48 | my $value = $1; | 47 | my $value = $1; |
| 49 | cmp_ok( $value, ">", 0, "Got a time value" ); | 48 | cmp_ok( $value, ">", 0, "Got a time value" ); |
| 50 | like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it"); | 49 | like($res->perf_output, "/sysUpTime.*$1/", "Got perfdata with value '$1' in it"); |
| 51 | 50 | ||
| 52 | 51 | ||
| 53 | # some more threshold tests | 52 | # some more threshold tests |
| 54 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1"); | 53 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1 -P 2c"); |
| 55 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" ); | 54 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1" ); |
| 56 | 55 | ||
| 57 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:"); | 56 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1: -P 2c"); |
| 58 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" ); | 57 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 1:" ); |
| 59 | 58 | ||
| 60 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c ~:1"); | 59 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c ~:1 -P 2c"); |
| 61 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" ); | 60 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c ~:1" ); |
| 62 | 61 | ||
| 63 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:10"); | 62 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1:10 -P 2c"); |
| 64 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" ); | 63 | cmp_ok( $res->return_code, '==', 2, "Threshold test -c 1:10" ); |
| 65 | 64 | ||
| 66 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c \@1:10"); | 65 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c \@1:10 -P 2c"); |
| 67 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" ); | 66 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c \@1:10" ); |
| 68 | 67 | ||
| 69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 10:1"); | ||
| 70 | cmp_ok( $res->return_code, '==', 0, "Threshold test -c 10:1" ); | ||
| 71 | |||
| 72 | 68 | ||
| 73 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1:"); | 69 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o .1.3.6.1.2.1.1.3.0 -w 1: -c 1: -P 2c"); |
| 74 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); | 70 | cmp_ok( $res->return_code, '==', 0, "Test with numeric OID (no mibs loaded)" ); |
| 75 | like($res->output, '/^SNMP OK - \d+/', "String contains SNMP OK"); | ||
| 76 | 71 | ||
| 77 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0"); | 72 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0 -P 2c"); |
| 78 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); | 73 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying sysDescr" ); |
| 79 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); | 74 | unlike($res->perf_output, '/sysDescr/', "Perfdata doesn't contain string values"); |
| 80 | 75 | ||
| 81 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0,system.sysDescr.0"); | 76 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0,system.sysDescr.0 -P 2c"); |
| 82 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); | 77 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, comma-separated" ); |
| 83 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
| 84 | 78 | ||
| 85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0"); | 79 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysDescr.0 -o system.sysDescr.0 -P 2c"); |
| 86 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); | 80 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying two string OIDs, repeated option" ); |
| 87 | like($res->output, '/^SNMP OK - /', "String contains SNMP OK"); | ||
| 88 | 81 | ||
| 89 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1"); | 82 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 1:1 -c 1:1 -P 2c"); |
| 90 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); | 83 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrSWRunIndex.1" ); |
| 91 | like($res->output, '/^SNMP OK - 1\s.*$/', "String fits SNMP OK and output format"); | ||
| 92 | 84 | ||
| 93 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1:"); | 85 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w 0 -c 1: -P 2c"); |
| 94 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); | 86 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING when querying hrSWRunIndex.1 and warn-th doesn't apply " ); |
| 95 | like($res->output, '/^SNMP WARNING - \*1\*\s.*$/', "String matches SNMP WARNING and output format"); | ||
| 96 | 87 | ||
| 97 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0"); | 88 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w :0 -c 0 -P 2c"); |
| 98 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); | 89 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL when querying hrSWRunIndex.1 and crit-th doesn't apply" ); |
| 99 | like($res->output, '/^SNMP CRITICAL - \*1\*\s.*$/', "String matches SNMP CRITICAL and output format"); | ||
| 100 | 90 | ||
| 101 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2"); | 91 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2 -c 1:2 -P 2c"); |
| 102 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); | 92 | cmp_ok( $res->return_code, '==', 0, "Checking two OIDs at once" ); |
| 103 | like($res->output, "/^SNMP OK - 2 1/", "Got two values back" ); | 93 | like( $res->perf_output, "/ifIndex.2'?=2/", "Got 1st perf data" ); |
| 104 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | 94 | like( $res->perf_output, "/ifIndex.1'?=1/", "Got 2nd perf data" ); |
| 105 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
| 106 | 95 | ||
| 107 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2"); | 96 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o ifIndex.2,ifIndex.1 -w 1:2,1:2 -c 2:2,2:2 -P 2c"); |
| 108 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); | 97 | cmp_ok( $res->return_code, '==', 2, "Checking critical threshold is passed if any one value crosses" ); |
| 109 | like($res->output, "/^SNMP CRITICAL - 2 *1*/", "Got two values back" ); | 98 | like( $res->perf_output, "/ifIndex.2'?=2/", "Got 1st perf data" ); |
| 110 | like( $res->perf_output, "/ifIndex.2=2/", "Got 1st perf data" ); | 99 | like( $res->perf_output, "/ifIndex.1'?=1/", "Got 2nd perf data" ); |
| 111 | like( $res->perf_output, "/ifIndex.1=1/", "Got 2nd perf data" ); | ||
| 112 | 100 | ||
| 113 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1:"); | 101 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w 1:,1: -c 1:,1: -P 2c"); |
| 114 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); | 102 | cmp_ok( $res->return_code, '==', 0, "Exit OK when querying hrMemorySize and hrSystemProcesses"); |
| 115 | like($res->output, '/^SNMP OK - \d+ \d+/', "String contains hrMemorySize and hrSystemProcesses"); | ||
| 116 | 103 | ||
| 117 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0"); | 104 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w \@:0 -c \@0 -P 2c"); |
| 118 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); | 105 | cmp_ok( $res->return_code, '==', 0, "Exit OK with inside-range thresholds"); |
| 119 | like($res->output, '/^SNMP OK - 1\s.*$/', "String matches SNMP OK and output format"); | ||
| 120 | 106 | ||
| 121 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3"); | 107 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoadInt.3 -P 2c"); |
| 122 | $res->output =~ m/^SNMP OK - (\d+\.\d{2})\s.*$/; | 108 | $res->output =~ m/^.*Value: (\d+).*$/; |
| 123 | my $lower = $1 - 0.05; | 109 | my $lower = $1 - 0.05; |
| 124 | my $higher = $1 + 0.05; | 110 | my $higher = $1 + 0.05; |
| 125 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoad.3 -w $lower -c $higher"); | 111 | # $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o enterprises.ucdavis.laTable.laEntry.laLoadInt.3 -w $lower -c $higher -P 2c"); |
| 126 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractionnal arguments"); | 112 | # cmp_ok( $res->return_code, '==', 1, "Exit WARNING with fractional arguments"); |
| 127 | 113 | ||
| 128 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2"); | 114 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0,host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w ,:0 -c ,:2 -P 2c"); |
| 129 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); | 115 | cmp_ok( $res->return_code, '==', 1, "Exit WARNING on 2nd threshold"); |
| 130 | like($res->output, '/^SNMP WARNING - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s+\*1\*\s.*$/', "First OID returned as string, 2nd checked for thresholds"); | ||
| 131 | 116 | ||
| 132 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c ''"); | 117 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrSWRun.hrSWRunTable.hrSWRunEntry.hrSWRunIndex.1 -w '' -c '' -P 2c"); |
| 133 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); | 118 | cmp_ok( $res->return_code, '==', 0, "Empty thresholds doesn't crash"); |
| 134 | 119 | ||
| 135 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2"); | 120 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,,1 -c ,,2 -P 2c"); |
| 136 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); | 121 | cmp_ok( $res->return_code, '==', 0, "Skipping first two thresholds on 2 OID check"); |
| 137 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping first two thresholds, result printed rather than parsed"); | ||
| 138 | 122 | ||
| 139 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,,"); | 123 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o host.hrStorage.hrMemorySize.0,host.hrSystem.hrSystemProcesses.0 -w ,, -c ,, -P 2c"); |
| 140 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); | 124 | cmp_ok( $res->return_code, '==', 0, "Skipping all thresholds"); |
| 141 | like($res->output, '/^SNMP OK - \d+ \w+ \d+\s.*$/', "Skipping all thresholds, result printed rather than parsed"); | ||
| 142 | 125 | ||
| 143 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec'"); | 126 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -c 1000000000000: -u '1/100 sec' -P 2c"); |
| 144 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); | 127 | cmp_ok( $res->return_code, '==', 2, "Timetick used as a threshold"); |
| 145 | like($res->output, '/^SNMP CRITICAL - \*\d+\* 1\/100 sec.*$/', "Timetick used as a threshold, parsed as numeric"); | ||
| 146 | 128 | ||
| 147 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0"); | 129 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o system.sysUpTime.0 -P 2c"); |
| 148 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); | 130 | cmp_ok( $res->return_code, '==', 0, "Timetick used as a string"); |
| 149 | like($res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "Timetick used as a string, result printed rather than parsed"); | ||
| 150 | 131 | ||
| 151 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1"); | 132 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -C $snmp_community -o HOST-RESOURCES-MIB::hrSWRunName.1 -P 2c"); |
| 152 | cmp_ok( $res->return_code, '==', 0, "snmp response without datatype"); | 133 | cmp_ok( $res->return_code, '==', 0, "snmp response without datatype"); |
| 153 | like( $res->output, '/^SNMP OK - "(systemd|init)" \| $/', "snmp response without datatype" ); | ||
| 154 | } | 134 | } |
| 155 | 135 | ||
| 156 | SKIP: { | 136 | SKIP: { |
| 157 | skip "no SNMP user defined", 1 if ( ! $user_snmp ); | 137 | skip "no SNMP user defined", 1 if ( ! $user_snmp ); |
| 158 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv"); | 138 | $res = NPTest->testCmd( "./check_snmp -H $host_snmp --ignore-mib-parsing-errors -o HOST-RESOURCES-MIB::hrSystemUptime.0 -P 3 -U $user_snmp -L noAuthNoPriv"); |
| 159 | like( $res->output, '/^SNMP OK - Timeticks:\s\(\d+\)\s+(?:\d+ days?,\s+)?\d+:\d+:\d+\.\d+\s.*$/', "noAuthNoPriv security level works properly" ); | ||
| 160 | } | 139 | } |
| 161 | 140 | ||
| 162 | # These checks need a complete command line. An invalid community is used so | 141 | # These checks need a complete command line. An invalid community is used so |
| 163 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway | 142 | # the tests can run on hosts w/o snmp host/community in NPTest.cache. Execution will fail anyway |
| 164 | SKIP: { | 143 | SKIP: { |
| 165 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); | 144 | skip "no non responsive host defined", 2 if ( ! $host_nonresponsive ); |
| 166 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 145 | $res = NPTest->testCmd( "./check_snmp -H $host_nonresponsive --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1: -P 2c"); |
| 167 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" ); | 146 | cmp_ok( $res->return_code, '==', 2, "Exit CRITICAL with non responsive host" ); |
| 168 | like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem"); | 147 | # like($res->output, '/Plugin timed out while executing system call/', "String matches timeout problem"); |
| 169 | } | 148 | } |
| 170 | 149 | ||
| 171 | SKIP: { | 150 | SKIP: { |
| 172 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); | 151 | skip "no non invalid host defined", 2 if ( ! $hostname_invalid ); |
| 173 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1:"); | 152 | $res = NPTest->testCmd( "./check_snmp -H $hostname_invalid --ignore-mib-parsing-errors -C np_foobar -o system.sysUpTime.0 -w 1: -c 1: -P 2c"); |
| 174 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); | 153 | cmp_ok( $res->return_code, '==', 3, "Exit UNKNOWN with non responsive host" ); |
| 175 | like($res->output, '/External command error: .*(nosuchhost|Name or service not known|Unknown host).*/s', "String matches invalid host"); | 154 | like($res->output, '/.*Unknown host.*/s', "String matches invalid host"); |
| 176 | } | 155 | } |
diff --git a/plugins/t/check_tcp.t b/plugins/t/check_tcp.t index cb4de53d..5c8fd0be 100644 --- a/plugins/t/check_tcp.t +++ b/plugins/t/check_tcp.t | |||
| @@ -21,19 +21,19 @@ my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname | |||
| 21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); | 21 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost"); |
| 22 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); | 22 | my $internet_access = getTestParameter("NP_INTERNET_ACCESS", "Is this system directly connected to the internet?", "yes"); |
| 23 | 23 | ||
| 24 | my $successOutput = '/^TCP OK\s-\s+[0-9]?\.?[0-9]+ second response time on port [0-9]+/'; | 24 | my $successOutput = '/Connection time\s+[0-9]?\.?[0-9]+s is within thresholds+/'; |
| 25 | 25 | ||
| 26 | my $failedExpect = '/^TCP WARNING\s-\sUnexpected response from host/socket on port [0-9]+/'; | 26 | my $failedExpect = '/Answer failed to match/'; |
| 27 | 27 | ||
| 28 | my $t; | 28 | my $t; |
| 29 | 29 | ||
| 30 | $tests = $tests - 4 if $internet_access eq "no"; | 30 | $tests = $tests - 4 if $internet_access eq "no"; |
| 31 | plan tests => $tests; | 31 | plan tests => $tests; |
| 32 | 32 | ||
| 33 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -wt 300 -ct 600", 0, $successOutput ); | 33 | $t += checkCmd( "./check_tcp $host_tcp_http -p 80 -w 300 -c 600", 0, $successOutput ); |
| 34 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -wt 0 -ct 0 -to 1", 2 ); # use invalid port for this test | 34 | $t += checkCmd( "./check_tcp $host_tcp_http -p 81 -w 0 -c 0 -t 1", 2 ); # use invalid port for this test |
| 35 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -wt 0 -ct 0 -to 1", 2 ); | 35 | $t += checkCmd( "./check_tcp $host_nonresponsive -p 80 -w 0 -c 0 -t 1", 2 ); |
| 36 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -wt 0 -ct 0 -to 1", 2 ); | 36 | $t += checkCmd( "./check_tcp $hostname_invalid -p 80 -w 0 -c 0 -t 1", 2 ); |
| 37 | if($internet_access ne "no") { | 37 | if($internet_access ne "no") { |
| 38 | $t += checkCmd( "./check_tcp -S -D 1 -H $host_tls_http -p 443", 0 ); | 38 | $t += checkCmd( "./check_tcp -S -D 1 -H $host_tls_http -p 443", 0 ); |
| 39 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H $host_tls_http -p 443", 1 ); | 39 | $t += checkCmd( "./check_tcp -S -D 9000,1 -H $host_tls_http -p 443", 1 ); |
diff --git a/plugins/t/check_udp.t b/plugins/t/check_udp.t index 6c47d095..5cb9e6dc 100644 --- a/plugins/t/check_udp.t +++ b/plugins/t/check_udp.t | |||
| @@ -28,7 +28,7 @@ like ( $res->output, '/With UDP checks, a send/expect string must be specified. | |||
| 28 | 28 | ||
| 29 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foo -e bar" ); | 29 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s foo -e bar" ); |
| 30 | cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" ); | 30 | cmp_ok( $res->return_code, '==', 2, "Errors correctly because no udp service running" ); |
| 31 | like ( $res->output, '/No data received from host/', "Output OK"); | 31 | like ( $res->output, '/Received no data /', "Output OK"); |
| 32 | 32 | ||
| 33 | my $nc; | 33 | my $nc; |
| 34 | if(system("which nc.traditional >/dev/null 2>&1") == 0) { | 34 | if(system("which nc.traditional >/dev/null 2>&1") == 0) { |
| @@ -48,7 +48,7 @@ SKIP: { | |||
| 48 | sleep 1; | 48 | sleep 1; |
| 49 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" ); | 49 | $res = NPTest->testCmd( "./check_udp -H localhost -p 3333 -s '' -e barbar -4" ); |
| 50 | cmp_ok( $res->return_code, '==', 0, "Got barbar response back" ); | 50 | cmp_ok( $res->return_code, '==', 0, "Got barbar response back" ); |
| 51 | like ( $res->output, '/\[barbar\]/', "Output OK"); | 51 | like ( $res->output, '/answer of the server matched/', "Output OK"); |
| 52 | close NC; | 52 | close NC; |
| 53 | 53 | ||
| 54 | # Start up a udp server listening on port 3333, quit after 3 seconds | 54 | # Start up a udp server listening on port 3333, quit after 3 seconds |
diff --git a/plugins/t/check_users.t b/plugins/t/check_users.t index 21c3e53d..446e0476 100644 --- a/plugins/t/check_users.t +++ b/plugins/t/check_users.t | |||
| @@ -15,8 +15,8 @@ use NPTest; | |||
| 15 | use vars qw($tests); | 15 | use vars qw($tests); |
| 16 | BEGIN {$tests = 12; plan tests => $tests} | 16 | BEGIN {$tests = 12; plan tests => $tests} |
| 17 | 17 | ||
| 18 | my $successOutput = '/^USERS OK - [0-9]+ users currently logged in/'; | 18 | my $successOutput = '/[0-9]+ users currently logged in/'; |
| 19 | my $failureOutput = '/^USERS CRITICAL - [0-9]+ users currently logged in/'; | 19 | my $failureOutput = '/[0-9]+ users currently logged in/'; |
| 20 | my $wrongOptionOutput = '/Usage:/'; | 20 | my $wrongOptionOutput = '/Usage:/'; |
| 21 | 21 | ||
| 22 | my $t; | 22 | my $t; |
