summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_ntp.pl
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2005-03-04 21:50:02 +0000
committerTon Voon <tonvoon@users.sourceforge.net>2005-03-04 21:50:02 +0000
commita78fd137e972f62deb6bd2370ef869d256b0bfae (patch)
tree69ad2c8a000582dce68109ff37955d9f9b710d04 /plugins-scripts/check_ntp.pl
parent59a4f3a1c0b2ba0c3ef53ea1541a7fa1fdd93966 (diff)
downloadmonitoring-plugins-a78fd137e972f62deb6bd2370ef869d256b0bfae.tar.gz
Support for IPv6 (Merijn Evertse - 1119917)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1145 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts/check_ntp.pl')
-rwxr-xr-xplugins-scripts/check_ntp.pl38
1 files changed, 28 insertions, 10 deletions
diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl
index 7adef984..cd02d477 100755
--- a/plugins-scripts/check_ntp.pl
+++ b/plugins-scripts/check_ntp.pl
@@ -8,7 +8,7 @@
8# should already have it installed. 8# should already have it installed.
9# 9#
10# $Id$ 10# $Id$
11# 11#
12# Nothing clever done in this program - its a very simple bare basics hack to 12# Nothing clever done in this program - its a very simple bare basics hack to
13# get the job done. 13# get the job done.
14# 14#
@@ -61,8 +61,8 @@ require 5.004;
61use POSIX; 61use POSIX;
62use strict; 62use strict;
63use Getopt::Long; 63use Getopt::Long;
64use vars qw($opt_V $opt_h $opt_H $opt_t $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME $def_jitter); 64use vars qw($opt_V $opt_h $opt_H $opt_t $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME $def_jitter $ipv4 $ipv6);
65use lib utils.pm; 65use lib utils.pm;
66use utils qw($TIMEOUT %ERRORS &print_revision &support); 66use utils qw($TIMEOUT %ERRORS &print_revision &support);
67 67
68$PROGNAME="check_ntp"; 68$PROGNAME="check_ntp";
@@ -85,7 +85,9 @@ Getopt::Long::Configure('bundling');
85GetOptions 85GetOptions
86 ("V" => \$opt_V, "version" => \$opt_V, 86 ("V" => \$opt_V, "version" => \$opt_V,
87 "h" => \$opt_h, "help" => \$opt_h, 87 "h" => \$opt_h, "help" => \$opt_h,
88 "v" => \$verbose, "verbose" => \$verbose, 88 "v" => \$verbose, "verbose" => \$verbose,
89 "4" => \$ipv4, "use-ipv4" => \$ipv4,
90 "6" => \$ipv6, "use-ipv6" => \$ipv6,
89 "w=f" => \$opt_w, "warning=f" => \$opt_w, # offset|adjust warning if above this number 91 "w=f" => \$opt_w, "warning=f" => \$opt_w, # offset|adjust warning if above this number
90 "c=f" => \$opt_c, "critical=f" => \$opt_c, # offset|adjust critical if above this number 92 "c=f" => \$opt_c, "critical=f" => \$opt_c, # offset|adjust critical if above this number
91 "j=s" => \$opt_j, "jwarn=i" => \$opt_j, # jitter warning if above this number 93 "j=s" => \$opt_j, "jwarn=i" => \$opt_j, # jitter warning if above this number
@@ -177,6 +179,18 @@ $SIG{'ALRM'} = sub {
177}; 179};
178alarm($timeout); 180alarm($timeout);
179 181
182# Determine protocol to be used for ntpdate and ntpq
183my $ntpdate = $utils::PATH_TO_NTPDATE;
184my $ntpq = $utils::PATH_TO_NTPQ;
185if ($ipv4) {
186 $ntpdate .= " -4";
187 $ntpq .= " -4";
188}
189elsif ($ipv6) {
190 $ntpdate .= " -6";
191 $ntpq .= " -6";
192}
193# else don't use any flags
180 194
181### 195###
182### 196###
@@ -184,7 +198,7 @@ alarm($timeout);
184### 198###
185### 199###
186 200
187if (!open (NTPDATE, "$utils::PATH_TO_NTPDATE -q $host 2>&1 |")) { 201if (!open (NTPDATE, $ntpdate . " -q $host 2>&1 |")) {
188 print "Could not open ntpdate\n"; 202 print "Could not open ntpdate\n";
189 exit $ERRORS{"UNKNOWN"}; 203 exit $ERRORS{"UNKNOWN"};
190} 204}
@@ -259,7 +273,7 @@ if ( $? && !$ignoreret ) {
259 273
260if ($have_ntpq) { 274if ($have_ntpq) {
261 275
262 if ( open(NTPQ,"$utils::PATH_TO_NTPQ -np $host 2>&1 |") ) { 276 if ( open(NTPQ, $ntpq . " -np $host 2>&1 |") ) {
263 while (<NTPQ>) { 277 while (<NTPQ>) {
264 print $_ if ($verbose); 278 print $_ if ($verbose);
265 if ( /timed out/ ){ 279 if ( /timed out/ ){
@@ -409,7 +423,7 @@ exit $state;
409#### subs 423#### subs
410 424
411sub print_usage () { 425sub print_usage () {
412 print "Usage: $PROGNAME -H <host> [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n"; 426 print "Usage: $PROGNAME -H <host> [-46] [-w <warn>] [-c <crit>] [-j <warn>] [-k <crit>] [-v verbose]\n";
413} 427}
414 428
415sub print_help () { 429sub print_help () {
@@ -427,10 +441,14 @@ Checks the jitter/dispersion of clock signal between <host> and its sys.peer wit
427-j (--jwarn) 441-j (--jwarn)
428 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_WARN. 442 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_WARN.
429-k (--jcrit) 443-k (--jcrit)
430 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_CRIT.\n 444 Clock jitter in milliseconds at which a warning message will be generated.\n Defaults to $DEFAULT_JITTER_CRIT.
431 445
432 If jitter/dispersion is specified with -j or -k and ntpq times out, then a 446 If jitter/dispersion is specified with -j or -k and ntpq times out, then a
433 warning is returned. 447 warning is returned.\n
434"; 448-4 (--use-ipv4)
449 Use IPv4 connection
450-6 (--use-ipv6)
451 Use IPv6 connection
452\n";
435support(); 453support();
436} 454}