Code

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