diff options
Diffstat (limited to 'plugins/t/check_nagios.t')
| -rw-r--r-- | plugins/t/check_nagios.t | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/plugins/t/check_nagios.t b/plugins/t/check_nagios.t new file mode 100644 index 00000000..7722071d --- /dev/null +++ b/plugins/t/check_nagios.t | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | #! /usr/bin/perl -w -I .. | ||
| 2 | # | ||
| 3 | # check_nagios tests | ||
| 4 | # | ||
| 5 | # $Id$ | ||
| 6 | # | ||
| 7 | |||
| 8 | use strict; | ||
| 9 | use Test::More tests => 13; | ||
| 10 | use NPTest; | ||
| 11 | |||
| 12 | my $successOutput = '/^NAGIOS OK: /'; | ||
| 13 | my $warningOutput = '/^NAGIOS WARNING: /'; | ||
| 14 | my $failureOutput = '/^NAGIOS CRITICAL: /'; | ||
| 15 | |||
| 16 | my $nagios1 = "t/check_nagios.nagios1.status.log"; | ||
| 17 | my $nagios2 = "t/check_nagios.nagios2.status.dat"; | ||
| 18 | |||
| 19 | my $result; | ||
| 20 | |||
| 21 | $result = NPTest->testCmd( | ||
| 22 | "./check_nagios -F $nagios1 -e 5 -C init" | ||
| 23 | ); | ||
| 24 | cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" ); | ||
| 25 | like ( $result->output, $warningOutput, "Output for warning correct" ); | ||
| 26 | |||
| 27 | my $now = time; | ||
| 28 | # This substitution is dependant on the testcase | ||
| 29 | system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; | ||
| 30 | |||
| 31 | $result = NPTest->testCmd( | ||
| 32 | "./check_nagios -F $nagios1.tmp -e 1 -C init" | ||
| 33 | ); | ||
| 34 | cmp_ok( $result->return_code, "==", 0, "Log up to date" ); | ||
| 35 | like ( $result->output, $successOutput, "Output for success correct" ); | ||
| 36 | |||
| 37 | my $later = $now - 61; | ||
| 38 | system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; | ||
| 39 | |||
| 40 | $result = NPTest->testCmd( | ||
| 41 | "./check_nagios -F $nagios1.tmp -e 1 -C init" | ||
| 42 | ); | ||
| 43 | cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" ); | ||
| 44 | my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/; | ||
| 45 | like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" ); | ||
| 46 | |||
| 47 | $result = NPTest->testCmd( | ||
| 48 | "./check_nagios -F $nagios1.tmp -e 5 -C unlikely_command_string" | ||
| 49 | ); | ||
| 50 | cmp_ok( $result->return_code, "==", 2, "Nagios command not found" ); | ||
| 51 | like ( $result->output, $failureOutput, "Output for failure correct" ); | ||
| 52 | |||
| 53 | $result = NPTest->testCmd( | ||
| 54 | "./check_nagios -F $nagios2 -e 5 -C init" | ||
| 55 | ); | ||
| 56 | cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" ); | ||
| 57 | |||
| 58 | $now = time; | ||
| 59 | system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2"; | ||
| 60 | |||
| 61 | $result = NPTest->testCmd( | ||
| 62 | "./check_nagios -F $nagios2.tmp -e 1 -C init" | ||
| 63 | ); | ||
| 64 | cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" ); | ||
| 65 | |||
| 66 | $later = $now - 61; | ||
| 67 | system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2"; | ||
| 68 | |||
| 69 | $result = NPTest->testCmd( | ||
| 70 | "./check_nagios -F $nagios2.tmp -e 1 -C init" | ||
| 71 | ); | ||
| 72 | cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" ); | ||
| 73 | ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/; | ||
| 74 | like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" ); | ||
| 75 | |||
| 76 | $result = NPTest->testCmd( | ||
| 77 | "./check_nagios -F t/check_nagios.t -e 1 -C init" | ||
| 78 | ); | ||
| 79 | cmp_ok( $result->return_code, "==", 2, "Invalid log file" ); | ||
| 80 | |||
| 81 | |||
