1 #! /usr/bin/perl -w -I ..
11 if (`uname -s` eq "SunOS\n") {
12 plan skip_all
=> "Ignoring tests on solaris because of pst3";
17 my $successOutput = '/^NAGIOS OK: /';
18 my $warningOutput = '/^NAGIOS WARNING: /';
19 my $failureOutput = '/^NAGIOS CRITICAL: /';
21 my $nagios1 = "t/check_nagios.nagios1.status.log";
22 my $nagios2 = "t/check_nagios.nagios2.status.dat";
26 # Did use init, but MacOSX 10.4 replaces init with launchd
27 # Alternative is to insist that nagios is running to run this test
28 # Reasonable to expect cron because build servers will
29 # invoke cron to run a build
30 my $procname = "cron";
32 $result = NPTest
->testCmd(
33 "./check_nagios -F $nagios1 -e 5 -C $procname"
35 cmp_ok
( $result->return_code, '==', 1, "Log over 5 minutes old" );
36 like
( $result->output, $warningOutput, "Output for warning correct" );
39 # This substitution is dependent on the testcase
40 system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
42 $result = NPTest
->testCmd(
43 "./check_nagios -F $nagios1.tmp -e 1 -C $procname"
45 cmp_ok
( $result->return_code, "==", 0, "Log up to date" );
46 like
( $result->output, $successOutput, "Output for success correct" );
48 my $later = $now - 61;
49 system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
51 $result = NPTest
->testCmd(
52 "./check_nagios -F $nagios1.tmp -e 1 -C $procname"
54 cmp_ok
( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" );
55 my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
56 like
( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
58 $result = NPTest
->testCmd(
59 "./check_nagios -F $nagios1.tmp -e 5 -C unlikely_command_string"
61 cmp_ok
( $result->return_code, "==", 2, "Nagios command not found" );
62 like
( $result->output, $failureOutput, "Output for failure correct" );
64 $result = NPTest
->testCmd(
65 "./check_nagios -F $nagios2 -e 5 -C $procname"
67 cmp_ok
( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" );
70 system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
72 $result = NPTest
->testCmd(
73 "./check_nagios -F $nagios2.tmp -e 1 -C $procname"
75 cmp_ok
( $result->return_code, "==", 0, "Nagios2 log up to date" );
78 system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
80 $result = NPTest
->testCmd(
81 "./check_nagios -F $nagios2.tmp -e 1 -C $procname"
83 cmp_ok
( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" );
84 ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
85 like
( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
87 $result = NPTest
->testCmd(
88 "./check_nagios -F t/check_nagios.t -e 1 -C $procname"
90 cmp_ok
( $result->return_code, "==", 2, "Invalid log file" );