diff options
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-x | plugins-scripts/check_ntp.pl | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl index 7adef98..cd02d47 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; | |||
61 | use POSIX; | 61 | use POSIX; |
62 | use strict; | 62 | use strict; |
63 | use Getopt::Long; | 63 | use Getopt::Long; |
64 | use vars qw($opt_V $opt_h $opt_H $opt_t $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME $def_jitter); | 64 | use vars qw($opt_V $opt_h $opt_H $opt_t $opt_w $opt_c $opt_j $opt_k $verbose $PROGNAME $def_jitter $ipv4 $ipv6); |
65 | use lib utils.pm; | 65 | use lib utils.pm; |
66 | use utils qw($TIMEOUT %ERRORS &print_revision &support); | 66 | use 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'); | |||
85 | GetOptions | 85 | GetOptions |
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 | }; |
178 | alarm($timeout); | 180 | alarm($timeout); |
179 | 181 | ||
182 | # Determine protocol to be used for ntpdate and ntpq | ||
183 | my $ntpdate = $utils::PATH_TO_NTPDATE; | ||
184 | my $ntpq = $utils::PATH_TO_NTPQ; | ||
185 | if ($ipv4) { | ||
186 | $ntpdate .= " -4"; | ||
187 | $ntpq .= " -4"; | ||
188 | } | ||
189 | elsif ($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 | ||
187 | if (!open (NTPDATE, "$utils::PATH_TO_NTPDATE -q $host 2>&1 |")) { | 201 | if (!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 | ||
260 | if ($have_ntpq) { | 274 | if ($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 | ||
411 | sub print_usage () { | 425 | sub 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 | ||
415 | sub print_help () { | 429 | sub 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"; | ||
435 | support(); | 453 | support(); |
436 | } | 454 | } |