diff options
Diffstat (limited to 'plugins-scripts/check_ntp.pl')
-rwxr-xr-x | plugins-scripts/check_ntp.pl | 30 |
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; | |||
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_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); |
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 | ||
@@ -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 | ||
95 | if ($opt_V) { | 96 | if ($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); | 119 | my ($timeout, $owarn, $ocrit, $jwarn, $jcrit); |
119 | my $owarn = $1 if ($opt_w =~ /([0-9.]+)/); | ||
120 | 120 | ||
121 | ($opt_c) || ($opt_c = $DEFAULT_OFFSET_CRIT); | 121 | $timeout = $TIMEOUT; |
122 | my $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; |
125 | my $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; |
128 | my $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 | ||
130 | if ($ocrit < $owarn ) { | 136 | if ($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 | }; |
168 | alarm($TIMEOUT); | 174 | alarm($timeout); |
169 | 175 | ||
170 | 176 | ||
171 | ### | 177 | ### |