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