Code

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