diff options
author | M. Sean Finney <seanius@users.sourceforge.net> | 2006-03-20 22:06:07 +0000 |
---|---|---|
committer | M. Sean Finney <seanius@users.sourceforge.net> | 2006-03-20 22:06:07 +0000 |
commit | 8250d650614c6e312f744b8dd503919e1b37bae8 (patch) | |
tree | d456ccdc4ed051cf2b2dc3c54f8049ac11334465 | |
parent | 8a9e443b4c653e30f46f20e4e52a656cbf0b531d (diff) | |
download | monitoring-plugins-8250d650614c6e312f744b8dd503919e1b37bae8.tar.gz |
- shuffling some code around to keep things tidy.
- now average the result of 4 queries just as ntpdate does
- put things in place for jitter calculation
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1332 f882894a-f735-0410-b71e-b25c423dba1c
-rw-r--r-- | plugins/check_ntp.c | 51 |
1 files changed, 32 insertions, 19 deletions
diff --git a/plugins/check_ntp.c b/plugins/check_ntp.c index 56e5a05d..5037786a 100644 --- a/plugins/check_ntp.c +++ b/plugins/check_ntp.c | |||
@@ -183,6 +183,32 @@ void setup_request(ntp_message *p){ | |||
183 | TVtoNTP64(t,p->txts); | 183 | TVtoNTP64(t,p->txts); |
184 | } | 184 | } |
185 | 185 | ||
186 | double offset_request(const char *host){ | ||
187 | int i=0, conn=-1; | ||
188 | ntp_message req; | ||
189 | double next_offset=0., avg_offset=0.; | ||
190 | struct timeval recv_time; | ||
191 | |||
192 | for(i=0; i<4; i++){ | ||
193 | setup_request(&req); | ||
194 | my_udp_connect(server_address, 123, &conn); | ||
195 | write(conn, &req, sizeof(ntp_message)); | ||
196 | read(conn, &req, sizeof(ntp_message)); | ||
197 | gettimeofday(&recv_time, NULL); | ||
198 | /* if(verbose) print_packet(&req); */ | ||
199 | close(conn); | ||
200 | next_offset=calc_offset(&req, &recv_time); | ||
201 | if(verbose) printf("offset: %g\n", next_offset); | ||
202 | avg_offset+=next_offset; | ||
203 | } | ||
204 | return avg_offset/4.; | ||
205 | } | ||
206 | |||
207 | /* not yet implemented yet */ | ||
208 | double jitter_request(const char *host){ | ||
209 | return 0.; | ||
210 | } | ||
211 | |||
186 | int process_arguments(int argc, char **argv){ | 212 | int process_arguments(int argc, char **argv){ |
187 | int c; | 213 | int c; |
188 | int option=0; | 214 | int option=0; |
@@ -282,9 +308,6 @@ int process_arguments(int argc, char **argv){ | |||
282 | 308 | ||
283 | int main(int argc, char *argv[]){ | 309 | int main(int argc, char *argv[]){ |
284 | int result = STATE_UNKNOWN; | 310 | int result = STATE_UNKNOWN; |
285 | int conn; | ||
286 | ntp_message m; | ||
287 | struct timeval recv_time; | ||
288 | double offset=0, jitter=0; | 311 | double offset=0, jitter=0; |
289 | 312 | ||
290 | if (process_arguments (argc, argv) == ERROR) | 313 | if (process_arguments (argc, argv) == ERROR) |
@@ -296,18 +319,7 @@ int main(int argc, char *argv[]){ | |||
296 | /* set socket timeout */ | 319 | /* set socket timeout */ |
297 | alarm (socket_timeout); | 320 | alarm (socket_timeout); |
298 | 321 | ||
299 | setup_request(&m); | 322 | offset = offset_request(server_address); |
300 | if(verbose) print_packet(&m); | ||
301 | my_udp_connect(server_address, 123, &conn); | ||
302 | write(conn, &m, sizeof(ntp_message)); | ||
303 | read(conn, &m, sizeof(ntp_message)); | ||
304 | gettimeofday(&recv_time, NULL); | ||
305 | if(verbose) print_packet(&m); | ||
306 | close(conn); | ||
307 | |||
308 | offset=calc_offset(&m, &recv_time); | ||
309 | printf("total offset: %g\n", offset); | ||
310 | |||
311 | if(offset > ocrit){ | 323 | if(offset > ocrit){ |
312 | printf("NTP CRITICAL: "); | 324 | printf("NTP CRITICAL: "); |
313 | result = STATE_CRITICAL; | 325 | result = STATE_CRITICAL; |
@@ -319,14 +331,15 @@ int main(int argc, char *argv[]){ | |||
319 | result = STATE_OK; | 331 | result = STATE_OK; |
320 | } | 332 | } |
321 | 333 | ||
322 | /* not implemented yet: | 334 | /* not implemented yet: */ |
323 | jitter=calc_jitter(&m, &recv_time); | 335 | jitter=jitter_request(server_address); |
324 | 336 | ||
337 | /* not implemented yet: | ||
325 | if(do_jitter){ | 338 | if(do_jitter){ |
326 | if(offset > ocrit){ | 339 | if(jitter > jcrit){ |
327 | printf("NTP CRITICAL: "); | 340 | printf("NTP CRITICAL: "); |
328 | result = STATE_CRITICAL; | 341 | result = STATE_CRITICAL; |
329 | } else if(offset > owarn) { | 342 | } else if(jitter > jwarn) { |
330 | printf("NTP WARNING: "); | 343 | printf("NTP WARNING: "); |
331 | result = STATE_WARNING; | 344 | result = STATE_WARNING; |
332 | } else { | 345 | } else { |