Revert "Make use of xasprintf instead of asprintf"
[monitoring-plugins.git] / plugins / check_nt.c
blobfefbfb7a01a6fc92c1b90ff760812390f3f83a32
1 /*****************************************************************************
2 *
3 * Monitoring check_nt plugin
4 *
5 * License: GPL
6 * Copyright (c) 2000-2002 Yves Rubin (rubiyz@yahoo.com)
7 * Copyright (c) 2003-2007 Monitoring Plugins Development Team
8 *
9 * Description:
11 * This file contains the check_nt plugin
13 * This plugin collects data from the NSClient service running on a
14 * Windows NT/2000/XP/2003 server.
15 * This plugin requires NSClient software to run on NT
16 * (http://nsclient.ready2run.nl/)
19 * This program is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License as published by
21 * the Free Software Foundation, either version 3 of the License, or
22 * (at your option) any later version.
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27 * GNU General Public License for more details.
29 * You should have received a copy of the GNU General Public License
30 * along with this program. If not, see <http://www.gnu.org/licenses/>.
33 *****************************************************************************/
35 const char *progname = "check_nt";
36 const char *copyright = "2000-2007";
37 const char *email = "devel@monitoring-plugins.org";
39 #include "common.h"
40 #include "netutils.h"
41 #include "utils.h"
43 enum checkvars {
44 CHECK_NONE,
45 CHECK_CLIENTVERSION,
46 CHECK_CPULOAD,
47 CHECK_UPTIME,
48 CHECK_USEDDISKSPACE,
49 CHECK_SERVICESTATE,
50 CHECK_PROCSTATE,
51 CHECK_MEMUSE,
52 CHECK_COUNTER,
53 CHECK_FILEAGE,
54 CHECK_INSTANCES
57 enum {
58 MAX_VALUE_LIST = 30,
59 PORT = 1248
62 char *server_address=NULL;
63 char *volume_name=NULL;
64 int server_port=PORT;
65 char *value_list=NULL;
66 char *req_password=NULL;
67 unsigned long lvalue_list[MAX_VALUE_LIST];
68 unsigned long warning_value=0L;
69 unsigned long critical_value=0L;
70 int check_warning_value=FALSE;
71 int check_critical_value=FALSE;
72 enum checkvars vars_to_check = CHECK_NONE;
73 int show_all=FALSE;
75 char recv_buffer[MAX_INPUT_BUFFER];
77 void fetch_data (const char* address, int port, const char* sendb);
78 int process_arguments(int, char **);
79 void preparelist(char *string);
80 int strtoularray(unsigned long *array, char *string, const char *delim);
81 void print_help(void);
82 void print_usage(void);
84 int main(int argc, char **argv){
86 /* should be int result = STATE_UNKNOWN; */
88 int return_code = STATE_UNKNOWN;
89 char *send_buffer=NULL;
90 char *output_message=NULL;
91 char *perfdata=NULL;
92 char *temp_string=NULL;
93 char *temp_string_perf=NULL;
94 char *description=NULL,*counter_unit = NULL;
95 char *minval = NULL, *maxval = NULL, *errcvt = NULL;
96 char *fds=NULL, *tds=NULL;
97 char *numstr;
99 double total_disk_space=0;
100 double free_disk_space=0;
101 double percent_used_space=0;
102 double warning_used_space=0;
103 double critical_used_space=0;
104 double mem_commitLimit=0;
105 double mem_commitByte=0;
106 double fminval = 0, fmaxval = 0;
107 unsigned long utilization;
108 unsigned long uptime;
109 unsigned long age_in_minutes;
110 double counter_value = 0.0;
111 int offset=0;
112 int updays=0;
113 int uphours=0;
114 int upminutes=0;
116 int isPercent = FALSE;
117 int allRight = FALSE;
119 setlocale (LC_ALL, "");
120 bindtextdomain (PACKAGE, LOCALEDIR);
121 textdomain (PACKAGE);
123 /* Parse extra opts if any */
124 argv=np_extra_opts (&argc, argv, progname);
126 if(process_arguments(argc,argv) == ERROR)
127 usage4 (_("Could not parse arguments"));
129 /* initialize alarm signal handling */
130 signal(SIGALRM,socket_timeout_alarm_handler);
132 /* set socket timeout */
133 alarm(socket_timeout);
135 switch (vars_to_check) {
137 case CHECK_CLIENTVERSION:
139 xasprintf(&send_buffer, "%s&1", req_password);
140 fetch_data (server_address, server_port, send_buffer);
141 if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) {
142 xasprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list);
143 return_code = STATE_WARNING;
144 } else {
145 xasprintf (&output_message, "%s", recv_buffer);
146 return_code = STATE_OK;
148 break;
150 case CHECK_CPULOAD:
152 if (value_list==NULL)
153 output_message = strdup (_("missing -l parameters"));
154 else if (strtoularray(lvalue_list,value_list,",")==FALSE)
155 output_message = strdup (_("wrong -l parameter."));
156 else {
157 /* -l parameters is present with only integers */
158 return_code=STATE_OK;
159 temp_string = strdup (_("CPU Load"));
160 temp_string_perf = strdup (" ");
162 /* loop until one of the parameters is wrong or not present */
163 while (lvalue_list[0+offset]> (unsigned long)0 &&
164 lvalue_list[0+offset]<=(unsigned long)17280 &&
165 lvalue_list[1+offset]> (unsigned long)0 &&
166 lvalue_list[1+offset]<=(unsigned long)100 &&
167 lvalue_list[2+offset]> (unsigned long)0 &&
168 lvalue_list[2+offset]<=(unsigned long)100) {
170 /* Send request and retrieve data */
171 xasprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]);
172 fetch_data (server_address, server_port, send_buffer);
174 utilization=strtoul(recv_buffer,NULL,10);
176 /* Check if any of the request is in a warning or critical state */
177 if(utilization >= lvalue_list[2+offset])
178 return_code=STATE_CRITICAL;
179 else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING)
180 return_code=STATE_WARNING;
182 xasprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]);
183 xasprintf(&temp_string,"%s%s",temp_string,output_message);
184 xasprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization,
185 lvalue_list[1+offset], lvalue_list[2+offset]);
186 xasprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata);
187 offset+=3; /* move across the array */
190 if (strlen(temp_string)>10) { /* we had at least one loop */
191 output_message = strdup (temp_string);
192 perfdata = temp_string_perf;
193 } else
194 output_message = strdup (_("not enough values for -l parameters"));
196 break;
198 case CHECK_UPTIME:
200 xasprintf(&send_buffer, "%s&3", req_password);
201 fetch_data (server_address, server_port, send_buffer);
202 uptime=strtoul(recv_buffer,NULL,10);
203 updays = uptime / 86400;
204 uphours = (uptime % 86400) / 3600;
205 upminutes = ((uptime % 86400) % 3600) / 60;
206 xasprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)|uptime=%lu"), updays, uphours, upminutes, uptime);
207 if (check_critical_value==TRUE && uptime <= critical_value)
208 return_code=STATE_CRITICAL;
209 else if (check_warning_value==TRUE && uptime <= warning_value)
210 return_code=STATE_WARNING;
211 else
212 return_code=STATE_OK;
213 break;
215 case CHECK_USEDDISKSPACE:
217 if (value_list==NULL)
218 output_message = strdup (_("missing -l parameters"));
219 else if (strlen(value_list)!=1)
220 output_message = strdup (_("wrong -l argument"));
221 else {
222 xasprintf(&send_buffer,"%s&4&%s", req_password, value_list);
223 fetch_data (server_address, server_port, send_buffer);
224 fds=strtok(recv_buffer,"&");
225 tds=strtok(NULL,"&");
226 if(fds!=NULL)
227 free_disk_space=atof(fds);
228 if(tds!=NULL)
229 total_disk_space=atof(tds);
231 if (total_disk_space>0 && free_disk_space>=0) {
232 percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
233 warning_used_space = ((float)warning_value / 100) * total_disk_space;
234 critical_used_space = ((float)critical_value / 100) * total_disk_space;
236 xasprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
237 value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824,
238 percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
239 xasprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
240 (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
241 critical_used_space / 1073741824, total_disk_space / 1073741824);
243 if(check_critical_value==TRUE && percent_used_space >= critical_value)
244 return_code=STATE_CRITICAL;
245 else if (check_warning_value==TRUE && percent_used_space >= warning_value)
246 return_code=STATE_WARNING;
247 else
248 return_code=STATE_OK;
250 output_message = strdup (temp_string);
251 perfdata = temp_string_perf;
252 } else {
253 output_message = strdup (_("Free disk space : Invalid drive"));
254 return_code=STATE_UNKNOWN;
257 break;
259 case CHECK_SERVICESTATE:
260 case CHECK_PROCSTATE:
262 if (value_list==NULL)
263 output_message = strdup (_("No service/process specified"));
264 else {
265 preparelist(value_list); /* replace , between services with & to send the request */
266 xasprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
267 (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
268 fetch_data (server_address, server_port, send_buffer);
269 numstr = strtok(recv_buffer,"&");
270 if (numstr == NULL)
271 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
272 return_code=atoi(numstr);
273 temp_string=strtok(NULL,"&");
274 output_message = strdup (temp_string);
276 break;
278 case CHECK_MEMUSE:
280 xasprintf(&send_buffer,"%s&7", req_password);
281 fetch_data (server_address, server_port, send_buffer);
282 numstr = strtok(recv_buffer,"&");
283 if (numstr == NULL)
284 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
285 mem_commitLimit=atof(numstr);
286 numstr = strtok(NULL,"&");
287 if (numstr == NULL)
288 die(STATE_UNKNOWN, _("could not fetch information from server\n"));
289 mem_commitByte=atof(numstr);
290 percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
291 warning_used_space = ((float)warning_value / 100) * mem_commitLimit;
292 critical_used_space = ((float)critical_value / 100) * mem_commitLimit;
294 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here,
295 which equals RAM + Pagefiles. */
296 xasprintf(&output_message,_("Memory usage: total:%.2f MB - used: %.2f MB (%.0f%%) - free: %.2f MB (%.0f%%)"),
297 mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,
298 (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
299 xasprintf(&perfdata,_("'Memory usage'=%.2fMB;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567,
300 warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);
302 return_code=STATE_OK;
303 if(check_critical_value==TRUE && percent_used_space >= critical_value)
304 return_code=STATE_CRITICAL;
305 else if (check_warning_value==TRUE && percent_used_space >= warning_value)
306 return_code=STATE_WARNING;
308 break;
310 case CHECK_COUNTER:
314 CHECK_COUNTER has been modified to provide extensive perfdata information.
315 In order to do this, some modifications have been done to the code
316 and some constraints have been introduced.
318 1) For the sake of simplicity of the code, perfdata information will only be
319 provided when the "description" field is added.
321 2) If the counter you're going to measure is percent-based, the code will detect
322 the percent sign in its name and will attribute minimum (0%) and maximum (100%)
323 values automagically, as well the ¨%" sign to graph units.
325 3) OTOH, if the counter is "absolute", you'll have to provide the following
326 the counter unit - that is, the dimensions of the counter you're getting. Examples:
327 pages/s, packets transferred, etc.
329 4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory,
330 but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise.
331 strange things will happen when you make graphs of your data.
334 if (value_list == NULL)
335 output_message = strdup (_("No counter specified"));
336 else
338 preparelist (value_list); /* replace , between services with & to send the request */
339 isPercent = (strchr (value_list, '%') != NULL);
341 strtok (value_list, "&"); /* burn the first parameters */
342 description = strtok (NULL, "&");
343 counter_unit = strtok (NULL, "&");
344 xasprintf (&send_buffer, "%s&8&%s", req_password, value_list);
345 fetch_data (server_address, server_port, send_buffer);
346 counter_value = atof (recv_buffer);
348 if (description == NULL)
349 xasprintf (&output_message, "%.f", counter_value);
350 else if (isPercent)
352 counter_unit = strdup ("%");
353 allRight = TRUE;
356 if ((counter_unit != NULL) && (!allRight))
358 minval = strtok (NULL, "&");
359 maxval = strtok (NULL, "&");
361 /* All parameters specified. Let's check the numbers */
363 fminval = (minval != NULL) ? strtod (minval, &errcvt) : -1;
364 fmaxval = (minval != NULL) ? strtod (maxval, &errcvt) : -1;
366 if ((fminval == 0) && (minval == errcvt))
367 output_message = strdup (_("Minimum value contains non-numbers"));
368 else
370 if ((fmaxval == 0) && (maxval == errcvt))
371 output_message = strdup (_("Maximum value contains non-numbers"));
372 else
373 allRight = TRUE; /* Everything is OK. */
377 else if ((counter_unit == NULL) && (description != NULL))
378 output_message = strdup (_("No unit counter specified"));
380 if (allRight)
382 /* Let's format the output string, finally... */
383 if (strstr(description, "%") == NULL) {
384 xasprintf (&output_message, "%s = %.2f %s", description, counter_value, counter_unit);
385 } else {
386 /* has formatting, will segv if wrong */
387 xasprintf (&output_message, description, counter_value);
389 xasprintf (&output_message, "%s |", output_message);
390 xasprintf (&output_message,"%s %s", output_message,
391 fperfdata (description, counter_value,
392 counter_unit, 1, warning_value, 1, critical_value,
393 (!(isPercent) && (minval != NULL)), fminval,
394 (!(isPercent) && (minval != NULL)), fmaxval));
398 if (critical_value > warning_value)
399 { /* Normal thresholds */
400 if (check_critical_value == TRUE && counter_value >= critical_value)
401 return_code = STATE_CRITICAL;
402 else if (check_warning_value == TRUE && counter_value >= warning_value)
403 return_code = STATE_WARNING;
404 else
405 return_code = STATE_OK;
407 else
408 { /* inverse thresholds */
409 return_code = STATE_OK;
410 if (check_critical_value == TRUE && counter_value <= critical_value)
411 return_code = STATE_CRITICAL;
412 else if (check_warning_value == TRUE && counter_value <= warning_value)
413 return_code = STATE_WARNING;
415 break;
417 case CHECK_FILEAGE:
419 if (value_list==NULL)
420 output_message = strdup (_("No counter specified"));
421 else {
422 preparelist(value_list); /* replace , between services with & to send the request */
423 xasprintf(&send_buffer,"%s&9&%s", req_password,value_list);
424 fetch_data (server_address, server_port, send_buffer);
425 age_in_minutes = atoi(strtok(recv_buffer,"&"));
426 description = strtok(NULL,"&");
427 output_message = strdup (description);
429 if (critical_value > warning_value) { /* Normal thresholds */
430 if(check_critical_value==TRUE && age_in_minutes >= critical_value)
431 return_code=STATE_CRITICAL;
432 else if (check_warning_value==TRUE && age_in_minutes >= warning_value)
433 return_code=STATE_WARNING;
434 else
435 return_code=STATE_OK;
437 else { /* inverse thresholds */
438 if(check_critical_value==TRUE && age_in_minutes <= critical_value)
439 return_code=STATE_CRITICAL;
440 else if (check_warning_value==TRUE && age_in_minutes <= warning_value)
441 return_code=STATE_WARNING;
442 else
443 return_code=STATE_OK;
446 break;
448 case CHECK_INSTANCES:
449 if (value_list==NULL)
450 output_message = strdup (_("No counter specified"));
451 else {
452 xasprintf(&send_buffer,"%s&10&%s", req_password,value_list);
453 fetch_data (server_address, server_port, send_buffer);
454 if (!strncmp(recv_buffer,"ERROR",5)) {
455 printf("NSClient - %s\n",recv_buffer);
456 exit(STATE_UNKNOWN);
458 xasprintf(&output_message,"%s",recv_buffer);
459 return_code=STATE_OK;
461 break;
463 case CHECK_NONE:
464 default:
465 usage4 (_("Please specify a variable to check"));
466 break;
470 /* reset timeout */
471 alarm(0);
473 if (perfdata==NULL)
474 printf("%s\n",output_message);
475 else
476 printf("%s | %s\n",output_message,perfdata);
477 return return_code;
482 /* process command-line arguments */
483 int process_arguments(int argc, char **argv){
484 int c;
486 int option = 0;
487 static struct option longopts[] =
489 {"port", required_argument,0,'p'},
490 {"timeout", required_argument,0,'t'},
491 {"critical", required_argument,0,'c'},
492 {"warning", required_argument,0,'w'},
493 {"variable", required_argument,0,'v'},
494 {"hostname", required_argument,0,'H'},
495 {"params", required_argument,0,'l'},
496 {"secret", required_argument,0,'s'},
497 {"display", required_argument,0,'d'},
498 {"unknown-timeout", no_argument, 0, 'u'},
499 {"version", no_argument, 0,'V'},
500 {"help", no_argument, 0,'h'},
501 {0,0,0,0}
504 /* no options were supplied */
505 if(argc<2) return ERROR;
507 /* backwards compatibility */
508 if (! is_option(argv[1])) {
509 server_address = strdup(argv[1]);
510 argv[1]=argv[0];
511 argv=&argv[1];
512 argc--;
515 for (c=1;c<argc;c++) {
516 if(strcmp("-to",argv[c])==0)
517 strcpy(argv[c],"-t");
518 else if (strcmp("-wv",argv[c])==0)
519 strcpy(argv[c],"-w");
520 else if (strcmp("-cv",argv[c])==0)
521 strcpy(argv[c],"-c");
524 while (1) {
525 c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:u",longopts,&option);
527 if (c==-1||c==EOF||c==1)
528 break;
530 switch (c) {
531 case '?': /* print short usage statement if args not parsable */
532 usage5 ();
533 case 'h': /* help */
534 print_help();
535 exit(STATE_OK);
536 case 'V': /* version */
537 print_revision(progname, NP_VERSION);
538 exit(STATE_OK);
539 case 'H': /* hostname */
540 server_address = optarg;
541 break;
542 case 's': /* password */
543 req_password = optarg;
544 break;
545 case 'p': /* port */
546 if (is_intnonneg(optarg))
547 server_port=atoi(optarg);
548 else
549 die(STATE_UNKNOWN,_("Server port must be an integer\n"));
550 break;
551 case 'v':
552 if(strlen(optarg)<4)
553 return ERROR;
554 if(!strcmp(optarg,"CLIENTVERSION"))
555 vars_to_check=CHECK_CLIENTVERSION;
556 else if(!strcmp(optarg,"CPULOAD"))
557 vars_to_check=CHECK_CPULOAD;
558 else if(!strcmp(optarg,"UPTIME"))
559 vars_to_check=CHECK_UPTIME;
560 else if(!strcmp(optarg,"USEDDISKSPACE"))
561 vars_to_check=CHECK_USEDDISKSPACE;
562 else if(!strcmp(optarg,"SERVICESTATE"))
563 vars_to_check=CHECK_SERVICESTATE;
564 else if(!strcmp(optarg,"PROCSTATE"))
565 vars_to_check=CHECK_PROCSTATE;
566 else if(!strcmp(optarg,"MEMUSE"))
567 vars_to_check=CHECK_MEMUSE;
568 else if(!strcmp(optarg,"COUNTER"))
569 vars_to_check=CHECK_COUNTER;
570 else if(!strcmp(optarg,"FILEAGE"))
571 vars_to_check=CHECK_FILEAGE;
572 else if(!strcmp(optarg,"INSTANCES"))
573 vars_to_check=CHECK_INSTANCES;
574 else
575 return ERROR;
576 break;
577 case 'l': /* value list */
578 value_list = optarg;
579 break;
580 case 'w': /* warning threshold */
581 warning_value=strtoul(optarg,NULL,10);
582 check_warning_value=TRUE;
583 break;
584 case 'c': /* critical threshold */
585 critical_value=strtoul(optarg,NULL,10);
586 check_critical_value=TRUE;
587 break;
588 case 'd': /* Display select for services */
589 if (!strcmp(optarg,"SHOWALL"))
590 show_all = TRUE;
591 break;
592 case 'u':
593 socket_timeout_state=STATE_UNKNOWN;
594 break;
595 case 't': /* timeout */
596 socket_timeout=atoi(optarg);
597 if(socket_timeout<=0)
598 return ERROR;
602 if (server_address == NULL)
603 usage4 (_("You must provide a server address or host name"));
605 if (vars_to_check==CHECK_NONE)
606 return ERROR;
608 if (req_password == NULL)
609 req_password = strdup (_("None"));
611 return OK;
616 void fetch_data (const char *address, int port, const char *sendb) {
617 int result;
619 result=process_tcp_request(address, port, sendb, recv_buffer,sizeof(recv_buffer));
621 if(result!=STATE_OK)
622 die (result, _("could not fetch information from server\n"));
624 if (!strncmp(recv_buffer,"ERROR",5))
625 die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer);
628 int strtoularray(unsigned long *array, char *string, const char *delim) {
629 /* split a <delim> delimited string into a long array */
630 int idx=0;
631 char *t1;
633 for (idx=0;idx<MAX_VALUE_LIST;idx++)
634 array[idx]=0;
636 idx=0;
637 for(t1 = strtok(string,delim);t1 != NULL; t1 = strtok(NULL, delim)) {
638 if (is_numeric(t1) && idx<MAX_VALUE_LIST) {
639 array[idx]=strtoul(t1,NULL,10);
640 idx++;
641 } else
642 return FALSE;
644 return TRUE;
647 void preparelist(char *string) {
648 /* Replace all , with & which is the delimiter for the request */
649 int i;
651 for (i = 0; (size_t)i < strlen(string); i++)
652 if (string[i] == ',') {
653 string[i]='&';
659 void print_help(void)
661 print_revision(progname, NP_VERSION);
663 printf ("Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n");
664 printf (COPYRIGHT, copyright, email);
666 printf ("%s\n", _("This plugin collects data from the NSClient service running on a"));
667 printf ("%s\n", _("Windows NT/2000/XP/2003 server."));
669 printf ("\n\n");
671 print_usage();
673 printf (UT_HELP_VRSN);
674 printf (UT_EXTRA_OPTS);
676 printf ("%s\n", _("Options:"));
677 printf (" %s\n", "-H, --hostname=HOST");
678 printf (" %s\n", _("Name of the host to check"));
679 printf (" %s\n", "-p, --port=INTEGER");
680 printf (" %s", _("Optional port number (default: "));
681 printf ("%d)\n", PORT);
682 printf (" %s\n", "-s, --secret=<password>");
683 printf (" %s\n", _("Password needed for the request"));
684 printf (" %s\n", "-w, --warning=INTEGER");
685 printf (" %s\n", _("Threshold which will result in a warning status"));
686 printf (" %s\n", "-c, --critical=INTEGER");
687 printf (" %s\n", _("Threshold which will result in a critical status"));
688 printf (" %s\n", "-t, --timeout=INTEGER");
689 printf (" %s", _("Seconds before connection attempt times out (default: "));
690 printf (" %s\n", "-l, --params=<parameters>");
691 printf (" %s", _("Parameters passed to specified check (see below)"));
692 printf (" %s\n", "-d, --display={SHOWALL}");
693 printf (" %s", _("Display options (currently only SHOWALL works)"));
694 printf (" %s\n", "-u, --unknown-timeout");
695 printf (" %s", _("Return UNKNOWN on timeouts"));
696 printf ("%d)\n", DEFAULT_SOCKET_TIMEOUT);
697 printf (" %s\n", "-h, --help");
698 printf (" %s\n", _("Print this help screen"));
699 printf (" %s\n", "-V, --version");
700 printf (" %s\n", _("Print version information"));
701 printf (" %s\n", "-v, --variable=STRING");
702 printf (" %s\n\n", _("Variable to check"));
703 printf ("%s\n", _("Valid variables are:"));
704 printf (" %s", "CLIENTVERSION =");
705 printf (" %s\n", _("Get the NSClient version"));
706 printf (" %s\n", _("If -l <version> is specified, will return warning if versions differ."));
707 printf (" %s\n", "CPULOAD =");
708 printf (" %s\n", _("Average CPU load on last x minutes."));
709 printf (" %s\n", _("Request a -l parameter with the following syntax:"));
710 printf (" %s\n", _("-l <minutes range>,<warning threshold>,<critical threshold>."));
711 printf (" %s\n", _("<minute range> should be less than 24*60."));
712 printf (" %s\n", _("Thresholds are percentage and up to 10 requests can be done in one shot."));
713 printf (" %s\n", "ie: -l 60,90,95,120,90,95");
714 printf (" %s\n", "UPTIME =");
715 printf (" %s\n", _("Get the uptime of the machine."));
716 printf (" %s\n", _("No specific parameters. No warning or critical threshold"));
717 printf (" %s\n", "USEDDISKSPACE =");
718 printf (" %s\n", _("Size and percentage of disk use."));
719 printf (" %s\n", _("Request a -l parameter containing the drive letter only."));
720 printf (" %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
721 printf (" %s\n", "MEMUSE =");
722 printf (" %s\n", _("Memory use."));
723 printf (" %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
724 printf (" %s\n", "SERVICESTATE =");
725 printf (" %s\n", _("Check the state of one or several services."));
726 printf (" %s\n", _("Request a -l parameters with the following syntax:"));
727 printf (" %s\n", _("-l <service1>,<service2>,<service3>,..."));
728 printf (" %s\n", _("You can specify -d SHOWALL in case you want to see working services"));
729 printf (" %s\n", _("in the returned string."));
730 printf (" %s\n", "PROCSTATE =");
731 printf (" %s\n", _("Check if one or several process are running."));
732 printf (" %s\n", _("Same syntax as SERVICESTATE."));
733 printf (" %s\n", "COUNTER =");
734 printf (" %s\n", _("Check any performance counter of Windows NT/2000."));
735 printf (" %s\n", _("Request a -l parameters with the following syntax:"));
736 printf (" %s\n", _("-l \"\\\\<performance object>\\\\counter\",\"<description>"));
737 printf (" %s\n", _("The <description> parameter is optional and is given to a printf "));
738 printf (" %s\n", _("output command which requires a float parameter."));
739 printf (" %s\n", _("If <description> does not include \"%%\", it is used as a label."));
740 printf (" %s\n", _("Some examples:"));
741 printf (" %s\n", "\"Paging file usage is %%.2f %%%%\"");
742 printf (" %s\n", "\"%%.f %%%% paging file used.\"");
743 printf (" %s\n", "INSTANCES =");
744 printf (" %s\n", _("Check any performance counter object of Windows NT/2000."));
745 printf (" %s\n", _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>"));
746 printf (" %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),"));
747 printf (" %s\n", _("if it is two words, it should be enclosed in quotes"));
748 printf (" %s\n", _("The returned results will be a comma-separated list of instances on "));
749 printf (" %s\n", _(" the selected computer for that object."));
750 printf (" %s\n", _("The purpose of this is to be run from command line to determine what instances"));
751 printf (" %s\n", _(" are available for monitoring without having to log onto the Windows server"));
752 printf (" %s\n", _(" to run Perfmon directly."));
753 printf (" %s\n", _("It can also be used in scripts that automatically create the monitoring service"));
754 printf (" %s\n", _(" configuration files."));
755 printf (" %s\n", _("Some examples:"));
756 printf (" %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process"));
758 printf ("%s\n", _("Notes:"));
759 printf (" %s\n", _("- The NSClient service should be running on the server to get any information"));
760 printf (" %s\n", "(http://nsclient.ready2run.nl).");
761 printf (" %s\n", _("- Critical thresholds should be lower than warning thresholds"));
762 printf (" %s\n", _("- Default port 1248 is sometimes in use by other services. The error"));
763 printf (" %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
764 printf (" %s\n", _("One fix for this is to change the port to something else on check_nt "));
765 printf (" %s\n", _("and on the client service it\'s connecting to."));
767 printf (UT_SUPPORT);
772 void print_usage(void)
774 printf ("%s\n", _("Usage:"));
775 printf ("%s -H host -v variable [-p port] [-w warning] [-c critical]\n",progname);
776 printf ("[-l params] [-d SHOWALL] [-u] [-t timeout]\n");