summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/t/check_nagios.t20
1 files changed, 13 insertions, 7 deletions
diff --git a/plugins/t/check_nagios.t b/plugins/t/check_nagios.t
index 7722071..bdb444f 100644
--- a/plugins/t/check_nagios.t
+++ b/plugins/t/check_nagios.t
@@ -18,8 +18,14 @@ my $nagios2 = "t/check_nagios.nagios2.status.dat";
18 18
19my $result; 19my $result;
20 20
21# Did use init, but MacOSX 10.4 replaces init with launchd
22# Alternative is to insist that nagios is running to run this test
23# Reasonable to expect cron because build servers will
24# invoke cron to run a build
25my $procname = "cron";
26
21$result = NPTest->testCmd( 27$result = NPTest->testCmd(
22 "./check_nagios -F $nagios1 -e 5 -C init" 28 "./check_nagios -F $nagios1 -e 5 -C $procname"
23 ); 29 );
24cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" ); 30cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" );
25like ( $result->output, $warningOutput, "Output for warning correct" ); 31like ( $result->output, $warningOutput, "Output for warning correct" );
@@ -29,7 +35,7 @@ my $now = time;
29system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; 35system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
30 36
31$result = NPTest->testCmd( 37$result = NPTest->testCmd(
32 "./check_nagios -F $nagios1.tmp -e 1 -C init" 38 "./check_nagios -F $nagios1.tmp -e 1 -C $procname"
33 ); 39 );
34cmp_ok( $result->return_code, "==", 0, "Log up to date" ); 40cmp_ok( $result->return_code, "==", 0, "Log up to date" );
35like ( $result->output, $successOutput, "Output for success correct" ); 41like ( $result->output, $successOutput, "Output for success correct" );
@@ -38,7 +44,7 @@ my $later = $now - 61;
38system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; 44system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
39 45
40$result = NPTest->testCmd( 46$result = NPTest->testCmd(
41 "./check_nagios -F $nagios1.tmp -e 1 -C init" 47 "./check_nagios -F $nagios1.tmp -e 1 -C $procname"
42 ); 48 );
43cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" ); 49cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" );
44my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/; 50my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
@@ -51,7 +57,7 @@ cmp_ok( $result->return_code, "==", 2, "Nagios command not found" );
51like ( $result->output, $failureOutput, "Output for failure correct" ); 57like ( $result->output, $failureOutput, "Output for failure correct" );
52 58
53$result = NPTest->testCmd( 59$result = NPTest->testCmd(
54 "./check_nagios -F $nagios2 -e 5 -C init" 60 "./check_nagios -F $nagios2 -e 5 -C $procname"
55 ); 61 );
56cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" ); 62cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" );
57 63
@@ -59,7 +65,7 @@ $now = time;
59system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2"; 65system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
60 66
61$result = NPTest->testCmd( 67$result = NPTest->testCmd(
62 "./check_nagios -F $nagios2.tmp -e 1 -C init" 68 "./check_nagios -F $nagios2.tmp -e 1 -C $procname"
63 ); 69 );
64cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" ); 70cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" );
65 71
@@ -67,14 +73,14 @@ $later = $now - 61;
67system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2"; 73system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
68 74
69$result = NPTest->testCmd( 75$result = NPTest->testCmd(
70 "./check_nagios -F $nagios2.tmp -e 1 -C init" 76 "./check_nagios -F $nagios2.tmp -e 1 -C $procname"
71 ); 77 );
72cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" ); 78cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" );
73($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/; 79($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
74like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" ); 80like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
75 81
76$result = NPTest->testCmd( 82$result = NPTest->testCmd(
77 "./check_nagios -F t/check_nagios.t -e 1 -C init" 83 "./check_nagios -F t/check_nagios.t -e 1 -C $procname"
78 ); 84 );
79cmp_ok( $result->return_code, "==", 2, "Invalid log file" ); 85cmp_ok( $result->return_code, "==", 2, "Invalid log file" );
80 86