diff options
author | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-05-27 01:56:22 (GMT) |
---|---|---|
committer | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-05-27 01:56:22 (GMT) |
commit | 2a8d67446fe41224c9551327a90a43eef2d35fe9 (patch) | |
tree | 57a113c2286feee375225c24d0552e60a85b8005 /plugins-scripts | |
parent | 12503c81fafff406a4f5874255b0d5e79af8951f (diff) | |
download | monitoring-plugins-2a8d67446fe41224c9551327a90a43eef2d35fe9.tar.gz |
logic reorg, ePN fix and support for utils.pm
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@35 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-scripts')
-rwxr-xr-x | plugins-scripts/check_ntp.pl | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/plugins-scripts/check_ntp.pl b/plugins-scripts/check_ntp.pl index 9a58d78..ddaa394 100755 --- a/plugins-scripts/check_ntp.pl +++ b/plugins-scripts/check_ntp.pl | |||
@@ -1,4 +1,4 @@ | |||
1 | #! /usr/bin/perl -wT | 1 | #! /usr/bin/perl -w |
2 | 2 | ||
3 | # (c)1999 Ian Cass, Knowledge Matters Ltd. | 3 | # (c)1999 Ian Cass, Knowledge Matters Ltd. |
4 | # Read the GNU copyright stuff for all the legalese | 4 | # Read the GNU copyright stuff for all the legalese |
@@ -47,7 +47,10 @@ | |||
47 | # source. This happens while starting up and if contact | 47 | # source. This happens while starting up and if contact |
48 | # with master has been lost. | 48 | # with master has been lost. |
49 | # | 49 | # |
50 | # Modifed to run under Embedded Perl | 50 | # Modifed to run under Embedded Perl (sghosh@users.sf.net) |
51 | # - combined logic some blocks together.. | ||
52 | # | ||
53 | # Todo - non-hardcoded dispersion values... | ||
51 | # | 54 | # |
52 | 55 | ||
53 | 56 | ||
@@ -73,8 +76,8 @@ GetOptions | |||
73 | ("V" => \$opt_V, "version" => \$opt_V, | 76 | ("V" => \$opt_V, "version" => \$opt_V, |
74 | "h" => \$opt_h, "help" => \$opt_h, | 77 | "h" => \$opt_h, "help" => \$opt_h, |
75 | "v" => \$verbose, "verbose" => \$verbose, | 78 | "v" => \$verbose, "verbose" => \$verbose, |
76 | "w=s" => \$opt_w, "warning=s" => \$opt_w, | 79 | "w=s" => \$opt_w, "warning=s" => \$opt_w, # offset|adjust warning if above this number |
77 | "c=s" => \$opt_c, "critical=s" => \$opt_c, | 80 | "c=s" => \$opt_c, "critical=s" => \$opt_c, # offset|adjust critical if above this number |
78 | "H=s" => \$opt_H, "hostname=s" => \$opt_H); | 81 | "H=s" => \$opt_H, "hostname=s" => \$opt_H); |
79 | 82 | ||
80 | if ($opt_V) { | 83 | if ($opt_V) { |
@@ -90,6 +93,7 @@ if ($opt_h) { | |||
90 | $opt_H = shift unless ($opt_H); | 93 | $opt_H = shift unless ($opt_H); |
91 | my $host = $1 if ($opt_H && $opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/); | 94 | my $host = $1 if ($opt_H && $opt_H =~ m/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+|[a-zA-Z][-a-zA-Z0-9]+(\.[a-zA-Z][-a-zA-Z0-9]+)*)$/); |
92 | unless ($host) { | 95 | unless ($host) { |
96 | print "No target host specified\n"; | ||
93 | print_usage(); | 97 | print_usage(); |
94 | exit $ERRORS{'UNKNOWN'}; | 98 | exit $ERRORS{'UNKNOWN'}; |
95 | } | 99 | } |
@@ -100,6 +104,12 @@ my $warning = $1 if ($opt_w =~ /([0-9]+)/); | |||
100 | ($opt_c) || ($opt_c = shift) || ($opt_c = 120); | 104 | ($opt_c) || ($opt_c = shift) || ($opt_c = 120); |
101 | my $critical = $1 if ($opt_c =~ /([0-9]+)/); | 105 | my $critical = $1 if ($opt_c =~ /([0-9]+)/); |
102 | 106 | ||
107 | if ($opt_c < $opt_w) { | ||
108 | print "Critical offset should be larger than warning offset\n"; | ||
109 | print_usage(); | ||
110 | exit $ERRORS{"UNKNOWN"}; | ||
111 | } | ||
112 | |||
103 | my $answer = undef; | 113 | my $answer = undef; |
104 | my $offset = undef; | 114 | my $offset = undef; |
105 | my $msg; # first line of output to print if format is invalid | 115 | my $msg; # first line of output to print if format is invalid |
@@ -115,16 +125,16 @@ $SIG{'ALRM'} = sub { | |||
115 | print ("ERROR: No response from ntp server (alarm)\n"); | 125 | print ("ERROR: No response from ntp server (alarm)\n"); |
116 | exit $ERRORS{"UNKNOWN"}; | 126 | exit $ERRORS{"UNKNOWN"}; |
117 | }; | 127 | }; |
118 | alarm($TIMEOUT); | 128 | #alarm($TIMEOUT); |
119 | 129 | ||
120 | 130 | ||
121 | ### | 131 | ### |
122 | ### | 132 | ###$dispersion_error = $ERRORS{' |
123 | ### First, check ntpdate | 133 | ### First, check ntpdate |
124 | ### | 134 | ### |
125 | ### | 135 | ### |
126 | 136 | ||
127 | if (!open (NTPDATE, "/usr/local/sbin/ntpdate -q $host 2>&1 |")) { | 137 | if (!open (NTPDATE, "$utils::PATH_TO_NTPDATE -q $host 2>&1 |")) { |
128 | print "Could not open ntpdate\n"; | 138 | print "Could not open ntpdate\n"; |
129 | exit $ERRORS{"UNKNOWN"}; | 139 | exit $ERRORS{"UNKNOWN"}; |
130 | } | 140 | } |
@@ -134,50 +144,60 @@ while (<NTPDATE>) { | |||
134 | $msg = $_ unless ($msg); | 144 | $msg = $_ unless ($msg); |
135 | if (/(offset|adjust)\s+([-.\d]+)/i) { | 145 | if (/(offset|adjust)\s+([-.\d]+)/i) { |
136 | $offset = $2; | 146 | $offset = $2; |
137 | last; | 147 | |
148 | # An offset of 0.000000 with an error is probably bogus. Actually, | ||
149 | # it's probably always bogus, but let's be paranoid here. | ||
150 | if ($offset == 0) { undef $offset;} | ||
151 | |||
152 | $ntpdate_error = defined ($offset) ? $ERRORS{"OK"} : $ERRORS{"CRITICAL"}; | ||
153 | print "ntperr = $ntpdate_error \n" if $verbose; | ||
154 | |||
138 | } | 155 | } |
139 | } | ||
140 | 156 | ||
141 | # soak up remaining output; check for error | ||
142 | while (<NTPDATE>) { | ||
143 | if (/no server suitable for synchronization found/) { | 157 | if (/no server suitable for synchronization found/) { |
144 | $ntpdate_error = $ERRORS{"CRITICAL"}; | 158 | $ntpdate_error = $ERRORS{"CRITICAL"}; |
159 | $msg = "No suitable peer server found - "; | ||
145 | } | 160 | } |
146 | } | ||
147 | 161 | ||
148 | close(NTPDATE); | 162 | } |
149 | 163 | ||
150 | # only declare an error if we also get a non-zero return code from ntpdate | 164 | close (NTPDATE); |
151 | $ntpdate_error = ($? >> 8) || $ntpdate_error; | 165 | # declare an error if we also get a non-zero return code from ntpdate |
166 | # unless already set to critical | ||
167 | if ( $? ) { | ||
168 | print "stderr = $? : $! \n" if $verbose; | ||
169 | $ntpdate_error = $ntpdate_error == $ERRORS{"CRITICAL"} ? $ERRORS{"CRITICAL"} : $ERRORS{"UNKNOWN"} ; | ||
170 | print "ntperr = $ntpdate_error : $!\n" if $verbose; | ||
171 | } | ||
152 | 172 | ||
153 | ### | 173 | ### |
154 | ### | 174 | ### |
155 | ### Then scan xntpdc if it exists | 175 | ### Then scan xntpdc/ntpdc if it exists |
156 | ### | 176 | ### and look in the 8th column for dispersion (ntpd v4) or jitter (ntpd v3) |
157 | ### | 177 | ### |
158 | 178 | ||
159 | if (#open(NTPDC,"/usr/sbin/ntpdc -c $host 2>&1 |") || | 179 | if ( open(NTPDC,"$utils::PATH_TO_NTPDC -s $host 2>&1 |") ) { |
160 | open(NTPDC,"/usr/sbin/xntpdc -c $host 2>&1 |") ) { | ||
161 | while (<NTPDC>) { | 180 | while (<NTPDC>) { |
162 | print if ($verbose); | 181 | print $_ if ($verbose); |
163 | if (/([^\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)/) { | 182 | if (/([^\s]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)\s+([-0-9.]+)/) { |
164 | if ($8>15) { | 183 | if ($8>15) { |
184 | print "Dispersion = $8 \n" if ($verbose); | ||
165 | $dispersion_error = $ERRORS{'CRITICAL'}; | 185 | $dispersion_error = $ERRORS{'CRITICAL'}; |
166 | } elsif ($8>5 && $dispersion_error<$ERRORS{'CRITICAL'}) { | 186 | } elsif ($8>5 && $dispersion_error<$ERRORS{'CRITICAL'}) { |
187 | print "Dispersion = $8 \n" if ($verbose); | ||
167 | $dispersion_error = $ERRORS{'WARNING'}; | 188 | $dispersion_error = $ERRORS{'WARNING'}; |
189 | } else { | ||
190 | $dispersion_error = $ERRORS{'OK'}; | ||
168 | } | 191 | } |
169 | } | 192 | } |
170 | } | 193 | } |
171 | close NTPDC; | 194 | close NTPDC; |
172 | } | 195 | } |
173 | 196 | ||
174 | # An offset of 0.000000 with an error is probably bogus. Actually, | ||
175 | # it's probably always bogus, but let's be paranoid here. | ||
176 | if ($ntpdate_error && $offset && ($offset == 0)) { undef $offset;} | ||
177 | 197 | ||
178 | if ($ntpdate_error > $ERRORS{'OK'}) { | 198 | if ($ntpdate_error != $ERRORS{'OK'}) { |
179 | $state = $ntpdate_error; | 199 | $state = $ntpdate_error; |
180 | $answer = "Server for ntp probably down\n"; | 200 | $answer = $msg . "Server for ntp probably down\n"; |
181 | if (defined($offset) && abs($offset) > $critical) { | 201 | if (defined($offset) && abs($offset) > $critical) { |
182 | $state = $ERRORS{'CRITICAL'}; | 202 | $state = $ERRORS{'CRITICAL'}; |
183 | $answer = "Server Error and time difference $offset seconds greater than +/- $critical sec\n"; | 203 | $answer = "Server Error and time difference $offset seconds greater than +/- $critical sec\n"; |
@@ -185,7 +205,7 @@ if ($ntpdate_error > $ERRORS{'OK'}) { | |||
185 | $answer = "Server error and time difference $offset seconds greater than +/- $warning sec\n"; | 205 | $answer = "Server error and time difference $offset seconds greater than +/- $warning sec\n"; |
186 | } | 206 | } |
187 | 207 | ||
188 | } elsif ($dispersion_error > $ERRORS{'OK'}) { | 208 | } elsif ($dispersion_error != $ERRORS{'OK'}) { |
189 | $state = $dispersion_error; | 209 | $state = $dispersion_error; |
190 | $answer = "Dispersion too high\n"; | 210 | $answer = "Dispersion too high\n"; |
191 | if (defined($offset) && abs($offset) > $critical) { | 211 | if (defined($offset) && abs($offset) > $critical) { |