Code

Fix bugs and flaws in best offset server selection of check_ntp_time and (deprecated...
[nagiosplug.git] / plugins / check_ntp_time.c
1 /******************************************************************************
2 *
3 * Nagios check_ntp_time plugin
4 *
5 * License: GPL
6 * Copyright (c) 2006 sean finney <seanius@seanius.net>
7 * Copyright (c) 2007 nagios-plugins team
8 *
9 * Last Modified: $Date$
10 *
11 * Description:
12 *
13 * This file contains the check_ntp_time plugin
14 *
15 *  This plugin checks the clock offset between the local host and a
16 *  remote NTP server. It is independent of any commandline programs or
17 *  external libraries.
18 *
19 *  If you'd rather want to monitor an NTP server, please use
20 *  check_ntp_peer.
21 *
22 *
23 * License Information:
24 *
25 * This program is free software; you can redistribute it and/or modify
26 * it under the terms of the GNU General Public License as published by
27 * the Free Software Foundation; either version 2 of the License, or
28 * (at your option) any later version.
29 *
30 * This program is distributed in the hope that it will be useful,
31 * but WITHOUT ANY WARRANTY; without even the implied warranty of
32 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33 * GNU General Public License for more details.
34 *
35 * You should have received a copy of the GNU General Public License
36 * along with this program; if not, write to the Free Software
37 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
39  $Id$
40  
41 *****************************************************************************/
43 const char *progname = "check_ntp_time";
44 const char *revision = "$Revision$";
45 const char *copyright = "2007";
46 const char *email = "nagiosplug-devel@lists.sourceforge.net";
48 #include "common.h"
49 #include "netutils.h"
50 #include "utils.h"
52 static char *server_address=NULL;
53 static int verbose=0;
54 static int quiet=0;
55 static char *owarn="60";
56 static char *ocrit="120";
58 int process_arguments (int, char **);
59 thresholds *offset_thresholds = NULL;
60 void print_help (void);
61 void print_usage (void);
63 /* number of times to perform each request to get a good average. */
64 #define AVG_NUM 4
66 /* max size of control message data */
67 #define MAX_CM_SIZE 468
69 /* this structure holds everything in an ntp request/response as per rfc1305 */
70 typedef struct {
71         uint8_t flags;       /* byte with leapindicator,vers,mode. see macros */
72         uint8_t stratum;     /* clock stratum */
73         int8_t poll;         /* polling interval */
74         int8_t precision;    /* precision of the local clock */
75         int32_t rtdelay;     /* total rt delay, as a fixed point num. see macros */
76         uint32_t rtdisp;     /* like above, but for max err to primary src */
77         uint32_t refid;      /* ref clock identifier */
78         uint64_t refts;      /* reference timestamp.  local time local clock */
79         uint64_t origts;     /* time at which request departed client */
80         uint64_t rxts;       /* time at which request arrived at server */
81         uint64_t txts;       /* time at which request departed server */
82 } ntp_message;
84 /* this structure holds data about results from querying offset from a peer */
85 typedef struct {
86         time_t waiting;         /* ts set when we started waiting for a response */ 
87         int num_responses;      /* number of successfully recieved responses */
88         uint8_t stratum;        /* copied verbatim from the ntp_message */
89         double rtdelay;         /* converted from the ntp_message */
90         double rtdisp;          /* converted from the ntp_message */
91         double offset[AVG_NUM]; /* offsets from each response */
92         uint8_t flags;       /* byte with leapindicator,vers,mode. see macros */
93 } ntp_server_results;
95 /* bits 1,2 are the leap indicator */
96 #define LI_MASK 0xc0
97 #define LI(x) ((x&LI_MASK)>>6)
98 #define LI_SET(x,y) do{ x |= ((y<<6)&LI_MASK); }while(0)
99 /* and these are the values of the leap indicator */
100 #define LI_NOWARNING 0x00
101 #define LI_EXTRASEC 0x01
102 #define LI_MISSINGSEC 0x02
103 #define LI_ALARM 0x03
104 /* bits 3,4,5 are the ntp version */
105 #define VN_MASK 0x38
106 #define VN(x)   ((x&VN_MASK)>>3)
107 #define VN_SET(x,y)     do{ x |= ((y<<3)&VN_MASK); }while(0)
108 #define VN_RESERVED 0x02
109 /* bits 6,7,8 are the ntp mode */
110 #define MODE_MASK 0x07
111 #define MODE(x) (x&MODE_MASK)
112 #define MODE_SET(x,y)   do{ x |= (y&MODE_MASK); }while(0)
113 /* here are some values */
114 #define MODE_CLIENT 0x03
115 #define MODE_CONTROLMSG 0x06
116 /* In control message, bits 8-10 are R,E,M bits */
117 #define REM_MASK 0xe0
118 #define REM_RESP 0x80
119 #define REM_ERROR 0x40
120 #define REM_MORE 0x20
121 /* In control message, bits 11 - 15 are opcode */
122 #define OP_MASK 0x1f
123 #define OP_SET(x,y)   do{ x |= (y&OP_MASK); }while(0)
124 #define OP_READSTAT 0x01
125 #define OP_READVAR  0x02
126 /* In peer status bytes, bits 6,7,8 determine clock selection status */
127 #define PEER_SEL(x) ((ntohs(x)>>8)&0x07)
128 #define PEER_INCLUDED 0x04
129 #define PEER_SYNCSOURCE 0x06
131 /**
132  ** a note about the 32-bit "fixed point" numbers:
133  **
134  they are divided into halves, each being a 16-bit int in network byte order:
135  - the first 16 bits are an int on the left side of a decimal point.
136  - the second 16 bits represent a fraction n/(2^16)
137  likewise for the 64-bit "fixed point" numbers with everything doubled :) 
138  **/
140 /* macros to access the left/right 16 bits of a 32-bit ntp "fixed point"
141    number.  note that these can be used as lvalues too */
142 #define L16(x) (((uint16_t*)&x)[0])
143 #define R16(x) (((uint16_t*)&x)[1])
144 /* macros to access the left/right 32 bits of a 64-bit ntp "fixed point"
145    number.  these too can be used as lvalues */
146 #define L32(x) (((uint32_t*)&x)[0])
147 #define R32(x) (((uint32_t*)&x)[1])
149 /* ntp wants seconds since 1/1/00, epoch is 1/1/70.  this is the difference */
150 #define EPOCHDIFF 0x83aa7e80UL
152 /* extract a 32-bit ntp fixed point number into a double */
153 #define NTP32asDOUBLE(x) (ntohs(L16(x)) + (double)ntohs(R16(x))/65536.0)
155 /* likewise for a 64-bit ntp fp number */
156 #define NTP64asDOUBLE(n) (double)(((uint64_t)n)?\
157                          (ntohl(L32(n))-EPOCHDIFF) + \
158                          (.00000001*(0.5+(double)(ntohl(R32(n))/42.94967296))):\
159                          0)
161 /* convert a struct timeval to a double */
162 #define TVasDOUBLE(x) (double)(x.tv_sec+(0.000001*x.tv_usec))
164 /* convert an ntp 64-bit fp number to a struct timeval */
165 #define NTP64toTV(n,t) \
166         do{ if(!n) t.tv_sec = t.tv_usec = 0; \
167             else { \
168                         t.tv_sec=ntohl(L32(n))-EPOCHDIFF; \
169                         t.tv_usec=(int)(0.5+(double)(ntohl(R32(n))/4294.967296)); \
170                 } \
171         }while(0)
173 /* convert a struct timeval to an ntp 64-bit fp number */
174 #define TVtoNTP64(t,n) \
175         do{ if(!t.tv_usec && !t.tv_sec) n=0x0UL; \
176                 else { \
177                         L32(n)=htonl(t.tv_sec + EPOCHDIFF); \
178                         R32(n)=htonl((uint64_t)((4294.967296*t.tv_usec)+.5)); \
179                 } \
180         } while(0)
182 /* NTP control message header is 12 bytes, plus any data in the data
183  * field, plus null padding to the nearest 32-bit boundary per rfc.
184  */
185 #define SIZEOF_NTPCM(m) (12+ntohs(m.count)+((m.count)?4-(ntohs(m.count)%4):0))
187 /* finally, a little helper or two for debugging: */
188 #define DBG(x) do{if(verbose>1){ x; }}while(0);
189 #define PRINTSOCKADDR(x) \
190         do{ \
191                 printf("%u.%u.%u.%u", (x>>24)&0xff, (x>>16)&0xff, (x>>8)&0xff, x&0xff);\
192         }while(0);
194 /* calculate the offset of the local clock */
195 static inline double calc_offset(const ntp_message *m, const struct timeval *t){
196         double client_tx, peer_rx, peer_tx, client_rx;
197         client_tx = NTP64asDOUBLE(m->origts);
198         peer_rx = NTP64asDOUBLE(m->rxts);
199         peer_tx = NTP64asDOUBLE(m->txts);
200         client_rx=TVasDOUBLE((*t));
201         return (.5*((peer_tx-client_rx)+(peer_rx-client_tx)));
204 /* print out a ntp packet in human readable/debuggable format */
205 void print_ntp_message(const ntp_message *p){
206         struct timeval ref, orig, rx, tx;
208         NTP64toTV(p->refts,ref);
209         NTP64toTV(p->origts,orig);
210         NTP64toTV(p->rxts,rx);
211         NTP64toTV(p->txts,tx);
213         printf("packet contents:\n");
214         printf("\tflags: 0x%.2x\n", p->flags);
215         printf("\t  li=%d (0x%.2x)\n", LI(p->flags), p->flags&LI_MASK);
216         printf("\t  vn=%d (0x%.2x)\n", VN(p->flags), p->flags&VN_MASK);
217         printf("\t  mode=%d (0x%.2x)\n", MODE(p->flags), p->flags&MODE_MASK);
218         printf("\tstratum = %d\n", p->stratum);
219         printf("\tpoll = %g\n", pow(2, p->poll));
220         printf("\tprecision = %g\n", pow(2, p->precision));
221         printf("\trtdelay = %-.16g\n", NTP32asDOUBLE(p->rtdelay));
222         printf("\trtdisp = %-.16g\n", NTP32asDOUBLE(p->rtdisp));
223         printf("\trefid = %x\n", p->refid);
224         printf("\trefts = %-.16g\n", NTP64asDOUBLE(p->refts));
225         printf("\torigts = %-.16g\n", NTP64asDOUBLE(p->origts));
226         printf("\trxts = %-.16g\n", NTP64asDOUBLE(p->rxts));
227         printf("\ttxts = %-.16g\n", NTP64asDOUBLE(p->txts));
230 void setup_request(ntp_message *p){
231         struct timeval t;
233         memset(p, 0, sizeof(ntp_message));
234         LI_SET(p->flags, LI_ALARM);
235         VN_SET(p->flags, 4);
236         MODE_SET(p->flags, MODE_CLIENT);
237         p->poll=4;
238         p->precision=(int8_t)0xfa;
239         L16(p->rtdelay)=htons(1);
240         L16(p->rtdisp)=htons(1);
242         gettimeofday(&t, NULL);
243         TVtoNTP64(t,p->txts);
246 /* select the "best" server from a list of servers, and return its index.
247  * this is done by filtering servers based on stratum, dispersion, and
248  * finally round-trip delay. */
249 int best_offset_server(const ntp_server_results *slist, int nservers){
250         int i=0, cserver=0, best_server=-1;
252         /* for each server */
253         for(cserver=0; cserver<nservers; cserver++){
254                 /* We don't want any servers that fails these tests */
255                 /* Sort out servers that didn't respond or responede with a 0 stratum;
256                  * stratum 0 is for reference clocks so no NTP server should ever report
257                  * a stratum 0 */
258                 if ( slist[cserver].stratum == 0){
259                         if (verbose) printf("discarding peer %d: stratum=%d\n", cserver, slist[cserver].stratum);
260                         continue;
261                 }
262                 /* Sort out servers with error flags */
263                 if ( LI(slist[cserver].flags) == LI_ALARM ){
264                         if (verbose) printf("discarding peer %d: flags=%d\n", cserver, LI(slist[cserver].flags));
265                         continue;
266                 }
268                 /* If we don't have a server yet, use the first one */
269                 if (best_server == -1) {
270                         best_server = cserver;
271                         DBG(printf("using peer %d as our first candidate\n", best_server));
272                         continue;
273                 }
275                 /* compare the server to the best one we've seen so far */
276                 /* does it have an equal or better stratum? */
277                 DBG(printf("comparing peer %d with peer %d\n", cserver, best_server));
278                 if(slist[cserver].stratum <= slist[best_server].stratum){
279                         DBG(printf("stratum for peer %d <= peer %d\n", cserver, best_server));
280                         /* does it have an equal or better dispersion? */
281                         if(slist[cserver].rtdisp <= slist[best_server].rtdisp){
282                                 DBG(printf("dispersion for peer %d <= peer %d\n", cserver, best_server));
283                                 /* does it have a better rtdelay? */
284                                 if(slist[cserver].rtdelay < slist[best_server].rtdelay){
285                                         DBG(printf("rtdelay for peer %d < peer %d\n", cserver, best_server));
286                                         best_server = cserver;
287                                         DBG(printf("peer %d is now our best candidate\n", best_server));
288                                 }
289                         }
290                 }
291         }
293         if(best_server >= 0) {
294                 DBG(printf("best server selected: peer %d\n", best_server));
295                 return best_server;
296         } else {
297                 DBG(printf("no peers meeting synchronization criteria :(\n"));
298                 return -1;
299         }
302 /* do everything we need to get the total average offset
303  * - we use a certain amount of parallelization with poll() to ensure
304  *   we don't waste time sitting around waiting for single packets. 
305  * - we also "manually" handle resolving host names and connecting, because
306  *   we have to do it in a way that our lazy macros don't handle currently :( */
307 double offset_request(const char *host, int *status){
308         int i=0, j=0, ga_result=0, num_hosts=0, *socklist=NULL, respnum=0;
309         int servers_completed=0, one_written=0, one_read=0, servers_readable=0, best_index=-1;
310         time_t now_time=0, start_ts=0;
311         ntp_message *req=NULL;
312         double avg_offset=0.;
313         struct timeval recv_time;
314         struct addrinfo *ai=NULL, *ai_tmp=NULL, hints;
315         struct pollfd *ufds=NULL;
316         ntp_server_results *servers=NULL;
318         /* setup hints to only return results from getaddrinfo that we'd like */
319         memset(&hints, 0, sizeof(struct addrinfo));
320         hints.ai_family = address_family;
321         hints.ai_protocol = IPPROTO_UDP;
322         hints.ai_socktype = SOCK_DGRAM;
324         /* fill in ai with the list of hosts resolved by the host name */
325         ga_result = getaddrinfo(host, "123", &hints, &ai);
326         if(ga_result!=0){
327                 die(STATE_UNKNOWN, "error getting address for %s: %s\n",
328                     host, gai_strerror(ga_result));
329         }
331         /* count the number of returned hosts, and allocate stuff accordingly */
332         for(ai_tmp=ai; ai_tmp!=NULL; ai_tmp=ai_tmp->ai_next){ num_hosts++; }
333         req=(ntp_message*)malloc(sizeof(ntp_message)*num_hosts);
334         if(req==NULL) die(STATE_UNKNOWN, "can not allocate ntp message array");
335         socklist=(int*)malloc(sizeof(int)*num_hosts);
336         if(socklist==NULL) die(STATE_UNKNOWN, "can not allocate socket array");
337         ufds=(struct pollfd*)malloc(sizeof(struct pollfd)*num_hosts);
338         if(ufds==NULL) die(STATE_UNKNOWN, "can not allocate socket array");
339         servers=(ntp_server_results*)malloc(sizeof(ntp_server_results)*num_hosts);
340         if(servers==NULL) die(STATE_UNKNOWN, "can not allocate server array");
341         memset(servers, 0, sizeof(ntp_server_results)*num_hosts);
342         DBG(printf("Found %d peers to check\n", num_hosts));
344         /* setup each socket for writing, and the corresponding struct pollfd */
345         ai_tmp=ai;
346         for(i=0;ai_tmp;i++){
347                 socklist[i]=socket(ai_tmp->ai_family, SOCK_DGRAM, IPPROTO_UDP);
348                 if(socklist[i] == -1) {
349                         perror(NULL);
350                         die(STATE_UNKNOWN, "can not create new socket");
351                 }
352                 if(connect(socklist[i], ai_tmp->ai_addr, ai_tmp->ai_addrlen)){
353                         die(STATE_UNKNOWN, "can't create socket connection");
354                 } else {
355                         ufds[i].fd=socklist[i];
356                         ufds[i].events=POLLIN;
357                         ufds[i].revents=0;
358                 }
359                 ai_tmp = ai_tmp->ai_next;
360         }
362         /* now do AVG_NUM checks to each host. We stop before timeout/2 seconds
363          * have passed in order to ensure post-processing and jitter time. */
364         now_time=start_ts=time(NULL);
365         while(servers_completed<num_hosts && now_time-start_ts <= socket_timeout/2){
366                 /* loop through each server and find each one which hasn't
367                  * been touched in the past second or so and is still lacking
368                  * some responses. For each of these servers, send a new request,
369                  * and update the "waiting" timestamp with the current time. */
370                 one_written=0;
371                 now_time=time(NULL);
373                 for(i=0; i<num_hosts; i++){
374                         if(servers[i].waiting<now_time && servers[i].num_responses<AVG_NUM){
375                                 if(verbose && servers[i].waiting != 0) printf("re-");
376                                 if(verbose) printf("sending request to peer %d\n", i);
377                                 setup_request(&req[i]);
378                                 write(socklist[i], &req[i], sizeof(ntp_message));
379                                 servers[i].waiting=now_time;
380                                 one_written=1;
381                                 break;
382                         }
383                 }
385                 /* quickly poll for any sockets with pending data */
386                 servers_readable=poll(ufds, num_hosts, 100);
387                 if(servers_readable==-1){
388                         perror("polling ntp sockets");
389                         die(STATE_UNKNOWN, "communication errors");
390                 }
392                 /* read from any sockets with pending data */
393                 for(i=0; servers_readable && i<num_hosts; i++){
394                         if(ufds[i].revents&POLLIN && servers[i].num_responses < AVG_NUM){
395                                 if(verbose) {
396                                         printf("response from peer %d: ", i);
397                                 }
399                                 read(ufds[i].fd, &req[i], sizeof(ntp_message));
400                                 gettimeofday(&recv_time, NULL);
401                                 DBG(print_ntp_message(&req[i]));
402                                 respnum=servers[i].num_responses++;
403                                 servers[i].offset[respnum]=calc_offset(&req[i], &recv_time);
404                                 if(verbose) {
405                                         printf("offset %.10g\n", servers[i].offset[respnum]);
406                                 }
407                                 servers[i].stratum=req[i].stratum;
408                                 servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp);
409                                 servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay);
410                                 servers[i].waiting=0;
411                                 servers[i].flags=req[i].flags;
412                                 servers_readable--;
413                                 one_read = 1;
414                                 if(servers[i].num_responses==AVG_NUM) servers_completed++;
415                         }
416                 }
417                 /* lather, rinse, repeat. */
418         }
420         if (one_read == 0) {
421                 die(STATE_CRITICAL, "NTP CRITICAL: No response from NTP server\n");
422         }
424         /* now, pick the best server from the list */
425         best_index=best_offset_server(servers, num_hosts);
426         if(best_index < 0){
427                 *status=STATE_UNKNOWN;
428         } else {
429                 /* finally, calculate the average offset */
430                 for(i=0; i<servers[best_index].num_responses;i++){
431                         avg_offset+=servers[best_index].offset[j];
432                 }
433                 avg_offset/=servers[best_index].num_responses;
434         }
436         /* cleanup */
437         for(j=0; j<num_hosts; j++){ close(socklist[j]); }
438         free(socklist);
439         free(ufds);
440         free(servers);
441         free(req);
442         freeaddrinfo(ai);
444         if(verbose) printf("overall average offset: %.10g\n", avg_offset);
445         return avg_offset;
448 int process_arguments(int argc, char **argv){
449         int c;
450         int option=0;
451         static struct option longopts[] = {
452                 {"version", no_argument, 0, 'V'},
453                 {"help", no_argument, 0, 'h'},
454                 {"verbose", no_argument, 0, 'v'},
455                 {"use-ipv4", no_argument, 0, '4'},
456                 {"use-ipv6", no_argument, 0, '6'},
457                 {"quiet", no_argument, 0, 'q'},
458                 {"warning", required_argument, 0, 'w'},
459                 {"critical", required_argument, 0, 'c'},
460                 {"timeout", required_argument, 0, 't'},
461                 {"hostname", required_argument, 0, 'H'},
462                 {0, 0, 0, 0}
463         };
465         
466         if (argc < 2)
467                 usage ("\n");
469         while (1) {
470                 c = getopt_long (argc, argv, "Vhv46qw:c:t:H:", longopts, &option);
471                 if (c == -1 || c == EOF || c == 1)
472                         break;
474                 switch (c) {
475                 case 'h':
476                         print_help();
477                         exit(STATE_OK);
478                         break;
479                 case 'V':
480                         print_revision(progname, revision);
481                         exit(STATE_OK);
482                         break;
483                 case 'v':
484                         verbose++;
485                         break;
486                 case 'q':
487                         quiet = 1;
488                         break;
489                 case 'w':
490                         owarn = optarg;
491                         break;
492                 case 'c':
493                         ocrit = optarg;
494                         break;
495                 case 'H':
496                         if(is_host(optarg) == FALSE)
497                                 usage2(_("Invalid hostname/address"), optarg);
498                         server_address = strdup(optarg);
499                         break;
500                 case 't':
501                         socket_timeout=atoi(optarg);
502                         break;
503                 case '4':
504                         address_family = AF_INET;
505                         break;
506                 case '6':
507 #ifdef USE_IPV6
508                         address_family = AF_INET6;
509 #else
510                         usage4 (_("IPv6 support not available"));
511 #endif
512                         break;
513                 case '?':
514                         /* print short usage statement if args not parsable */
515                         usage5 ();
516                         break;
517                 }
518         }
520         if(server_address == NULL){
521                 usage4(_("Hostname was not supplied"));
522         }
524         return 0;
527 char *perfd_offset (double offset)
529         return fperfdata ("offset", offset, "s",
530                 TRUE, offset_thresholds->warning->end,
531                 TRUE, offset_thresholds->critical->end,
532                 FALSE, 0, FALSE, 0);
535 int main(int argc, char *argv[]){
536         int result, offset_result;
537         double offset=0;
538         char *result_line, *perfdata_line;
540         setlocale (LC_ALL, "");
541         bindtextdomain (PACKAGE, LOCALEDIR);
542         textdomain (PACKAGE);
544         result = offset_result = STATE_OK;
546         if (process_arguments (argc, argv) == ERROR)
547                 usage4 (_("Could not parse arguments"));
549         set_thresholds(&offset_thresholds, owarn, ocrit);
551         /* initialize alarm signal handling */
552         signal (SIGALRM, socket_timeout_alarm_handler);
554         /* set socket timeout */
555         alarm (socket_timeout);
557         offset = offset_request(server_address, &offset_result);
558         if (offset_result == STATE_UNKNOWN) {
559                 result = (quiet == 1 ? STATE_UNKNOWN : STATE_CRITICAL);
560         } else {
561                 result = get_status(fabs(offset), offset_thresholds);
562         }
564         switch (result) {
565                 case STATE_CRITICAL :
566                         asprintf(&result_line, _("NTP CRITICAL:"));
567                         break;
568                 case STATE_WARNING :
569                         asprintf(&result_line, _("NTP WARNING:"));
570                         break;
571                 case STATE_OK :
572                         asprintf(&result_line, _("NTP OK:"));
573                         break;
574                 default :
575                         asprintf(&result_line, _("NTP UNKNOWN:"));
576                         break;
577         }
578         if(offset_result == STATE_UNKNOWN){
579                 asprintf(&result_line, "%s %s", result_line, _("Offset unknown"));
580                 asprintf(&perfdata_line, "");
581         } else {
582                 asprintf(&result_line, "%s %s %.10g secs", result_line, _("Offset"), offset);
583                 asprintf(&perfdata_line, "%s", perfd_offset(offset));
584         }
585         printf("%s|%s\n", result_line, perfdata_line);
587         if(server_address!=NULL) free(server_address);
588         return result;
591 void print_help(void){
592         print_revision(progname, revision);
594         printf ("Copyright (c) 2006 Sean Finney\n");
595         printf (COPYRIGHT, copyright, email);
597         printf ("%s\n", _("This plugin checks the clock offset with the ntp server"));
599         printf ("\n\n");
601         print_usage();
602         printf (_(UT_HELP_VRSN));
603         printf (_(UT_HOST_PORT), 'p', "123");
604         printf (" %s\n", "-q, --quiet");
605         printf ("    %s\n", _("Returns UNKNOWN instead of CRITICAL if offset cannot be found"));
606         printf (" %s\n", "-w, --warning=THRESHOLD");
607         printf ("    %s\n", _("Offset to result in warning status (seconds)"));
608         printf (" %s\n", "-c, --critical=THRESHOLD");
609         printf ("    %s\n", _("Offset to result in critical status (seconds)"));
610         printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
611         printf (_(UT_VERBOSE));
613         printf("\n");
614         printf("%s\n", _("Notes:"));
615         printf(" %s\n", _("This plugin checks the clock offset between the local host and a"));
616         printf(" %s\n", _("remote NTP server. It is independent of any commandline programs or"));
617         printf(" %s\n\n", _("external libraries."));
618         printf(" %s\n", _("If you'd rather want to monitor an NTP server, please use"));
619         printf(" %s\n\n", _("check_ntp_peer."));
621         printf(" %s\n", _("See:"));
622         printf(" %s\n", ("http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT"));
623         printf(" %s\n", _("for THRESHOLD format and examples."));
625         printf("\n");
626         printf("%s\n", _("Examples:"));
627         printf("  %s\n", ("./check_ntp_time -H ntpserv -w 0.5 -c 1"));
629         printf (_(UT_SUPPORT));
632 void
633 print_usage(void)
635         printf (_("Usage:"));
636         printf(" %s -H <host> [-w <warn>] [-c <crit>] [-v verbose]\n", progname);