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