diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-11-02 13:37:39 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2024-11-02 13:37:39 +0100 |
| commit | 3faeed07c4825d5c3ceb323e814e703d9262cd82 (patch) | |
| tree | b6a61e24ffa0fbb4af5f145c137f1f584aaba1bc /plugins/t | |
| parent | 735b04eff721a28e791714c0da4c8ac5726bfbcf (diff) | |
| parent | 6d1d1dac32841d5ca6ee51bb09b30a6c604b17e2 (diff) | |
| download | monitoring-plugins-3faeed07c4825d5c3ceb323e814e703d9262cd82.tar.gz | |
Merge branch 'master' into check_swap_again
Diffstat (limited to 'plugins/t')
| -rw-r--r-- | plugins/t/check_curl.t | 4 | ||||
| -rw-r--r-- | plugins/t/check_disk.t | 10 | ||||
| -rw-r--r-- | plugins/t/check_http.t | 4 | ||||
| -rw-r--r-- | plugins/t/check_ssh.t | 122 | ||||
| -rw-r--r-- | plugins/t/check_swap.t | 14 |
5 files changed, 126 insertions, 28 deletions
diff --git a/plugins/t/check_curl.t b/plugins/t/check_curl.t index eae98cc1..7a930a4e 100644 --- a/plugins/t/check_curl.t +++ b/plugins/t/check_curl.t | |||
| @@ -205,9 +205,9 @@ SKIP: { | |||
| 205 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 205 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
| 206 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 206 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
| 207 | 207 | ||
| 208 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f curl" ); | 208 | $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"); | 209 | is( $res->return_code, 0, "Redirection based on location is okay"); |
| 210 | 210 | ||
| 211 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); | 211 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); |
| 212 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 212 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
| 213 | } | 213 | } |
diff --git a/plugins/t/check_disk.t b/plugins/t/check_disk.t index bf8dd362..9eb77ce4 100644 --- a/plugins/t/check_disk.t +++ b/plugins/t/check_disk.t | |||
| @@ -44,7 +44,7 @@ my @perf_data = sort(split(/ /, $result->perf_output)); | |||
| 44 | # Calculate avg_free free on mountpoint1 and mountpoint2 | 44 | # Calculate avg_free free on mountpoint1 and mountpoint2 |
| 45 | # because if you check in the middle, you should get different errors | 45 | # because if you check in the middle, you should get different errors |
| 46 | $_ = $result->output; | 46 | $_ = $result->output; |
| 47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+)%.*\((\d+)%/); | 47 | my ($free_on_mp1, $free_on_mp2) = (m/\((\d+\.\d+)%.*\((\d+\.\d+)%/); |
| 48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); | 48 | die "Cannot parse output: $_" unless ($free_on_mp1 && $free_on_mp2); |
| 49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); | 49 | my $avg_free = ceil(($free_on_mp1+$free_on_mp2)/2); |
| 50 | my ($more_free, $less_free); | 50 | my ($more_free, $less_free); |
| @@ -119,8 +119,12 @@ like ( $result->only_output, qr/$more_free/, "Have disk name in text"); | |||
| 119 | 119 | ||
| 120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); | 120 | $result = NPTest->testCmd( "./check_disk -w 1 -c 1 -p $more_free -p $less_free" ); |
| 121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); | 121 | cmp_ok( $result->return_code, '==', 0, "At least 1 MB available on $more_free and $less_free"); |
| 122 | |||
| 122 | $_ = $result->output; | 123 | $_ = $result->output; |
| 124 | |||
| 123 | my ($free_mb_on_mp1, $free_mb_on_mp2) = (m/(\d+)MiB .* (\d+)MiB /g); | 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); | ||
| 127 | |||
| 124 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; | 128 | my $free_mb_on_all = $free_mb_on_mp1 + $free_mb_on_mp2; |
| 125 | 129 | ||
| 126 | 130 | ||
| @@ -311,8 +315,8 @@ $result = NPTest->testCmd( "./check_disk -w 0% -c 0% -C -w 0% -c 0% -p $mountpoi | |||
| 311 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); | 315 | like( $result->output, '/;.*;\|/', "-C selects partitions if -p is not given"); |
| 312 | 316 | ||
| 313 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit | 317 | # grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit |
| 314 | $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" ); | 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" ); |
| 315 | cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit"); | 319 | cmp_ok( $result->return_code, '==', 2, "grouping: exit crit if the sum of free megs on mp1+mp2 is less than warn/crit\nInstead received: " . $result->output); |
| 316 | 320 | ||
| 317 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c | 321 | # grouping: exit warning if the sum of free megs on mp1+mp2 is between -w and -c |
| 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" ); | 322 | $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" ); |
diff --git a/plugins/t/check_http.t b/plugins/t/check_http.t index 1f2fbdfd..6ab4a5b6 100644 --- a/plugins/t/check_http.t +++ b/plugins/t/check_http.t | |||
| @@ -166,10 +166,10 @@ SKIP: { | |||
| 166 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 166 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
| 167 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); | 167 | like ( $res->output, '/time_ssl=[\d\.]+/', 'Extended Performance Data SSL Output OK' ); |
| 168 | 168 | ||
| 169 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com -u /firefox -f follow" ); | 169 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org -u /download.html -f follow" ); |
| 170 | is( $res->return_code, 0, "Redirection based on location is okay"); | 170 | is( $res->return_code, 0, "Redirection based on location is okay"); |
| 171 | 171 | ||
| 172 | $res = NPTest->testCmd( "./$plugin -H www.mozilla.com --extended-perfdata" ); | 172 | $res = NPTest->testCmd( "./$plugin -H monitoring-plugins.org --extended-perfdata" ); |
| 173 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); | 173 | like ( $res->output, '/time_connect=[\d\.]+/', 'Extended Performance Data Output OK' ); |
| 174 | } | 174 | } |
| 175 | 175 | ||
diff --git a/plugins/t/check_ssh.t b/plugins/t/check_ssh.t index a5cd23ce..907d33a8 100644 --- a/plugins/t/check_ssh.t +++ b/plugins/t/check_ssh.t | |||
| @@ -8,34 +8,116 @@ use strict; | |||
| 8 | use Test::More; | 8 | use Test::More; |
| 9 | use NPTest; | 9 | use NPTest; |
| 10 | 10 | ||
| 11 | my $res; | ||
| 12 | |||
| 11 | # Required parameters | 13 | # Required parameters |
| 12 | my $ssh_host = getTestParameter("NP_SSH_HOST", "A host providing SSH service", "localhost"); | 14 | my $ssh_host = getTestParameter("NP_SSH_HOST", |
| 13 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1" ); | 15 | "A host providing SSH service", |
| 14 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost" ); | 16 | "localhost"); |
| 17 | |||
| 18 | my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", | ||
| 19 | "The hostname of system not responsive to network requests", | ||
| 20 | "10.0.0.1" ); | ||
| 21 | |||
| 22 | my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", | ||
| 23 | "An invalid (not known to DNS) hostname", | ||
| 24 | "nosuchhost" ); | ||
| 25 | |||
| 26 | |||
| 27 | plan tests => 14 + 6; | ||
| 28 | |||
| 29 | SKIP: { | ||
| 30 | skip "SSH_HOST must be defined", 6 unless $ssh_host; | ||
| 31 | my $result = NPTest->testCmd( | ||
| 32 | "./check_ssh -H $ssh_host" | ||
| 33 | ); | ||
| 34 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); | ||
| 35 | like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)"); | ||
| 36 | |||
| 37 | |||
| 38 | $result = NPTest->testCmd( | ||
| 39 | "./check_ssh -H $host_nonresponsive -t 2" | ||
| 40 | ); | ||
| 41 | cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)"); | ||
| 42 | like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)"); | ||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | $result = NPTest->testCmd( | ||
| 47 | "./check_ssh -H $hostname_invalid -t 2" | ||
| 48 | ); | ||
| 49 | cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)"); | ||
| 50 | like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)"); | ||
| 51 | |||
| 15 | 52 | ||
| 53 | } | ||
| 54 | SKIP: { | ||
| 16 | 55 | ||
| 17 | plan skip_all => "SSH_HOST must be defined" unless $ssh_host; | 56 | skip "No netcat available", 14 unless (system("which nc > /dev/null") == 0); |
| 18 | plan tests => 6; | ||
| 19 | 57 | ||
| 58 | # netcat on linux (on debian) will just keep the socket open if not advised otherwise | ||
| 59 | # therefore we add -q to close it after two seconds after receiving the EOF from input | ||
| 60 | my $nc_flags = "-l 5003 -N"; | ||
| 61 | #A valid protocol version control string has the form | ||
| 62 | # SSH-protoversion-softwareversion SP comments CR LF | ||
| 63 | # | ||
| 64 | # where `comments` is optional, protoversion is the SSH protocol version and | ||
| 65 | # softwareversion is an arbitrary string representing the server software version | ||
| 66 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1' | nc ${nc_flags}|"); | ||
| 67 | sleep 0.1; | ||
| 68 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
| 69 | cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string"); | ||
| 70 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK"); | ||
| 71 | close NC; | ||
| 20 | 72 | ||
| 21 | my $result = NPTest->testCmd( | 73 | open(NC, "echo 'SSH-2.0-3.2.9.1' | nc ${nc_flags}|"); |
| 22 | "./check_ssh -H $ssh_host" | 74 | sleep 0.1; |
| 23 | ); | 75 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); |
| 24 | cmp_ok($result->return_code, '==', 0, "Exit with return code 0 (OK)"); | 76 | cmp_ok( $res->return_code, "==", 0, "Got SSH protocol version control string with non-alpha softwareversion string"); |
| 25 | like($result->output, '/^SSH OK - /', "Status text if command returned none (OK)"); | 77 | like( $res->output, '/^SSH OK - 3.2.9.1 \(protocol 2.0\)/', "Output OK for non-alpha softwareversion string"); |
| 78 | close NC; | ||
| 26 | 79 | ||
| 80 | open(NC, "echo 'SSH-2.0-nagiosplug.ssh.0.1 this is a comment' | nc ${nc_flags} |"); | ||
| 81 | sleep 0.1; | ||
| 82 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003 -r nagiosplug.ssh.0.1" ); | ||
| 83 | cmp_ok( $res->return_code, '==', 0, "Got SSH protocol version control string, and parsed comment appropriately"); | ||
| 84 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.1 \(protocol 2.0\)/', "Output OK"); | ||
| 85 | close NC; | ||
| 27 | 86 | ||
| 28 | $result = NPTest->testCmd( | 87 | open(NC, "echo 'SSH-' | nc ${nc_flags}|"); |
| 29 | "./check_ssh -H $host_nonresponsive -t 2" | 88 | sleep 0.1; |
| 30 | ); | 89 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); |
| 31 | cmp_ok($result->return_code, '==', 2, "Exit with return code 0 (OK)"); | 90 | cmp_ok( $res->return_code, '==', 2, "Got invalid SSH protocol version control string"); |
| 32 | like($result->output, '/^CRITICAL - Socket timeout after 2 seconds/', "Status text if command returned none (OK)"); | 91 | like( $res->output, '/^SSH CRITICAL/', "Output OK"); |
| 92 | close NC; | ||
| 33 | 93 | ||
| 94 | open(NC, "echo '' | nc ${nc_flags}|"); | ||
| 95 | sleep 0.1; | ||
| 96 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
| 97 | cmp_ok( $res->return_code, '==', 2, "No version control string received"); | ||
| 98 | like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK"); | ||
| 99 | close NC; | ||
| 34 | 100 | ||
| 101 | open(NC, "echo 'Not a version control string' | nc ${nc_flags}|"); | ||
| 102 | sleep 0.1; | ||
| 103 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
| 104 | cmp_ok( $res->return_code, '==', 2, "No version control string received"); | ||
| 105 | like( $res->output, '/^SSH CRITICAL - No version control string received/', "Output OK"); | ||
| 106 | close NC; | ||
| 35 | 107 | ||
| 36 | $result = NPTest->testCmd( | ||
| 37 | "./check_ssh -H $hostname_invalid -t 2" | ||
| 38 | ); | ||
| 39 | cmp_ok($result->return_code, '==', 3, "Exit with return code 0 (OK)"); | ||
| 40 | like($result->output, '/^check_ssh: Invalid hostname/', "Status text if command returned none (OK)"); | ||
| 41 | 108 | ||
| 109 | #RFC 4253 permits servers to send any number of data lines prior to sending the protocol version control string | ||
| 110 | open(NC, "{ echo 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'; sleep 0.5; | ||
| 111 | echo 'BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB'; sleep 0.5; | ||
| 112 | echo 'CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC'; sleep 0.2; | ||
| 113 | echo 'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD'; sleep 0.3; | ||
| 114 | printf 'EEEEEEEEEEEEEEEEEE'; sleep 0.2; | ||
| 115 | printf 'EEEEEEEEEEEEEEEEEE\n'; sleep 0.2; | ||
| 116 | echo 'Some\nPrepended\nData\nLines\n'; sleep 0.2; | ||
| 117 | echo 'SSH-2.0-nagiosplug.ssh.0.2';} | nc ${nc_flags}|"); | ||
| 118 | sleep 0.1; | ||
| 119 | $res = NPTest->testCmd( "./check_ssh -H localhost -p 5003" ); | ||
| 120 | cmp_ok( $res->return_code, '==', 0, "Got delayed SSH protocol version control string"); | ||
| 121 | like( $res->output, '/^SSH OK - nagiosplug.ssh.0.2 \(protocol 2.0\)/', "Output OK"); | ||
| 122 | close NC; | ||
| 123 | } | ||
diff --git a/plugins/t/check_swap.t b/plugins/t/check_swap.t index de9e0f05..18780386 100644 --- a/plugins/t/check_swap.t +++ b/plugins/t/check_swap.t | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | # | 5 | # |
| 6 | 6 | ||
| 7 | use strict; | 7 | use strict; |
| 8 | use Test::More tests => 8; | 8 | use Test::More tests => 14; |
| 9 | use NPTest; | 9 | use NPTest; |
| 10 | 10 | ||
| 11 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; | 11 | my $successOutput = '/^SWAP OK - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\)/'; |
| @@ -14,6 +14,10 @@ my $warnOutput = '/^SWAP WARNING - [0-9]+\% free \([0-9]+MB out of [0-9]+MB\) | |||
| 14 | 14 | ||
| 15 | my $result; | 15 | my $result; |
| 16 | 16 | ||
| 17 | $result = NPTest->testCmd( "./check_swap" ); # Always OK | ||
| 18 | cmp_ok( $result->return_code, "==", 0, "Always OK" ); | ||
| 19 | like( $result->output, $successOutput, "Right output" ); | ||
| 20 | |||
| 17 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free | 21 | $result = NPTest->testCmd( "./check_swap -w 1048576 -c 1048576" ); # 1 MB free |
| 18 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); | 22 | cmp_ok( $result->return_code, "==", 0, "At least 1MB free" ); |
| 19 | like( $result->output, $successOutput, "Right output" ); | 23 | like( $result->output, $successOutput, "Right output" ); |
| @@ -29,3 +33,11 @@ like( $result->output, $failureOutput, "Right output" ); | |||
| 29 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) | 33 | $result = NPTest->testCmd( "./check_swap -w 100% -c 1%" ); # 100% (always warn) |
| 30 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | 34 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); |
| 31 | like( $result->output, $warnOutput, "Right output" ); | 35 | like( $result->output, $warnOutput, "Right output" ); |
| 36 | |||
| 37 | $result = NPTest->testCmd( "./check_swap -w 100%" ); # 100% (single threshold, always warn) | ||
| 38 | cmp_ok( $result->return_code, "==", 1, 'Get warning because not 100% free' ); | ||
| 39 | like( $result->output, $warnOutput, "Right output" ); | ||
| 40 | |||
| 41 | $result = NPTest->testCmd( "./check_swap -c 100%" ); # 100% (single threshold, always critical) | ||
| 42 | cmp_ok( $result->return_code, "==", 2, 'Get critical because not 100% free' ); | ||
| 43 | like( $result->output, $failureOutput, "Right output" ); | ||
