Don't run check_nagios tests on Solaris, because of pst3 requirement
[monitoring-plugins.git] / plugins / t / check_nagios.t
blobd5d48465e0bef979cb33b1008aa9c5be43aa74ef
1 #! /usr/bin/perl -w -I ..
3 # check_nagios tests
5 # $Id$
8 use strict;
9 use Test::More;
10 use NPTest;
12 if (`uname -s` eq "SunOS\n") {
13 plan skip_all => "Ignoring tests on solaris because of pst3";
14 } else {
15 plan tests => 13;
18 my $successOutput = '/^NAGIOS OK: /';
19 my $warningOutput = '/^NAGIOS WARNING: /';
20 my $failureOutput = '/^NAGIOS CRITICAL: /';
22 my $nagios1 = "t/check_nagios.nagios1.status.log";
23 my $nagios2 = "t/check_nagios.nagios2.status.dat";
25 my $result;
27 # Did use init, but MacOSX 10.4 replaces init with launchd
28 # Alternative is to insist that nagios is running to run this test
29 # Reasonable to expect cron because build servers will
30 # invoke cron to run a build
31 my $procname = "cron";
33 $result = NPTest->testCmd(
34 "./check_nagios -F $nagios1 -e 5 -C $procname"
36 cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" );
37 like ( $result->output, $warningOutput, "Output for warning correct" );
39 my $now = time;
40 # This substitution is dependant on the testcase
41 system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
43 $result = NPTest->testCmd(
44 "./check_nagios -F $nagios1.tmp -e 1 -C $procname"
46 cmp_ok( $result->return_code, "==", 0, "Log up to date" );
47 like ( $result->output, $successOutput, "Output for success correct" );
49 my $later = $now - 61;
50 system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1";
52 $result = NPTest->testCmd(
53 "./check_nagios -F $nagios1.tmp -e 1 -C $procname"
55 cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" );
56 my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
57 like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
59 $result = NPTest->testCmd(
60 "./check_nagios -F $nagios1.tmp -e 5 -C unlikely_command_string"
62 cmp_ok( $result->return_code, "==", 2, "Nagios command not found" );
63 like ( $result->output, $failureOutput, "Output for failure correct" );
65 $result = NPTest->testCmd(
66 "./check_nagios -F $nagios2 -e 5 -C $procname"
68 cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" );
70 $now = time;
71 system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
73 $result = NPTest->testCmd(
74 "./check_nagios -F $nagios2.tmp -e 1 -C $procname"
76 cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" );
78 $later = $now - 61;
79 system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2";
81 $result = NPTest->testCmd(
82 "./check_nagios -F $nagios2.tmp -e 1 -C $procname"
84 cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" );
85 ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
86 like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" );
88 $result = NPTest->testCmd(
89 "./check_nagios -F t/check_nagios.t -e 1 -C $procname"
91 cmp_ok( $result->return_code, "==", 2, "Invalid log file" );