summaryrefslogtreecommitdiffstats
path: root/plugins/t/check_ntp.t
blob: 6ba521f177fc097af34b554c44f3b4db6c76e3a8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/perl -w -I ..
#
# Testing NTP
#
# $Id$
#

use strict;
use Test::More;
use NPTest;

plan tests => 4;

my $res;

my $ntp_service = getTestParameter( "NP_GOOD_NTP_SERVICE",
		"A host providing NTP service",
		"pool.ntp.org");

my $no_ntp_service = getTestParameter( "NP_NO_NTP_SERVICE",
		"A host NOT providing the NTP service",
		"localhost" );

my $host_nonresponsive = getTestParameter( "NP_HOST_NONRESPONSIVE", 
		"The hostname of system not responsive to network requests",
		"10.0.0.1" );

my $hostname_invalid   = getTestParameter( "NP_HOSTNAME_INVALID", 
		"An invalid (not known to DNS) hostname",  
		"nosuchhost");

SKIP: {
	skip "No NTP server defined", 1 unless $ntp_service;
	$res = NPTest->testCmd(
		"./check_ntp -H $ntp_service"
		);
	cmp_ok( $res->return_code, '==', 0, "Got good NTP result");
}

SKIP: {
	skip "No bad NTP server defined", 1 unless $ntp_service;
	$res = NPTest->testCmd(
		"./check_ntp -H $no_ntp_service"
		);
	cmp_ok( $res->return_code, '==', 2, "Got bad NTP result");
}

$res = NPTest->testCmd(
	"./check_ntp -H $host_nonresponsive"
	);
cmp_ok( $res->return_code, '==', 2, "Got critical if server not responding");

$res = NPTest->testCmd(
	"./check_ntp -H $hostname_invalid"
	);
cmp_ok( $res->return_code, '==', 3, "Got critical if server hostname invalid");