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){ TVtoNTP64(t,p->txts); } +double offset_request(const char *host){ + int i=0, conn=-1; + ntp_message req; + double next_offset=0., avg_offset=0.; + struct timeval recv_time; + + for(i=0; i<4; i++){ + setup_request(&req); + my_udp_connect(server_address, 123, &conn); + write(conn, &req, sizeof(ntp_message)); + read(conn, &req, sizeof(ntp_message)); + gettimeofday(&recv_time, NULL); + /* if(verbose) print_packet(&req); */ + close(conn); + next_offset=calc_offset(&req, &recv_time); + if(verbose) printf("offset: %g\n", next_offset); + avg_offset+=next_offset; + } + return avg_offset/4.; +} + +/* not yet implemented yet */ +double jitter_request(const char *host){ + return 0.; +} + int process_arguments(int argc, char **argv){ int c; int option=0; @@ -282,9 +308,6 @@ int process_arguments(int argc, char **argv){ int main(int argc, char *argv[]){ int result = STATE_UNKNOWN; - int conn; - ntp_message m; - struct timeval recv_time; double offset=0, jitter=0; if (process_arguments (argc, argv) == ERROR) @@ -296,18 +319,7 @@ int main(int argc, char *argv[]){ /* set socket timeout */ alarm (socket_timeout); - setup_request(&m); - if(verbose) print_packet(&m); - my_udp_connect(server_address, 123, &conn); - write(conn, &m, sizeof(ntp_message)); - read(conn, &m, sizeof(ntp_message)); - gettimeofday(&recv_time, NULL); - if(verbose) print_packet(&m); - close(conn); - - offset=calc_offset(&m, &recv_time); - printf("total offset: %g\n", offset); - + offset = offset_request(server_address); if(offset > ocrit){ printf("NTP CRITICAL: "); result = STATE_CRITICAL; @@ -319,14 +331,15 @@ int main(int argc, char *argv[]){ result = STATE_OK; } - /* not implemented yet: - jitter=calc_jitter(&m, &recv_time); + /* not implemented yet: */ + jitter=jitter_request(server_address); + /* not implemented yet: if(do_jitter){ - if(offset > ocrit){ + if(jitter > jcrit){ printf("NTP CRITICAL: "); result = STATE_CRITICAL; - } else if(offset > owarn) { + } else if(jitter > jwarn) { printf("NTP WARNING: "); result = STATE_WARNING; } else { |