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