Code

Ignore stderr messages unless return code is non-zero or there is no output
[nagiosplug.git] / plugins / check_nt.c
1 /*****************************************************************************
2
3 * Nagios check_nt plugin
4
5 * License: GPL
6 * Copyright (c) 2000-2002 Yves Rubin (rubiyz@yahoo.com)
7 * Copyright (c) 2003-2007 Nagios Plugins Development Team
8
9 * Description:
10
11 * This file contains the check_nt plugin
12
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/)
17
18
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.
23
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.
28
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/>.
31
32
33 *****************************************************************************/
35 const char *progname = "check_nt";
36 const char *copyright = "2000-2007";
37 const char *email = "nagiosplug-devel@lists.sourceforge.net";
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
55 };
57 enum {
58         MAX_VALUE_LIST = 30,
59         PORT = 1248
60 };
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;
98         double total_disk_space=0;
99         double free_disk_space=0;
100         double percent_used_space=0;
101         double warning_used_space=0;
102         double critical_used_space=0;
103         double mem_commitLimit=0;
104         double mem_commitByte=0;
105         double fminval = 0, fmaxval = 0;
106         unsigned long utilization;
107         unsigned long uptime;
108         unsigned long age_in_minutes;
109         double counter_value = 0.0;
110         int offset=0;
111         int updays=0;
112         int uphours=0;
113         int upminutes=0;
115         int isPercent = FALSE;
116         int allRight = FALSE;
118         setlocale (LC_ALL, "");
119         bindtextdomain (PACKAGE, LOCALEDIR);
120         textdomain (PACKAGE);
122         /* Parse extra opts if any */
123         argv=np_extra_opts (&argc, argv, progname);
125         if(process_arguments(argc,argv) == ERROR)
126                 usage4 (_("Could not parse arguments"));
128         /* initialize alarm signal handling */
129         signal(SIGALRM,socket_timeout_alarm_handler);
131         /* set socket timeout */
132         alarm(socket_timeout);
134         switch (vars_to_check) {
136         case CHECK_CLIENTVERSION:
138                 asprintf(&send_buffer, "%s&1", req_password);
139                 fetch_data (server_address, server_port, send_buffer);
140                 if (value_list != NULL && strcmp(recv_buffer, value_list) != 0) {
141                         asprintf (&output_message, _("Wrong client version - running: %s, required: %s"), recv_buffer, value_list);
142                         return_code = STATE_WARNING;
143                 } else {
144                         asprintf (&output_message, "%s", recv_buffer);
145                         return_code = STATE_OK;
146                 }
147                 break;
149         case CHECK_CPULOAD:
151                 if (value_list==NULL)
152                         output_message = strdup (_("missing -l parameters"));
153                 else if (strtoularray(lvalue_list,value_list,",")==FALSE)
154                         output_message = strdup (_("wrong -l parameter."));
155                 else {
156                         /* -l parameters is present with only integers */
157                         return_code=STATE_OK;
158                         temp_string = strdup (_("CPU Load"));
159                         temp_string_perf = strdup (" ");
161                         /* loop until one of the parameters is wrong or not present */
162                         while (lvalue_list[0+offset]> (unsigned long)0 &&
163                                                  lvalue_list[0+offset]<=(unsigned long)17280 && 
164                                                  lvalue_list[1+offset]> (unsigned long)0 &&
165                                                  lvalue_list[1+offset]<=(unsigned long)100 && 
166                                                  lvalue_list[2+offset]> (unsigned long)0 &&
167                                                  lvalue_list[2+offset]<=(unsigned long)100) {
169                                 /* Send request and retrieve data */
170                                 asprintf(&send_buffer,"%s&2&%lu",req_password,lvalue_list[0+offset]);
171                                 fetch_data (server_address, server_port, send_buffer);
173                                 utilization=strtoul(recv_buffer,NULL,10);
174                                 
175                                 /* Check if any of the request is in a warning or critical state */
176                                 if(utilization >= lvalue_list[2+offset])
177                                         return_code=STATE_CRITICAL;
178                                 else if(utilization >= lvalue_list[1+offset] && return_code<STATE_WARNING)
179                                         return_code=STATE_WARNING;
181                                 asprintf(&output_message,_(" %lu%% (%lu min average)"), utilization, lvalue_list[0+offset]);
182                                 asprintf(&temp_string,"%s%s",temp_string,output_message);
183                                 asprintf(&perfdata,_(" '%lu min avg Load'=%lu%%;%lu;%lu;0;100"), lvalue_list[0+offset], utilization,
184                                   lvalue_list[1+offset], lvalue_list[2+offset]);
185                                 asprintf(&temp_string_perf,"%s%s",temp_string_perf,perfdata);
186                                 offset+=3;      /* move across the array */
187                         }
189                         if (strlen(temp_string)>10) {  /* we had at least one loop */
190                                 output_message = strdup (temp_string);
191                                 perfdata = temp_string_perf;
192                         } else
193                                 output_message = strdup (_("not enough values for -l parameters"));
194                 }       
195                 break;
197         case CHECK_UPTIME:
199                 asprintf(&send_buffer, "%s&3", req_password);
200                 fetch_data (server_address, server_port, send_buffer);
201                 uptime=strtoul(recv_buffer,NULL,10);
202                 updays = uptime / 86400;                        
203                 uphours = (uptime % 86400) / 3600;
204                 upminutes = ((uptime % 86400) % 3600) / 60;
205                 asprintf(&output_message,_("System Uptime - %u day(s) %u hour(s) %u minute(s)"),updays,uphours, upminutes);
206                 return_code=STATE_OK;
207                 break;
209         case CHECK_USEDDISKSPACE:
211                 if (value_list==NULL)
212                         output_message = strdup (_("missing -l parameters"));
213                 else if (strlen(value_list)!=1)
214                         output_message = strdup (_("wrong -l argument"));
215                 else {
216                         asprintf(&send_buffer,"%s&4&%s", req_password, value_list);
217                         fetch_data (server_address, server_port, send_buffer);
218                         fds=strtok(recv_buffer,"&");
219                         tds=strtok(NULL,"&");
220                         if(fds!=NULL)
221                                 free_disk_space=atof(fds);
222                         if(tds!=NULL)
223                                 total_disk_space=atof(tds);
225                         if (total_disk_space>0 && free_disk_space>=0) {
226                                 percent_used_space = ((total_disk_space - free_disk_space) / total_disk_space) * 100;
227                                 warning_used_space = ((float)warning_value / 100) * total_disk_space;
228                                 critical_used_space = ((float)critical_value / 100) * total_disk_space;
230                                 asprintf(&temp_string,_("%s:\\ - total: %.2f Gb - used: %.2f Gb (%.0f%%) - free %.2f Gb (%.0f%%)"),
231                                   value_list, total_disk_space / 1073741824, (total_disk_space - free_disk_space) / 1073741824,
232                                   percent_used_space, free_disk_space / 1073741824, (free_disk_space / total_disk_space)*100);
233                                 asprintf(&temp_string_perf,_("'%s:\\ Used Space'=%.2fGb;%.2f;%.2f;0.00;%.2f"), value_list,
234                                   (total_disk_space - free_disk_space) / 1073741824, warning_used_space / 1073741824,
235                                   critical_used_space / 1073741824, total_disk_space / 1073741824);
237                                 if(check_critical_value==TRUE && percent_used_space >= critical_value)
238                                         return_code=STATE_CRITICAL;
239                                 else if (check_warning_value==TRUE && percent_used_space >= warning_value)
240                                         return_code=STATE_WARNING;      
241                                 else
242                                         return_code=STATE_OK;   
244                                 output_message = strdup (temp_string);
245                                 perfdata = temp_string_perf;
246                         } else {
247                                 output_message = strdup (_("Free disk space : Invalid drive"));
248                                 return_code=STATE_UNKNOWN;
249                         }
250                 }
251                 break;
253         case CHECK_SERVICESTATE:
254         case CHECK_PROCSTATE:
256                 if (value_list==NULL)
257                         output_message = strdup (_("No service/process specified"));
258                 else {
259                         preparelist(value_list);                /* replace , between services with & to send the request */
260                         asprintf(&send_buffer,"%s&%u&%s&%s", req_password,(vars_to_check==CHECK_SERVICESTATE)?5:6,
261                                                          (show_all==TRUE) ? "ShowAll" : "ShowFail",value_list);
262                         fetch_data (server_address, server_port, send_buffer);
263                         return_code=atoi(strtok(recv_buffer,"&"));
264                         temp_string=strtok(NULL,"&");
265                         output_message = strdup (temp_string);
266                 }
267                 break;
269         case CHECK_MEMUSE:
270                 
271                 asprintf(&send_buffer,"%s&7", req_password);
272                 fetch_data (server_address, server_port, send_buffer);
273                 mem_commitLimit=atof(strtok(recv_buffer,"&"));
274                 mem_commitByte=atof(strtok(NULL,"&"));
275                 percent_used_space = (mem_commitByte / mem_commitLimit) * 100;
276                 warning_used_space = ((float)warning_value / 100) * mem_commitLimit;
277                 critical_used_space = ((float)critical_value / 100) * mem_commitLimit;
279                 /* Divisor should be 1048567, not 3044515, as we are measuring "Commit Charge" here, 
280                 which equals RAM + Pagefiles. */
281                 asprintf(&output_message,_("Memory usage: total:%.2f Mb - used: %.2f Mb (%.0f%%) - free: %.2f Mb (%.0f%%)"), 
282                   mem_commitLimit / 1048567, mem_commitByte / 1048567, percent_used_space,  
283                   (mem_commitLimit - mem_commitByte) / 1048567, (mem_commitLimit - mem_commitByte) / mem_commitLimit * 100);
284                 asprintf(&perfdata,_("'Memory usage'=%.2fMb;%.2f;%.2f;0.00;%.2f"), mem_commitByte / 1048567,
285                   warning_used_space / 1048567, critical_used_space / 1048567, mem_commitLimit / 1048567);
286         
287                 return_code=STATE_OK;
288                 if(check_critical_value==TRUE && percent_used_space >= critical_value)
289                         return_code=STATE_CRITICAL;
290                 else if (check_warning_value==TRUE && percent_used_space >= warning_value)
291                         return_code=STATE_WARNING;      
293                 break;
295         case CHECK_COUNTER:
298                 /* 
299                 CHECK_COUNTER has been modified to provide extensive perfdata information.
300                 In order to do this, some modifications have been done to the code
301                 and some constraints have been introduced.
302                 
303                 1) For the sake of simplicity of the code, perfdata information will only be 
304                  provided when the "description" field is added. 
305                 
306                 2) If the counter you're going to measure is percent-based, the code will detect
307                  the percent sign in its name and will attribute minimum (0%) and maximum (100%) 
308                  values automagically, as well the ĀØ%" sign to graph units.
310                 3) OTOH, if the counter is "absolute", you'll have to provide the following
311                  the counter unit - that is, the dimensions of the counter you're getting. Examples:
312                  pages/s, packets transferred, etc.
314                 4) If you want, you may provide the minimum and maximum values to expect. They aren't mandatory,
315                  but once specified they MUST have the same order of magnitude and units of -w and -c; otherwise.
316                  strange things will happen when you make graphs of your data.
317                 */
319                 if (value_list == NULL)
320                         output_message = strdup (_("No counter specified"));
321                 else
322                 {
323                         preparelist (value_list);       /* replace , between services with & to send the request */
324                         isPercent = (strchr (value_list, '%') != NULL);
326                         strtok (value_list, "&");       /* burn the first parameters */
327                         description = strtok (NULL, "&");
328                         counter_unit = strtok (NULL, "&");
329                         asprintf (&send_buffer, "%s&8&%s", req_password, value_list);
330                         fetch_data (server_address, server_port, send_buffer);
331                         counter_value = atof (recv_buffer);
334                         if (description == NULL)
335                         asprintf (&output_message, "%.f", counter_value);
336                         else if (isPercent)
337                              {  
338                                 counter_unit = strdup ("%");
339                                 allRight = TRUE;
340                              }
342                         if ((counter_unit != NULL) && (!allRight))
343                         {       
344                                 minval = strtok (NULL, "&");
345                                 maxval = strtok (NULL, "&");
347                                 /* All parameters specified. Let's check the numbers */
349                                 fminval = (minval != NULL) ? strtod (minval, &errcvt) : -1;
350                                 fmaxval = (minval != NULL) ? strtod (maxval, &errcvt) : -1;
352                                 if ((fminval == 0) && (minval == errcvt))
353                                         output_message = strdup (_("Minimum value contains non-numbers"));
354                                 else
355                                 {
356                                         if ((fmaxval == 0) && (maxval == errcvt))
357                                                 output_message = strdup (_("Maximum value contains non-numbers"));
358                                         else
359                                                 allRight = TRUE;        /* Everything is OK. */
361                                 }
362                         }
363                         else if ((counter_unit == NULL) && (description != NULL))
364                                 output_message = strdup (_("No unit counter specified"));
366                         if (allRight)
367                         {
368                                 /* Let's format the output string, finally... */
369                                         if (strstr(description, "%") == NULL) {
370                                                 asprintf (&output_message, "%s = %.2f %s",                                                                                      description, counter_value, counter_unit);
371                                         } else {
372                                                 /* has formatting, will segv if wrong */
373                                         asprintf (&output_message, description, counter_value);
374                                         }
375                                         asprintf (&output_message, "%s |", output_message);
376                                 asprintf (&output_message,"%s %s", output_message, 
377                                                 fperfdata (description, counter_value, 
378                                                         counter_unit, 1, warning_value, 1, critical_value,
379                                                         (!(isPercent) && (minval != NULL)), fminval,
380                                                         (!(isPercent) && (minval != NULL)), fmaxval));
381                         }
382                 }
384                 if (critical_value > warning_value)
385                 {                       /* Normal thresholds */
386                         if (check_critical_value == TRUE && counter_value >= critical_value)
387                              return_code = STATE_CRITICAL;
388                         else if (check_warning_value == TRUE && counter_value >= warning_value)
389                                 return_code = STATE_WARNING;
390                              else
391                                 return_code = STATE_OK;
392                 }
393                 else
394                 {                       /* inverse thresholds */
395                         return_code = STATE_OK;
396                         if (check_critical_value == TRUE && counter_value <= critical_value)
397                              return_code = STATE_CRITICAL;
398                         else if (check_warning_value == TRUE && counter_value <= warning_value)
399                                     return_code = STATE_WARNING;
400                 }
401         break;
402                 
403         case CHECK_FILEAGE:
405                 if (value_list==NULL)
406                         output_message = strdup (_("No counter specified"));
407                 else {
408                         preparelist(value_list);                /* replace , between services with & to send the request */
409                         asprintf(&send_buffer,"%s&9&%s", req_password,value_list);
410                         fetch_data (server_address, server_port, send_buffer);
411                         age_in_minutes = atoi(strtok(recv_buffer,"&"));
412                         description = strtok(NULL,"&");
413                         output_message = strdup (description);
414         
415                         if (critical_value > warning_value) {        /* Normal thresholds */
416                                 if(check_critical_value==TRUE && age_in_minutes >= critical_value)
417                                         return_code=STATE_CRITICAL;
418                                 else if (check_warning_value==TRUE && age_in_minutes >= warning_value)
419                                         return_code=STATE_WARNING;      
420                                 else
421                                         return_code=STATE_OK;   
422                         }
423                         else {                                       /* inverse thresholds */
424                                 if(check_critical_value==TRUE && age_in_minutes <= critical_value)
425                                         return_code=STATE_CRITICAL;
426                                 else if (check_warning_value==TRUE && age_in_minutes <= warning_value)
427                                         return_code=STATE_WARNING;      
428                                 else
429                                         return_code=STATE_OK;   
430                         }
431                 }
432                 break;
434         case CHECK_INSTANCES:           
435                 if (value_list==NULL)
436                         output_message = strdup (_("No counter specified"));
437                 else {
438                         asprintf(&send_buffer,"%s&10&%s", req_password,value_list);
439                         fetch_data (server_address, server_port, send_buffer);
440                         if (!strncmp(recv_buffer,"ERROR",5)) {
441                                 printf("NSClient - %s\n",recv_buffer);
442                                 exit(STATE_UNKNOWN);
443                         }
444                         asprintf(&output_message,"%s",recv_buffer);                     
445                         return_code=STATE_OK;
446                 }
447                 break;
449         case CHECK_NONE:
450         default:
451                 usage4 (_("Please specify a variable to check"));
452                 break;
454         }
456         /* reset timeout */
457         alarm(0);
459         if (perfdata==NULL)
460                 printf("%s\n",output_message);
461         else
462                 printf("%s | %s\n",output_message,perfdata);
463         return return_code;
468 /* process command-line arguments */
469 int process_arguments(int argc, char **argv){
470         int c;
472         int option = 0;
473         static struct option longopts[] =
474         { 
475                 {"port",     required_argument,0,'p'},
476                 {"timeout",  required_argument,0,'t'},
477                 {"critical", required_argument,0,'c'},
478                 {"warning",  required_argument,0,'w'},
479                 {"variable", required_argument,0,'v'},
480                 {"hostname", required_argument,0,'H'},
481                 {"params",   required_argument,0,'l'},
482                 {"secret",   required_argument,0,'s'},
483                 {"display",  required_argument,0,'d'},
484                 {"version",  no_argument,      0,'V'},
485                 {"help",     no_argument,      0,'h'},
486                 {0,0,0,0}
487         };
489         /* no options were supplied */
490         if(argc<2) return ERROR;
492         /* backwards compatibility */
493         if (! is_option(argv[1])) {
494                 server_address = strdup(argv[1]);
495                 argv[1]=argv[0];
496                 argv=&argv[1];
497                 argc--;
498         }
500   for (c=1;c<argc;c++) {
501     if(strcmp("-to",argv[c])==0)
502       strcpy(argv[c],"-t");
503     else if (strcmp("-wv",argv[c])==0)
504       strcpy(argv[c],"-w");
505     else if (strcmp("-cv",argv[c])==0)
506       strcpy(argv[c],"-c");
507         }
509         while (1) {
510                 c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",longopts,&option);
512                 if (c==-1||c==EOF||c==1)
513                         break;
515                 switch (c) {
516                         case '?': /* print short usage statement if args not parsable */
517                         usage5 ();
518                         case 'h': /* help */
519                                 print_help();
520                                 exit(STATE_OK);
521                         case 'V': /* version */
522                                 print_revision(progname, NP_VERSION);
523                                 exit(STATE_OK);
524                         case 'H': /* hostname */
525                                 if (server_address)     free(server_address);
526                                 server_address = optarg;
527                                 break;
528                         case 's': /* password */
529                                 req_password = optarg;
530                                 break;
531                         case 'p': /* port */
532                                 if (is_intnonneg(optarg))
533                                         server_port=atoi(optarg);
534                                 else
535                                         die(STATE_UNKNOWN,_("Server port must be an integer\n"));
536                                 break;
537                         case 'v':
538                                 if(strlen(optarg)<4)
539                                         return ERROR;
540                                 if(!strcmp(optarg,"CLIENTVERSION"))
541                                         vars_to_check=CHECK_CLIENTVERSION;
542                                 else if(!strcmp(optarg,"CPULOAD"))
543                                         vars_to_check=CHECK_CPULOAD;
544                                 else if(!strcmp(optarg,"UPTIME"))
545                                         vars_to_check=CHECK_UPTIME;
546                                 else if(!strcmp(optarg,"USEDDISKSPACE"))
547                                         vars_to_check=CHECK_USEDDISKSPACE;
548                                 else if(!strcmp(optarg,"SERVICESTATE"))
549                                         vars_to_check=CHECK_SERVICESTATE;
550                                 else if(!strcmp(optarg,"PROCSTATE"))
551                                         vars_to_check=CHECK_PROCSTATE;
552                                 else if(!strcmp(optarg,"MEMUSE"))
553                                         vars_to_check=CHECK_MEMUSE;
554                                 else if(!strcmp(optarg,"COUNTER"))
555                                         vars_to_check=CHECK_COUNTER;
556                                 else if(!strcmp(optarg,"FILEAGE"))
557                                         vars_to_check=CHECK_FILEAGE;
558                                 else if(!strcmp(optarg,"INSTANCES"))
559                                         vars_to_check=CHECK_INSTANCES;
560                                 else
561                                         return ERROR;
562                                 break;
563                         case 'l': /* value list */
564                                 value_list = optarg;
565                                 break;
566                         case 'w': /* warning threshold */
567                                 warning_value=strtoul(optarg,NULL,10);
568                                 check_warning_value=TRUE;
569                                 break;
570                         case 'c': /* critical threshold */
571                                 critical_value=strtoul(optarg,NULL,10);
572                                 check_critical_value=TRUE;
573                                 break;
574                         case 'd': /* Display select for services */
575                                 if (!strcmp(optarg,"SHOWALL"))
576                                         show_all = TRUE;
577                                 break;
578                         case 't': /* timeout */
579                                 socket_timeout=atoi(optarg);
580                                 if(socket_timeout<=0)
581                                         return ERROR;
582                         }
584         }
586         if (vars_to_check==CHECK_NONE)
587                 return ERROR;
589         if (req_password == NULL)
590                 req_password = strdup (_("None"));
592         return OK;
597 void fetch_data (const char *address, int port, const char *sendb) {
598         int result;
600         result=process_tcp_request(address, port, sendb, recv_buffer,sizeof(recv_buffer));
602         if(result!=STATE_OK)
603                 die (result, _("could not fetch information from server\n"));
604                 
605         if (!strncmp(recv_buffer,"ERROR",5))
606                 die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer);
609 int strtoularray(unsigned long *array, char *string, const char *delim) {
610         /* split a <delim> delimited string into a long array */
611         int idx=0;
612         char *t1;
614         for (idx=0;idx<MAX_VALUE_LIST;idx++)
615                 array[idx]=0;
616         
617         idx=0;
618         for(t1 = strtok(string,delim);t1 != NULL; t1 = strtok(NULL, delim)) {
619                 if (is_numeric(t1) && idx<MAX_VALUE_LIST) {
620                         array[idx]=strtoul(t1,NULL,10);
621                         idx++;
622                 } else  
623                         return FALSE;
624         }               
625         return TRUE;
628 void preparelist(char *string) {
629         /* Replace all , with & which is the delimiter for the request */
630         int i;
632         for (i = 0; (size_t)i < strlen(string); i++)
633                 if (string[i] == ',') {
634                         string[i]='&';
635                 }
640 void print_help(void)
642         print_revision(progname, NP_VERSION);
643         
644         printf ("Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n");
645         printf (COPYRIGHT, copyright, email);
646         
647         printf ("%s\n", _("This plugin collects data from the NSClient service running on a"));
648   printf ("%s\n", _("Windows NT/2000/XP/2003 server."));
650   printf ("\n\n");
652         print_usage();
653         
654   printf (_(UT_HELP_VRSN));
655   printf (_(UT_EXTRA_OPTS));
657   printf ("%s\n", _("Options:"));
658   printf (" %s\n", "-H, --hostname=HOST");
659   printf ("   %s\n", _("Name of the host to check"));
660   printf (" %s\n", "-p, --port=INTEGER");
661   printf ("   %s", _("Optional port number (default: "));
662   printf ("%d)\n", PORT);
663   printf (" %s\n", "-s, --secret=<password>");
664   printf ("   %s\n", _("Password needed for the request"));
665   printf (" %s\n", "-w, --warning=INTEGER");
666   printf ("   %s\n", _("Threshold which will result in a warning status"));
667   printf (" %s\n", "-c, --critical=INTEGER");
668   printf ("   %s\n", _("Threshold which will result in a critical status"));
669   printf (" %s\n", "-t, --timeout=INTEGER");
670   printf ("   %s", _("Seconds before connection attempt times out (default: "));
671   printf (" %s\n", "-l, --params=<parameters>");
672   printf ("   %s", _("Parameters passed to specified check (see below)"));
673   printf (" %s\n", "-d, --display={SHOWALL}");
674   printf ("   %s", _("Display options (currently only SHOWALL works)"));
675   printf ("%d)\n", DEFAULT_SOCKET_TIMEOUT);
676   printf (" %s\n", "-h, --help");
677   printf ("   %s\n", _("Print this help screen"));
678   printf (" %s\n", "-V, --version");
679   printf ("   %s\n", _("Print version information"));
680   printf (" %s\n", "-v, --variable=STRING");
681   printf ("   %s\n\n", _("Variable to check"));
682   printf ("%s\n", _("Valid variables are:"));
683   printf (" %s", "CLIENTVERSION =");
684   printf (" %s\n", _("Get the NSClient version"));
685   printf ("  %s\n", _("If -l <version> is specified, will return warning if versions differ."));
686   printf (" %s\n", "CPULOAD =");
687   printf ("  %s\n", _("Average CPU load on last x minutes."));
688   printf ("  %s\n", _("Request a -l parameter with the following syntax:"));
689   printf ("  %s\n", _("-l <minutes range>,<warning threshold>,<critical threshold>."));
690   printf ("  %s\n", _("<minute range> should be less than 24*60."));
691   printf ("  %s\n", _("Thresholds are percentage and up to 10 requests can be done in one shot."));
692   printf ("  %s\n", "ie: -l 60,90,95,120,90,95");
693   printf (" %s\n", "UPTIME =");
694   printf ("  %s\n", _("Get the uptime of the machine."));
695   printf ("  %s\n", _("No specific parameters. No warning or critical threshold"));
696   printf (" %s\n", "USEDDISKSPACE =");
697   printf ("  %s\n", _("Size and percentage of disk use."));
698   printf ("  %s\n", _("Request a -l parameter containing the drive letter only."));
699   printf ("  %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
700   printf (" %s\n", "MEMUSE =");
701   printf ("  %s\n", _("Memory use."));
702   printf ("  %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
703   printf (" %s\n", "SERVICESTATE =");
704   printf ("  %s\n", _("Check the state of one or several services."));
705   printf ("  %s\n", _("Request a -l parameters with the following syntax:"));
706   printf ("  %s\n", _("-l <service1>,<service2>,<service3>,..."));
707   printf ("  %s\n", _("You can specify -d SHOWALL in case you want to see working services"));
708   printf ("  %s\n", _("in the returned string."));
709   printf (" %s\n", "PROCSTATE =");
710   printf ("  %s\n", _("Check if one or several process are running."));
711   printf ("  %s\n", _("Same syntax as SERVICESTATE."));
712   printf (" %s\n", "COUNTER =");
713   printf ("  %s\n", _("Check any performance counter of Windows NT/2000."));
714   printf ("  %s\n", _("Request a -l parameters with the following syntax:"));
715   printf ("  %s\n", _("-l \"\\\\<performance object>\\\\counter\",\"<description>"));
716   printf ("  %s\n", _("The <description> parameter is optional and is given to a printf "));
717   printf ("  %s\n", _("output command which requires a float parameter."));
718   printf ("  %s\n", _("If <description> does not include \"%%\", it is used as a label."));
719   printf ("  %s\n", _("Some examples:"));
720   printf ("  %s\n", "\"Paging file usage is %%.2f %%%%\"");
721   printf ("  %s\n", "\"%%.f %%%% paging file used.\"");
722   printf (" %s\n", "INSTANCES =");  
723   printf ("  %s\n", _("Check any performance counter object of Windows NT/2000."));
724   printf ("  %s\n", _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>"));
725   printf ("  %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),"));
726   printf ("  %s\n", _("if it is two words, it should be enclosed in quotes"));
727   printf ("  %s\n", _("The returned results will be a comma-separated list of instances on "));
728   printf ("  %s\n", _(" the selected computer for that object."));
729   printf ("  %s\n", _("The purpose of this is to be run from command line to determine what instances"));
730   printf ("  %s\n", _(" are available for monitoring without having to log onto the Windows server"));
731   printf ("  %s\n", _("  to run Perfmon directly."));
732   printf ("  %s\n", _("It can also be used in scripts that automatically create Nagios service"));
733   printf ("  %s\n", _(" configuration files."));
734   printf ("  %s\n", _("Some examples:"));
735   printf ("  %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process"));
737   printf ("%s\n", _("Notes:"));
738   printf (" %s\n", _("- The NSClient service should be running on the server to get any information"));
739   printf ("   %s\n", "(http://nsclient.ready2run.nl).");
740   printf (" %s\n", _("- Critical thresholds should be lower than warning thresholds"));
741   printf (" %s\n", _("- Default port 1248 is sometimes in use by other services. The error"));
742   printf ("   %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
743   printf ("   %s\n", _("One fix for this is to change the port to something else on check_nt "));
744   printf ("   %s\n", _("and on the client service it\'s connecting to."));
745 #ifdef NP_EXTRA_OPTS
746   printf (" -%s", _(UT_EXTRA_OPTS_NOTES));
747 #endif
749   printf (_(UT_SUPPORT));
754 void print_usage(void)
756   printf (_("Usage:"));
757         printf ("%s -H host -v variable [-p port] [-w warning] [-c critical]\n",progname);
758   printf ("[-l params] [-d SHOWALL] [-t timeout]\n");