[Nagiosplug-checkins] nagiosplug/plugins/t check_nagios.t,NONE,1.1 check_nagios.nagios1.status.log,NONE,1.1 check_nagios.nagios2.status.dat,NONE,1.1
Ton Voon
tonvoon at users.sourceforge.net
Fri Dec 2 14:29:08 CET 2005
Update of /cvsroot/nagiosplug/nagiosplug/plugins/t
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13216/plugins/t
Added Files:
check_nagios.t check_nagios.nagios1.status.log
check_nagios.nagios2.status.dat
Log Message:
Support for Nagios 1 and Nagios 2 status files (Gerhard Lausser - 1296242)
--- NEW FILE: check_nagios.t ---
#! /usr/bin/perl -w -I ..
#
# check_nagios tests
#
# $Id: check_nagios.t,v 1.1 2005/12/02 22:28:06 tonvoon Exp $
#
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" );
--- NEW FILE: check_nagios.nagios2.status.dat ---
########################################
# 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
}
--- NEW FILE: check_nagios.nagios1.status.log ---
# 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
More information about the Commits
mailing list