Code

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