summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_nagios.t
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/t/check_nagios.t')
-rw-r--r--plugins/t/check_nagios.t81
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
8use strict;
9use Test::More tests => 13;
10use NPTest;
11
12my $successOutput = '/^NAGIOS OK: /';
13my $warningOutput = '/^NAGIOS WARNING: /';
14my $failureOutput = '/^NAGIOS CRITICAL: /';
15
16my $nagios1 = "t/check_nagios.nagios1.status.log";
17my $nagios2 = "t/check_nagios.nagios2.status.dat";
18
19my $result;
20
21$result = NPTest->testCmd(
22 "./check_nagios -F $nagios1 -e 5 -C init"
23 );
24cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" );
25like ( $result->output, $warningOutput, "Output for warning correct" );
26
27my $now = time;
28# This substitution is dependant on the testcase
29system( "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 );
34cmp_ok( $result->return_code, "==", 0, "Log up to date" );
35like ( $result->output, $successOutput, "Output for success correct" );
36
37my $later = $now - 61;
38system( "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 );
43cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" );
44my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
45like( $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 );
50cmp_ok( $result->return_code, "==", 2, "Nagios command not found" );
51like ( $result->output, $failureOutput, "Output for failure correct" );
52
53$result = NPTest->testCmd(
54 "./check_nagios -F $nagios2 -e 5 -C init"
55 );
56cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" );
57
58$now = time;
59system( "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 );
64cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" );
65
66$later = $now - 61;
67system( "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 );
72cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" );
73($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/;
74like( $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 );
79cmp_ok( $result->return_code, "==", 2, "Invalid log file" );
80
81