Code

Add missing long options for check_nt (for use with extra-opts)
[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                 {"params",   required_argument,0,'l'},
480                 {"secret",   required_argument,0,'s'},
481                 {"display",  required_argument,0,'d'},
482                 {"version",  no_argument,      0,'V'},
483                 {"help",     no_argument,      0,'h'},
484                 {0,0,0,0}
485         };
487         /* no options were supplied */
488         if(argc<2) return ERROR;
490         /* backwards compatibility */
491         if (! is_option(argv[1])) {
492                 server_address = strdup(argv[1]);
493                 argv[1]=argv[0];
494                 argv=&argv[1];
495                 argc--;
496         }
498   for (c=1;c<argc;c++) {
499     if(strcmp("-to",argv[c])==0)
500       strcpy(argv[c],"-t");
501     else if (strcmp("-wv",argv[c])==0)
502       strcpy(argv[c],"-w");
503     else if (strcmp("-cv",argv[c])==0)
504       strcpy(argv[c],"-c");
505         }
507         while (1) {
508                 c = getopt_long(argc,argv,"+hVH:t:c:w:p:v:l:s:d:",longopts,&option);
510                 if (c==-1||c==EOF||c==1)
511                         break;
513                 switch (c) {
514                         case '?': /* print short usage statement if args not parsable */
515                         usage5 ();
516                         case 'h': /* help */
517                                 print_help();
518                                 exit(STATE_OK);
519                         case 'V': /* version */
520                                 print_revision(progname,revision);
521                                 exit(STATE_OK);
522                         case 'H': /* hostname */
523                                 if (server_address)     free(server_address);
524                                 server_address = optarg;
525                                 break;
526                         case 's': /* password */
527                                 req_password = optarg;
528                                 break;
529                         case 'p': /* port */
530                                 if (is_intnonneg(optarg))
531                                         server_port=atoi(optarg);
532                                 else
533                                         die(STATE_UNKNOWN,_("Server port must be an integer\n"));
534                                 break;
535                         case 'v':
536                                 if(strlen(optarg)<4)
537                                         return ERROR;
538                                 if(!strcmp(optarg,"CLIENTVERSION"))
539                                         vars_to_check=CHECK_CLIENTVERSION;
540                                 else if(!strcmp(optarg,"CPULOAD"))
541                                         vars_to_check=CHECK_CPULOAD;
542                                 else if(!strcmp(optarg,"UPTIME"))
543                                         vars_to_check=CHECK_UPTIME;
544                                 else if(!strcmp(optarg,"USEDDISKSPACE"))
545                                         vars_to_check=CHECK_USEDDISKSPACE;
546                                 else if(!strcmp(optarg,"SERVICESTATE"))
547                                         vars_to_check=CHECK_SERVICESTATE;
548                                 else if(!strcmp(optarg,"PROCSTATE"))
549                                         vars_to_check=CHECK_PROCSTATE;
550                                 else if(!strcmp(optarg,"MEMUSE"))
551                                         vars_to_check=CHECK_MEMUSE;
552                                 else if(!strcmp(optarg,"COUNTER"))
553                                         vars_to_check=CHECK_COUNTER;
554                                 else if(!strcmp(optarg,"FILEAGE"))
555                                         vars_to_check=CHECK_FILEAGE;
556                                 else if(!strcmp(optarg,"INSTANCES"))
557                                         vars_to_check=CHECK_INSTANCES;
558                                 else
559                                         return ERROR;
560                                 break;
561                         case 'l': /* value list */
562                                 value_list = optarg;
563                                 break;
564                         case 'w': /* warning threshold */
565                                 warning_value=strtoul(optarg,NULL,10);
566                                 check_warning_value=TRUE;
567                                 break;
568                         case 'c': /* critical threshold */
569                                 critical_value=strtoul(optarg,NULL,10);
570                                 check_critical_value=TRUE;
571                                 break;
572                         case 'd': /* Display select for services */
573                                 if (!strcmp(optarg,"SHOWALL"))
574                                         show_all = TRUE;
575                                 break;
576                         case 't': /* timeout */
577                                 socket_timeout=atoi(optarg);
578                                 if(socket_timeout<=0)
579                                         return ERROR;
580                         }
582         }
584         if (vars_to_check==CHECK_NONE)
585                 return ERROR;
587         if (req_password == NULL)
588                 req_password = strdup (_("None"));
590         return OK;
595 void fetch_data (const char *address, int port, const char *sendb) {
596         int result;
598         result=process_tcp_request(address, port, sendb, recv_buffer,sizeof(recv_buffer));
600         if(result!=STATE_OK)
601                 die (result, _("could not fetch information from server\n"));
602                 
603         if (!strncmp(recv_buffer,"ERROR",5))
604                 die (STATE_UNKNOWN, "NSClient - %s\n",recv_buffer);
607 int strtoularray(unsigned long *array, char *string, const char *delim) {
608         /* split a <delim> delimited string into a long array */
609         int idx=0;
610         char *t1;
612         for (idx=0;idx<MAX_VALUE_LIST;idx++)
613                 array[idx]=0;
614         
615         idx=0;
616         for(t1 = strtok(string,delim);t1 != NULL; t1 = strtok(NULL, delim)) {
617                 if (is_numeric(t1) && idx<MAX_VALUE_LIST) {
618                         array[idx]=strtoul(t1,NULL,10);
619                         idx++;
620                 } else  
621                         return FALSE;
622         }               
623         return TRUE;
626 void preparelist(char *string) {
627         /* Replace all , with & which is the delimiter for the request */
628         int i;
630         for (i = 0; (size_t)i < strlen(string); i++)
631                 if (string[i] == ',') {
632                         string[i]='&';
633                 }
638 void print_help(void)
640         print_revision(progname,revision);
641         
642         printf ("Copyright (c) 2000 Yves Rubin (rubiyz@yahoo.com)\n");
643         printf (COPYRIGHT, copyright, email);
644         
645         printf ("%s\n", _("This plugin collects data from the NSClient service running on a"));
646   printf ("%s\n", _("Windows NT/2000/XP/2003 server."));
648   printf ("\n\n");
650         print_usage();
651         
652   printf (_(UT_HELP_VRSN));
653   printf (_(UT_EXTRA_OPTS));
655   printf ("%s\n", _("Options:"));
656   printf (" %s\n", "-H, --hostname=HOST");
657   printf ("   %s\n", _("Name of the host to check"));
658   printf (" %s\n", "-p, --port=INTEGER");
659   printf ("   %s", _("Optional port number (default: "));
660   printf ("%d)\n", PORT);
661   printf (" %s\n", "-s, --secret=<password>");
662   printf ("   %s\n", _("Password needed for the request"));
663   printf (" %s\n", "-w, --warning=INTEGER");
664   printf ("   %s\n", _("Threshold which will result in a warning status"));
665   printf (" %s\n", "-c, --critical=INTEGER");
666   printf ("   %s\n", _("Threshold which will result in a critical status"));
667   printf (" %s\n", "-t, --timeout=INTEGER");
668   printf ("   %s", _("Seconds before connection attempt times out (default: "));
669   printf (" %s\n", "-l, --params=<parameters>");
670   printf ("   %s", _("Parameters passed to specified check (see below)"));
671   printf (" %s\n", "-d, --display={SHOWALL}");
672   printf ("   %s", _("Display options (currently only SHOWALL works)"));
673   printf ("%d)\n", DEFAULT_SOCKET_TIMEOUT);
674   printf (" %s\n", "-h, --help");
675   printf ("   %s\n", _("Print this help screen"));
676   printf (" %s\n", "-V, --version");
677   printf ("   %s\n", _("Print version information"));
678   printf (" %s\n", "-v, --variable=STRING");
679   printf ("   %s\n\n", _("Variable to check"));
680   printf ("%s\n", _("Valid variables are:"));
681   printf (" %s", "CLIENTVERSION =");
682   printf (" %s\n", _("Get the NSClient version"));
683   printf ("  %s\n", _("If -l <version> is specified, will return warning if versions differ."));
684   printf (" %s\n", "CPULOAD =");
685   printf ("  %s\n", _("Average CPU load on last x minutes."));
686   printf ("  %s\n", _("Request a -l parameter with the following syntax:"));
687   printf ("  %s\n", _("-l <minutes range>,<warning threshold>,<critical threshold>."));
688   printf ("  %s\n", _("<minute range> should be less than 24*60."));
689   printf ("  %s\n", _("Thresholds are percentage and up to 10 requests can be done in one shot."));
690   printf ("  %s\n", "ie: -l 60,90,95,120,90,95");
691   printf (" %s\n", "UPTIME =");
692   printf ("  %s\n", _("Get the uptime of the machine."));
693   printf ("  %s\n", _("No specific parameters. No warning or critical threshold"));
694   printf (" %s\n", "USEDDISKSPACE =");
695   printf ("  %s\n", _("Size and percentage of disk use."));
696   printf ("  %s\n", _("Request a -l parameter containing the drive letter only."));
697   printf ("  %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
698   printf (" %s\n", "MEMUSE =");
699   printf ("  %s\n", _("Memory use."));
700   printf ("  %s\n", _("Warning and critical thresholds can be specified with -w and -c."));
701   printf (" %s\n", "SERVICESTATE =");
702   printf ("  %s\n", _("Check the state of one or several services."));
703   printf ("  %s\n", _("Request a -l parameters with the following syntax:"));
704   printf ("  %s\n", _("-l <service1>,<service2>,<service3>,..."));
705   printf ("  %s\n", _("You can specify -d SHOWALL in case you want to see working services"));
706   printf ("  %s\n", _("in the returned string."));
707   printf (" %s\n", "PROCSTATE =");
708   printf ("  %s\n", _("Check if one or several process are running."));
709   printf ("  %s\n", _("Same syntax as SERVICESTATE."));
710   printf (" %s\n", "COUNTER =");
711   printf ("  %s\n", _("Check any performance counter of Windows NT/2000."));
712   printf ("  %s\n", _("Request a -l parameters with the following syntax:"));
713   printf ("  %s\n", _("-l \"\\\\<performance object>\\\\counter\",\"<description>"));
714   printf ("  %s\n", _("The <description> parameter is optional and is given to a printf "));
715   printf ("  %s\n", _("output command which requires a float parameter."));
716   printf ("  %s\n", _("If <description> does not include \"%%\", it is used as a label."));
717   printf ("  %s\n", _("Some examples:"));
718   printf ("  %s\n", "\"Paging file usage is %%.2f %%%%\"");
719   printf ("  %s\n", "\"%%.f %%%% paging file used.\"");
720   printf (" %s\n", "INSTANCES =");  
721   printf ("  %s\n", _("Check any performance counter object of Windows NT/2000."));
722   printf ("  %s\n", _("Syntax: check_nt -H <hostname> -p <port> -v INSTANCES -l <counter object>"));
723   printf ("  %s\n", _("<counter object> is a Windows Perfmon Counter object (eg. Process),"));
724   printf ("  %s\n", _("if it is two words, it should be enclosed in quotes"));
725   printf ("  %s\n", _("The returned results will be a comma-separated list of instances on "));
726   printf ("  %s\n", _(" the selected computer for that object."));
727   printf ("  %s\n", _("The purpose of this is to be run from command line to determine what instances"));
728   printf ("  %s\n", _(" are available for monitoring without having to log onto the Windows server"));
729   printf ("  %s\n", _("  to run Perfmon directly."));
730   printf ("  %s\n", _("It can also be used in scripts that automatically create Nagios service"));
731   printf ("  %s\n", _(" configuration files."));
732   printf ("  %s\n", _("Some examples:"));
733   printf ("  %s\n\n", _("check_nt -H 192.168.1.1 -p 1248 -v INSTANCES -l Process"));
735   printf ("%s\n", _("Notes:"));
736   printf (" %s\n", _("- The NSClient service should be running on the server to get any information"));
737   printf ("   %s\n", "(http://nsclient.ready2run.nl).");
738   printf (" %s\n", _("- Critical thresholds should be lower than warning thresholds"));
739   printf (" %s\n", _("- Default port 1248 is sometimes in use by other services. The error"));
740   printf ("   %s\n", _("output when this happens contains \"Cannot map xxxxx to protocol number\"."));
741   printf ("   %s\n", _("One fix for this is to change the port to something else on check_nt "));
742   printf ("   %s\n", _("and on the client service it\'s connecting to."));
743 #ifdef NP_EXTRA_OPTS
744   printf (" -%s", _(UT_EXTRA_OPTS_NOTES));
745 #endif
747   printf (_(UT_SUPPORT));
752 void print_usage(void)
754   printf (_("Usage:"));
755         printf ("%s -H host -v variable [-p port] [-w warning] [-c critical]\n",progname);
756   printf ("[-l params] [-d SHOWALL] [-t timeout]\n");