diff options
Diffstat (limited to 'plugins/t')
-rw-r--r-- | plugins/t/check_nagios.nagios1.status.log | 5 | ||||
-rw-r--r-- | plugins/t/check_nagios.nagios2.status.dat | 127 | ||||
-rw-r--r-- | plugins/t/check_nagios.t | 81 |
3 files changed, 213 insertions, 0 deletions
diff --git a/plugins/t/check_nagios.nagios1.status.log b/plugins/t/check_nagios.nagios1.status.log new file mode 100644 index 00000000..64d9ce7b --- /dev/null +++ b/plugins/t/check_nagios.nagios1.status.log | |||
@@ -0,0 +1,5 @@ | |||
1 | # Nagios 1.2 Status File | ||
2 | [1133537544] PROGRAM;1133537484;21980;1;1133537534;0;1;1;1;1;0;1;1;1 | ||
3 | [1133537544] HOST;ADSL;PENDING;0;0;0;0;0;0;0;0;1;1;1;1;0;0.0;0;1;1;(Not enough data to determine host status yet) | ||
4 | [1133537544] HOST;Internet;UP;1133537486;1132135282;0;1402203;0;0;0;0;1;1;1;1;0;0.00;0;1;1;(Host assumed to be up) | ||
5 | [1133537544] SERVICE;Internet;TCP/IP;OK;1/3;HARD;1133537486;1133537786;ACTIVE;1;1;1;1132135282;0;OK;1402203;0;0;0;0;0;1;0;4;1;0;0.00;0;1;1;0;PING OK - Packet loss = 0%, RTA = 0.09 ms | ||
diff --git a/plugins/t/check_nagios.nagios2.status.dat b/plugins/t/check_nagios.nagios2.status.dat new file mode 100644 index 00000000..6f62baca --- /dev/null +++ b/plugins/t/check_nagios.nagios2.status.dat | |||
@@ -0,0 +1,127 @@ | |||
1 | ######################################## | ||
2 | # NAGIOS STATUS FILE | ||
3 | # | ||
4 | # THIS FILE IS AUTOMATICALLY GENERATED | ||
5 | # BY NAGIOS. DO NOT MODIFY THIS FILE! | ||
6 | ######################################## | ||
7 | |||
8 | info { | ||
9 | created=1133537302 | ||
10 | version=2.0b5 | ||
11 | } | ||
12 | |||
13 | program { | ||
14 | modified_host_attributes=0 | ||
15 | modified_service_attributes=0 | ||
16 | nagios_pid=2750 | ||
17 | daemon_mode=1 | ||
18 | program_start=1133537167 | ||
19 | last_command_check=1133537297 | ||
20 | last_log_rotation=0 | ||
21 | enable_notifications=1 | ||
22 | active_service_checks_enabled=1 | ||
23 | passive_service_checks_enabled=1 | ||
24 | active_host_checks_enabled=1 | ||
25 | passive_host_checks_enabled=1 | ||
26 | enable_event_handlers=1 | ||
27 | obsess_over_services=0 | ||
28 | obsess_over_hosts=0 | ||
29 | check_service_freshness=1 | ||
30 | check_host_freshness=0 | ||
31 | enable_flap_detection=1 | ||
32 | enable_failure_prediction=1 | ||
33 | process_performance_data=0 | ||
34 | global_host_event_handler= | ||
35 | global_service_event_handler= | ||
36 | } | ||
37 | |||
38 | host { | ||
39 | host_name=ADSL-derby-office | ||
40 | modified_attributes=0 | ||
41 | check_command=check_host_alive_ping | ||
42 | event_handler= | ||
43 | has_been_checked=0 | ||
44 | should_be_scheduled=0 | ||
45 | check_execution_time=0.000 | ||
46 | check_latency=0.000 | ||
47 | check_type=0 | ||
48 | current_state=0 | ||
49 | last_hard_state=0 | ||
50 | plugin_output= | ||
51 | performance_data= | ||
52 | last_check=0 | ||
53 | next_check=0 | ||
54 | current_attempt=1 | ||
55 | max_attempts=3 | ||
56 | state_type=1 | ||
57 | last_state_change=0 | ||
58 | last_hard_state_change=0 | ||
59 | last_time_up=0 | ||
60 | last_time_down=0 | ||
61 | last_time_unreachable=0 | ||
62 | last_notification=0 | ||
63 | next_notification=0 | ||
64 | no_more_notifications=0 | ||
65 | current_notification_number=0 | ||
66 | notifications_enabled=1 | ||
67 | problem_has_been_acknowledged=0 | ||
68 | acknowledgement_type=0 | ||
69 | active_checks_enabled=1 | ||
70 | passive_checks_enabled=1 | ||
71 | event_handler_enabled=1 | ||
72 | flap_detection_enabled=1 | ||
73 | failure_prediction_enabled=1 | ||
74 | process_performance_data=1 | ||
75 | obsess_over_host=1 | ||
76 | last_update=1133537302 | ||
77 | is_flapping=0 | ||
78 | percent_state_change=0.00 | ||
79 | scheduled_downtime_depth=0 | ||
80 | } | ||
81 | |||
82 | service { | ||
83 | host_name=ADSL-derby-office | ||
84 | service_description=TCP/IP | ||
85 | modified_attributes=0 | ||
86 | check_command=host5_service23_check_ping | ||
87 | event_handler= | ||
88 | has_been_checked=0 | ||
89 | should_be_scheduled=1 | ||
90 | check_execution_time=0.000 | ||
91 | check_latency=0.000 | ||
92 | check_type=0 | ||
93 | current_state=0 | ||
94 | last_hard_state=0 | ||
95 | current_attempt=1 | ||
96 | max_attempts=3 | ||
97 | state_type=1 | ||
98 | last_state_change=0 | ||
99 | last_hard_state_change=0 | ||
100 | last_time_ok=0 | ||
101 | last_time_warning=0 | ||
102 | last_time_unknown=0 | ||
103 | last_time_critical=0 | ||
104 | plugin_output=(Service assumed to be ok) | ||
105 | performance_data= | ||
106 | last_check=0 | ||
107 | next_check=1133537317 | ||
108 | current_notification_number=0 | ||
109 | last_notification=0 | ||
110 | next_notification=0 | ||
111 | no_more_notifications=0 | ||
112 | notifications_enabled=0 | ||
113 | active_checks_enabled=1 | ||
114 | passive_checks_enabled=1 | ||
115 | event_handler_enabled=1 | ||
116 | problem_has_been_acknowledged=0 | ||
117 | acknowledgement_type=0 | ||
118 | flap_detection_enabled=1 | ||
119 | failure_prediction_enabled=1 | ||
120 | process_performance_data=1 | ||
121 | obsess_over_service=0 | ||
122 | last_update=1133537302 | ||
123 | is_flapping=0 | ||
124 | percent_state_change=0.00 | ||
125 | scheduled_downtime_depth=0 | ||
126 | } | ||
127 | |||
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 | |||