Merge pull request #1586 from computersalat/master
[monitoring-plugins.git] / plugins / t / check_time.t
blob92c2f89190b7b4443c682b2a51e28f24462c1f14
1 #! /usr/bin/perl -w -I ..
3 # System Time Tests via check_time
7 use strict;
8 use Test;
9 use NPTest;
11 use vars qw($tests);
12 BEGIN {$tests = 8; plan tests => $tests}
14 my $host_udp_time = getTestParameter("NP_HOST_UDP_TIME", "A host providing the UDP Time Service", "localhost");
15 my $host_nonresponsive = getTestParameter("NP_HOST_NONRESPONSIVE", "The hostname of system not responsive to network requests", "10.0.0.1");
16 my $hostname_invalid = getTestParameter("NP_HOSTNAME_INVALID", "An invalid (not known to DNS) hostname", "nosuchhost");
18 my $successOutput = '/^TIME OK - [0-9]+ second time difference/';
20 my %exceptions = ( 3 => "No time server present?");
22 my $t;
24 # standard mode
25 $t += checkCmd( "./check_time -H $host_udp_time -w 999999,59 -c 999999,59 -t 60", 0, $successOutput, %exceptions );
26 $t += checkCmd( "./check_time -H $host_udp_time -w 999999 -W 59 -c 999999 -C 59 -t 60", 0, $successOutput, %exceptions );
28 # reverse compatibility mode
29 $t += checkCmd( "./check_time $host_udp_time -wt 59 -ct 59 -cd 999999 -wd 999999 -to 60", 0, $successOutput, %exceptions );
31 # failure mode
32 $t += checkCmd( "./check_time -H $host_nonresponsive -t 1", 2 );
33 $t += checkCmd( "./check_time -H $hostname_invalid -t 1", 3 );
35 exit(0) if defined($Test::Harness::VERSION);
36 exit($tests - $t);