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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#! /usr/bin/perl -w -I ..
#
# Testing NTP
#
# $Id$
#
use strict;
use Test::More;
use NPTest;
my @PLUGINS1 = ('check_ntp', 'check_ntp_peer', 'check_ntp_time');
my @PLUGINS2 = ('check_ntp_peer');
plan tests => (9 * scalar(@PLUGINS1)) + (6 * scalar(@PLUGINS2));
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");
my $ntp_okmatch1 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
my $ntp_warnmatch1 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
my $ntp_critmatch1 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs/';
my $ntp_okmatch2 = '/^NTP\sOK:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}/';
my $ntp_warnmatch2 = '/^NTP\sWARNING:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}/';
my $ntp_critmatch2 = '/^NTP\sCRITICAL:\sOffset\s-?[0-9]+(\.[0-9]+)?(e-[0-9]{2})?\ssecs,\sjitter=[0-9]+\.[0-9]+,\sstratum=[0-9]{1,2}/';
foreach my $plugin (@PLUGINS1) {
SKIP: {
skip "No NTP server defined", 1 unless $ntp_service;
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000 -c 2000"
);
cmp_ok( $res->return_code, '==', 0, "$plugin: Got good NTP result");
like( $res->output, $ntp_okmatch1, "Output OK" );
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000: -c 2000"
);
cmp_ok( $res->return_code, '==', 1, "$plugin: Got warning NTP result");
like( $res->output, $ntp_warnmatch1, "Output WARNING" );
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000 -c 2000:"
);
cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical NTP result");
like( $res->output, $ntp_critmatch1, "Output CRITICAL" );
}
SKIP: {
skip "No bad NTP server defined", 1 unless $no_ntp_service;
$res = NPTest->testCmd(
"./$plugin -H $no_ntp_service"
);
cmp_ok( $res->return_code, '==', 2, "$plugin: Got bad NTP result");
}
$res = NPTest->testCmd(
"./$plugin -H $host_nonresponsive"
);
cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical if server not responding");
$res = NPTest->testCmd(
"./$plugin -H $hostname_invalid"
);
cmp_ok( $res->return_code, '==', 3, "$plugin: Got critical if server hostname invalid");
}
foreach my $plugin (@PLUGINS2) {
SKIP: {
skip "No NTP server defined", 1 unless $ntp_service;
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k 200000"
);
cmp_ok( $res->return_code, '==', 0, "$plugin: Got good NTP result");
like( $res->output, $ntp_okmatch2, "Output OK" );
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000 -c 2000 -W ~:-1 -C 21 -j 100000 -k 200000"
);
cmp_ok( $res->return_code, '==', 1, "$plugin: Got warning NTP result");
like( $res->output, $ntp_warnmatch2, "Output WARNING" );
$res = NPTest->testCmd(
"./$plugin -H $ntp_service -w 1000 -c 2000 -W 20 -C 21 -j 100000 -k ~:-1"
);
cmp_ok( $res->return_code, '==', 2, "$plugin: Got critical NTP result");
like( $res->output, $ntp_critmatch2, "Output CRITICAL" );
}
}
|