diff options
author | Ton Voon <tonvoon@users.sourceforge.net> | 2005-12-02 22:28:06 +0000 |
---|---|---|
committer | Ton Voon <tonvoon@users.sourceforge.net> | 2005-12-02 22:28:06 +0000 |
commit | ec6d0db61c33e65a1c3e414b07638a55022dfbf6 (patch) | |
tree | 7c9d092636a8d76fb422392870e99860569717e3 /plugins/t | |
parent | 01886efb2bc2500e4cd441d7d18f74cb817efd0c (diff) | |
download | monitoring-plugins-ec6d0db61c33e65a1c3e414b07638a55022dfbf6.tar.gz |
Support for Nagios 1 and Nagios 2 status files (Gerhard Lausser - 1296242)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1294 f882894a-f735-0410-b71e-b25c423dba1c
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 @@ +# Nagios 1.2 Status File +[1133537544] PROGRAM;1133537484;21980;1;1133537534;0;1;1;1;1;0;1;1;1 +[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) +[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) +[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 @@ +######################################## +# NAGIOS STATUS FILE +# +# THIS FILE IS AUTOMATICALLY GENERATED +# BY NAGIOS. DO NOT MODIFY THIS FILE! +######################################## + +info { + created=1133537302 + version=2.0b5 + } + +program { + modified_host_attributes=0 + modified_service_attributes=0 + nagios_pid=2750 + daemon_mode=1 + program_start=1133537167 + last_command_check=1133537297 + last_log_rotation=0 + enable_notifications=1 + active_service_checks_enabled=1 + passive_service_checks_enabled=1 + active_host_checks_enabled=1 + passive_host_checks_enabled=1 + enable_event_handlers=1 + obsess_over_services=0 + obsess_over_hosts=0 + check_service_freshness=1 + check_host_freshness=0 + enable_flap_detection=1 + enable_failure_prediction=1 + process_performance_data=0 + global_host_event_handler= + global_service_event_handler= + } + +host { + host_name=ADSL-derby-office + modified_attributes=0 + check_command=check_host_alive_ping + event_handler= + has_been_checked=0 + should_be_scheduled=0 + check_execution_time=0.000 + check_latency=0.000 + check_type=0 + current_state=0 + last_hard_state=0 + plugin_output= + performance_data= + last_check=0 + next_check=0 + current_attempt=1 + max_attempts=3 + state_type=1 + last_state_change=0 + last_hard_state_change=0 + last_time_up=0 + last_time_down=0 + last_time_unreachable=0 + last_notification=0 + next_notification=0 + no_more_notifications=0 + current_notification_number=0 + notifications_enabled=1 + problem_has_been_acknowledged=0 + acknowledgement_type=0 + active_checks_enabled=1 + passive_checks_enabled=1 + event_handler_enabled=1 + flap_detection_enabled=1 + failure_prediction_enabled=1 + process_performance_data=1 + obsess_over_host=1 + last_update=1133537302 + is_flapping=0 + percent_state_change=0.00 + scheduled_downtime_depth=0 + } + +service { + host_name=ADSL-derby-office + service_description=TCP/IP + modified_attributes=0 + check_command=host5_service23_check_ping + event_handler= + has_been_checked=0 + should_be_scheduled=1 + check_execution_time=0.000 + check_latency=0.000 + check_type=0 + current_state=0 + last_hard_state=0 + current_attempt=1 + max_attempts=3 + state_type=1 + last_state_change=0 + last_hard_state_change=0 + last_time_ok=0 + last_time_warning=0 + last_time_unknown=0 + last_time_critical=0 + plugin_output=(Service assumed to be ok) + performance_data= + last_check=0 + next_check=1133537317 + current_notification_number=0 + last_notification=0 + next_notification=0 + no_more_notifications=0 + notifications_enabled=0 + active_checks_enabled=1 + passive_checks_enabled=1 + event_handler_enabled=1 + problem_has_been_acknowledged=0 + acknowledgement_type=0 + flap_detection_enabled=1 + failure_prediction_enabled=1 + process_performance_data=1 + obsess_over_service=0 + last_update=1133537302 + is_flapping=0 + percent_state_change=0.00 + scheduled_downtime_depth=0 + } + 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 @@ +#! /usr/bin/perl -w -I .. +# +# check_nagios tests +# +# $Id$ +# + +use strict; +use Test::More tests => 13; +use NPTest; + +my $successOutput = '/^NAGIOS OK: /'; +my $warningOutput = '/^NAGIOS WARNING: /'; +my $failureOutput = '/^NAGIOS CRITICAL: /'; + +my $nagios1 = "t/check_nagios.nagios1.status.log"; +my $nagios2 = "t/check_nagios.nagios2.status.dat"; + +my $result; + +$result = NPTest->testCmd( + "./check_nagios -F $nagios1 -e 5 -C init" + ); +cmp_ok( $result->return_code, '==', 1, "Log over 5 minutes old" ); +like ( $result->output, $warningOutput, "Output for warning correct" ); + +my $now = time; +# This substitution is dependant on the testcase +system( "perl -pe 's/1133537544/$now/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; + +$result = NPTest->testCmd( + "./check_nagios -F $nagios1.tmp -e 1 -C init" + ); +cmp_ok( $result->return_code, "==", 0, "Log up to date" ); +like ( $result->output, $successOutput, "Output for success correct" ); + +my $later = $now - 61; +system( "perl -pe 's/1133537544/$later/' $nagios1 > $nagios1.tmp" ) == 0 or die "Problem with munging $nagios1"; + +$result = NPTest->testCmd( + "./check_nagios -F $nagios1.tmp -e 1 -C init" + ); +cmp_ok( $result->return_code, "==", 1, "Log correctly seen as over 1 minute old" ); +my ($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/; +like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" ); + +$result = NPTest->testCmd( + "./check_nagios -F $nagios1.tmp -e 5 -C unlikely_command_string" + ); +cmp_ok( $result->return_code, "==", 2, "Nagios command not found" ); +like ( $result->output, $failureOutput, "Output for failure correct" ); + +$result = NPTest->testCmd( + "./check_nagios -F $nagios2 -e 5 -C init" + ); +cmp_ok( $result->return_code, "==", 1, "Nagios2 for logfile over 5 mins old" ); + +$now = time; +system( "perl -pe 's/1133537302/$now/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2"; + +$result = NPTest->testCmd( + "./check_nagios -F $nagios2.tmp -e 1 -C init" + ); +cmp_ok( $result->return_code, "==", 0, "Nagios2 log up to date" ); + +$later = $now - 61; +system( "perl -pe 's/1133537302/$later/' $nagios2 > $nagios2.tmp" ) == 0 or die "Problem with munging $nagios2"; + +$result = NPTest->testCmd( + "./check_nagios -F $nagios2.tmp -e 1 -C init" + ); +cmp_ok( $result->return_code, "==", 1, "Nagios2 log correctly seen as over 1 minute old" ); +($age) = ($_ = $result->output) =~ /status log updated (\d+) seconds ago/; +like( $age, '/^6[0-9]$/', "Log correctly seen as between 60-69 seconds old" ); + +$result = NPTest->testCmd( + "./check_nagios -F t/check_nagios.t -e 1 -C init" + ); +cmp_ok( $result->return_code, "==", 2, "Invalid log file" ); + + |