[Nagiosplug-checkins] nagiosplug/plugins check_ntp.c,1.2,1.3
M. Sean Finney
seanius at users.sourceforge.net
Mon Mar 20 14:07:00 CET 2006
Update of /cvsroot/nagiosplug/nagiosplug/plugins
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19758
Modified Files:
check_ntp.c
Log Message:
- 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
Index: check_ntp.c
===================================================================
RCS file: /cvsroot/nagiosplug/nagiosplug/plugins/check_ntp.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- check_ntp.c 20 Mar 2006 17:18:44 -0000 1.2
+++ check_ntp.c 20 Mar 2006 22:06:07 -0000 1.3
@@ -183,6 +183,32 @@
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 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 @@
/* 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 @@
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 {
More information about the Commits
mailing list