summaryrefslogtreecommitdiffstats
path: root/plugins-scripts/check_ntp.pl
diff options
context:
space:
mode:
Diffstat (limited to 'plugins-scripts/check_ntp.pl')
-rwxr-xr-xplugins-scripts/check_ntp.pl30
1 files changed, 18 insertions, 12 deletions
diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl
index 269ed3ba..a2e75b15 100755
--- a/plugins-scripts/check_ntp.pl
+++ b/plugins-scripts/check_ntp.pl
@@ -61,7 +61,7 @@ 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_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);
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
@@ -88,8 +88,9 @@ GetOptions
88 "v" => \$verbose, "verbose" => \$verbose, 88 "v" => \$verbose, "verbose" => \$verbose,
89 "w=f" => \$opt_w, "warning=f" => \$opt_w, # offset|adjust warning if above this number 89 "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 90 "c=f" => \$opt_c, "critical=f" => \$opt_c, # offset|adjust critical if above this number
91 "j=s" => \$opt_j, "jwarn=s" => \$opt_j, # jitter warning if above this number 91 "j=s" => \$opt_j, "jwarn=i" => \$opt_j, # jitter warning if above this number
92 "k=s" => \$opt_k, "jcrit=s" => \$opt_k, # jitter critical if above this number 92 "k=s" => \$opt_k, "jcrit=i" => \$opt_k, # jitter critical if above this number
93 "t=s" => \$opt_t, "timeout=i" => \$opt_t,
93 "H=s" => \$opt_H, "hostname=s" => \$opt_H); 94 "H=s" => \$opt_H, "hostname=s" => \$opt_H);
94 95
95if ($opt_V) { 96if ($opt_V) {
@@ -115,17 +116,22 @@ unless ($host) {
115 exit $ERRORS{'UNKNOWN'}; 116 exit $ERRORS{'UNKNOWN'};
116} 117}
117 118
118($opt_w) || ($opt_w = $DEFAULT_OFFSET_WARN); 119my ($timeout, $owarn, $ocrit, $jwarn, $jcrit);
119my $owarn = $1 if ($opt_w =~ /([0-9.]+)/);
120 120
121($opt_c) || ($opt_c = $DEFAULT_OFFSET_CRIT); 121$timeout = $TIMEOUT;
122my $ocrit = $1 if ($opt_c =~ /([0-9.]+)/); 122($opt_t) && ($opt_t =~ /^([0-9]+)$/) && ($timeout = $1);
123 123
124($opt_j) || ($opt_j = $DEFAULT_JITTER_WARN); 124$owarn = $DEFAULT_OFFSET_WARN;
125my $jwarn = $1 if ($opt_j =~ /([0-9]+)/); 125($opt_w) && ($opt_w =~ /^([0-9.]+)$/) && ($owarn = $1);
126 126
127($opt_k) || ($opt_k = $DEFAULT_JITTER_CRIT); 127$ocrit = $DEFAULT_OFFSET_CRIT;
128my $jcrit = $1 if ($opt_k =~ /([0-9]+)/); 128($opt_c) && ($opt_c =~ /^([0-9.]+)$/) && ($ocrit = $1);
129
130$jwarn = $DEFAULT_JITTER_WARN;
131($opt_j) && ($opt_j =~ /^([0-9]+)$/) && ($jwarn = $1);
132
133$jcrit = $DEFAULT_JITTER_CRIT;
134($opt_k) && ($opt_k =~ /^([0-9]+)$/) && ($jcrit = $1);
129 135
130if ($ocrit < $owarn ) { 136if ($ocrit < $owarn ) {
131 print "Critical offset should be larger than warning offset\n"; 137 print "Critical offset should be larger than warning offset\n";
@@ -165,7 +171,7 @@ $SIG{'ALRM'} = sub {
165 print ("ERROR: No response from ntp server (alarm)\n"); 171 print ("ERROR: No response from ntp server (alarm)\n");
166 exit $ERRORS{"UNKNOWN"}; 172 exit $ERRORS{"UNKNOWN"};
167}; 173};
168alarm($TIMEOUT); 174alarm($timeout);
169 175
170 176
171### 177###