diff options
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 216 |
1 files changed, 165 insertions, 51 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index afc568b2..2acada22 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -1,31 +1,31 @@ | |||
1 | /***************************************************************************** | 1 | /***************************************************************************** |
2 | * | 2 | * |
3 | * Monitoring check_snmp plugin | 3 | * Monitoring check_snmp plugin |
4 | * | 4 | * |
5 | * License: GPL | 5 | * License: GPL |
6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team | 6 | * Copyright (c) 1999-2007 Monitoring Plugins Development Team |
7 | * | 7 | * |
8 | * Description: | 8 | * Description: |
9 | * | 9 | * |
10 | * This file contains the check_snmp plugin | 10 | * This file contains the check_snmp plugin |
11 | * | 11 | * |
12 | * Check status of remote machines and obtain system information via SNMP | 12 | * Check status of remote machines and obtain system information via SNMP |
13 | * | 13 | * |
14 | * | 14 | * |
15 | * This program is free software: you can redistribute it and/or modify | 15 | * This program is free software: you can redistribute it and/or modify |
16 | * it under the terms of the GNU General Public License as published by | 16 | * it under the terms of the GNU General Public License as published by |
17 | * the Free Software Foundation, either version 3 of the License, or | 17 | * the Free Software Foundation, either version 3 of the License, or |
18 | * (at your option) any later version. | 18 | * (at your option) any later version. |
19 | * | 19 | * |
20 | * This program is distributed in the hope that it will be useful, | 20 | * This program is distributed in the hope that it will be useful, |
21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 21 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 22 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | * GNU General Public License for more details. | 23 | * GNU General Public License for more details. |
24 | * | 24 | * |
25 | * You should have received a copy of the GNU General Public License | 25 | * You should have received a copy of the GNU General Public License |
26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 26 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | * | 27 | * |
28 | * | 28 | * |
29 | *****************************************************************************/ | 29 | *****************************************************************************/ |
30 | 30 | ||
31 | const char *progname = "check_snmp"; | 31 | const char *progname = "check_snmp"; |
@@ -46,6 +46,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
46 | #define DEFAULT_PRIV_PROTOCOL "DES" | 46 | #define DEFAULT_PRIV_PROTOCOL "DES" |
47 | #define DEFAULT_DELIMITER "=" | 47 | #define DEFAULT_DELIMITER "=" |
48 | #define DEFAULT_OUTPUT_DELIMITER " " | 48 | #define DEFAULT_OUTPUT_DELIMITER " " |
49 | #define DEFAULT_BUFFER_SIZE 100 | ||
49 | 50 | ||
50 | #define mark(a) ((a)!=0?"*":"") | 51 | #define mark(a) ((a)!=0?"*":"") |
51 | 52 | ||
@@ -64,6 +65,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
64 | #define L_RATE_MULTIPLIER CHAR_MAX+2 | 65 | #define L_RATE_MULTIPLIER CHAR_MAX+2 |
65 | #define L_INVERT_SEARCH CHAR_MAX+3 | 66 | #define L_INVERT_SEARCH CHAR_MAX+3 |
66 | #define L_OFFSET CHAR_MAX+4 | 67 | #define L_OFFSET CHAR_MAX+4 |
68 | #define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5 | ||
67 | 69 | ||
68 | /* Gobble to string - stop incrementing c when c[0] match one of the | 70 | /* Gobble to string - stop incrementing c when c[0] match one of the |
69 | * characters in s */ | 71 | * characters in s */ |
@@ -90,6 +92,7 @@ char *thisarg (char *str); | |||
90 | char *nextarg (char *str); | 92 | char *nextarg (char *str); |
91 | void print_usage (void); | 93 | void print_usage (void); |
92 | void print_help (void); | 94 | void print_help (void); |
95 | char *multiply (char *str); | ||
93 | 96 | ||
94 | #include "regex.h" | 97 | #include "regex.h" |
95 | char regex_expect[MAX_INPUT_BUFFER] = ""; | 98 | char regex_expect[MAX_INPUT_BUFFER] = ""; |
@@ -113,6 +116,7 @@ char *authproto = NULL; | |||
113 | char *privproto = NULL; | 116 | char *privproto = NULL; |
114 | char *authpasswd = NULL; | 117 | char *authpasswd = NULL; |
115 | char *privpasswd = NULL; | 118 | char *privpasswd = NULL; |
119 | int nulloid = STATE_UNKNOWN; | ||
116 | char **oids = NULL; | 120 | char **oids = NULL; |
117 | size_t oids_size = 0; | 121 | size_t oids_size = 0; |
118 | char *label; | 122 | char *label; |
@@ -153,6 +157,10 @@ double *previous_value; | |||
153 | size_t previous_size = OID_COUNT_STEP; | 157 | size_t previous_size = OID_COUNT_STEP; |
154 | int perf_labels = 1; | 158 | int perf_labels = 1; |
155 | char* ip_version = ""; | 159 | char* ip_version = ""; |
160 | double multiplier = 1.0; | ||
161 | char *fmtstr = ""; | ||
162 | char buffer[DEFAULT_BUFFER_SIZE]; | ||
163 | bool ignore_mib_parsing_errors = false; | ||
156 | 164 | ||
157 | static char *fix_snmp_range(char *th) | 165 | static char *fix_snmp_range(char *th) |
158 | { | 166 | { |
@@ -300,42 +308,55 @@ main (int argc, char **argv) | |||
300 | } | 308 | } |
301 | 309 | ||
302 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ | 310 | /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ |
303 | command_line = calloc (10 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); | 311 | |
304 | command_line[0] = snmpcmd; | 312 | unsigned index = 0; |
305 | command_line[1] = strdup ("-Le"); | 313 | command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); |
306 | command_line[2] = strdup ("-t"); | 314 | |
307 | xasprintf (&command_line[3], "%d", timeout_interval); | 315 | command_line[index++] = snmpcmd; |
308 | command_line[4] = strdup ("-r"); | 316 | command_line[index++] = strdup ("-Le"); |
309 | xasprintf (&command_line[5], "%d", retries); | 317 | command_line[index++] = strdup ("-t"); |
310 | command_line[6] = strdup ("-m"); | 318 | xasprintf (&command_line[index++], "%d", timeout_interval); |
311 | command_line[7] = strdup (miblist); | 319 | command_line[index++] = strdup ("-r"); |
312 | command_line[8] = "-v"; | 320 | xasprintf (&command_line[index++], "%d", retries); |
313 | command_line[9] = strdup (proto); | 321 | command_line[index++] = strdup ("-m"); |
322 | command_line[index++] = strdup (miblist); | ||
323 | command_line[index++] = "-v"; | ||
324 | command_line[index++] = strdup (proto); | ||
325 | |||
326 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", | ||
327 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto); | ||
328 | |||
329 | if (ignore_mib_parsing_errors) { | ||
330 | command_line[index++] = "-Pe"; | ||
331 | xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth); | ||
332 | } | ||
333 | |||
314 | 334 | ||
315 | for (i = 0; i < numcontext; i++) { | 335 | for (i = 0; i < numcontext; i++) { |
316 | command_line[10 + i] = contextargs[i]; | 336 | command_line[index++] = contextargs[i]; |
317 | } | 337 | } |
318 | 338 | ||
319 | for (i = 0; i < numauthpriv; i++) { | 339 | for (i = 0; i < numauthpriv; i++) { |
320 | command_line[10 + numcontext + i] = authpriv[i]; | 340 | command_line[index++] = authpriv[i]; |
321 | } | 341 | } |
322 | 342 | ||
323 | xasprintf (&command_line[10 + numcontext + numauthpriv], "%s:%s", server_address, port); | 343 | xasprintf (&command_line[index++], "%s:%s", server_address, port); |
324 | 344 | ||
325 | /* This is just for display purposes, so it can remain a string */ | 345 | xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", |
326 | xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s %s:%s", | 346 | cl_hidden_auth, |
327 | snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[context]", "[authpriv]", | 347 | server_address, |
328 | server_address, port); | 348 | port); |
329 | 349 | ||
330 | for (i = 0; i < numoids; i++) { | 350 | for (i = 0; i < numoids; i++) { |
331 | command_line[10 + numcontext + numauthpriv + 1 + i] = oids[i]; | 351 | command_line[index++] = oids[i]; |
332 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 352 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
333 | } | 353 | } |
334 | 354 | ||
335 | command_line[10 + numcontext + numauthpriv + 1 + numoids] = NULL; | 355 | command_line[index++] = NULL; |
336 | 356 | ||
337 | if (verbose) | 357 | if (verbose) { |
338 | printf ("%s\n", cl_hidden_auth); | 358 | printf ("%s\n", cl_hidden_auth); |
359 | } | ||
339 | 360 | ||
340 | /* Set signal handling and alarm */ | 361 | /* Set signal handling and alarm */ |
341 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { | 362 | if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { |
@@ -375,7 +396,7 @@ main (int argc, char **argv) | |||
375 | } | 396 | } |
376 | } | 397 | } |
377 | 398 | ||
378 | for (line=0, i=0; line < chld_out.lines; line++, i++) { | 399 | for (line=0, i=0; line < chld_out.lines && i < numoids ; line++, i++) { |
379 | if(calculate_rate) | 400 | if(calculate_rate) |
380 | conv = "%.10g"; | 401 | conv = "%.10g"; |
381 | else | 402 | else |
@@ -397,15 +418,15 @@ main (int argc, char **argv) | |||
397 | is_counter=0; | 418 | is_counter=0; |
398 | /* We strip out the datatype indicator for PHBs */ | 419 | /* We strip out the datatype indicator for PHBs */ |
399 | if (strstr (response, "Gauge: ")) { | 420 | if (strstr (response, "Gauge: ")) { |
400 | show = strstr (response, "Gauge: ") + 7; | 421 | show = multiply (strstr (response, "Gauge: ") + 7); |
401 | } | 422 | } |
402 | else if (strstr (response, "Gauge32: ")) { | 423 | else if (strstr (response, "Gauge32: ")) { |
403 | show = strstr (response, "Gauge32: ") + 9; | 424 | show = multiply (strstr (response, "Gauge32: ") + 9); |
404 | } | 425 | } |
405 | else if (strstr (response, "Counter32: ")) { | 426 | else if (strstr (response, "Counter32: ")) { |
406 | show = strstr (response, "Counter32: ") + 11; | 427 | show = strstr (response, "Counter32: ") + 11; |
407 | is_counter=1; | 428 | is_counter=1; |
408 | if(!calculate_rate) | 429 | if(!calculate_rate) |
409 | strcpy(type, "c"); | 430 | strcpy(type, "c"); |
410 | } | 431 | } |
411 | else if (strstr (response, "Counter64: ")) { | 432 | else if (strstr (response, "Counter64: ")) { |
@@ -415,7 +436,10 @@ main (int argc, char **argv) | |||
415 | strcpy(type, "c"); | 436 | strcpy(type, "c"); |
416 | } | 437 | } |
417 | else if (strstr (response, "INTEGER: ")) { | 438 | else if (strstr (response, "INTEGER: ")) { |
418 | show = strstr (response, "INTEGER: ") + 9; | 439 | show = multiply (strstr (response, "INTEGER: ") + 9); |
440 | if (fmtstr != "") { | ||
441 | conv = fmtstr; | ||
442 | } | ||
419 | } | 443 | } |
420 | else if (strstr (response, "OID: ")) { | 444 | else if (strstr (response, "OID: ")) { |
421 | show = strstr (response, "OID: ") + 5; | 445 | show = strstr (response, "OID: ") + 5; |
@@ -468,9 +492,20 @@ main (int argc, char **argv) | |||
468 | /* Process this block for numeric comparisons */ | 492 | /* Process this block for numeric comparisons */ |
469 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ | 493 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ |
470 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { | 494 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { |
495 | if (verbose > 2) { | ||
496 | print_thresholds(" thresholds", thlds[i]); | ||
497 | } | ||
471 | ptr = strpbrk (show, "-0123456789"); | 498 | ptr = strpbrk (show, "-0123456789"); |
472 | if (ptr == NULL) | 499 | if (ptr == NULL){ |
473 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | 500 | if (nulloid == 3) |
501 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | ||
502 | else if (nulloid == 0) | ||
503 | die (STATE_OK,_("No valid data returned (%s)\n"), show); | ||
504 | else if (nulloid == 1) | ||
505 | die (STATE_WARNING,_("No valid data returned (%s)\n"), show); | ||
506 | else if (nulloid == 2) | ||
507 | die (STATE_CRITICAL,_("No valid data returned (%s)\n"), show); | ||
508 | } | ||
474 | while (i >= response_size) { | 509 | while (i >= response_size) { |
475 | response_size += OID_COUNT_STEP; | 510 | response_size += OID_COUNT_STEP; |
476 | response_value = realloc(response_value, response_size * sizeof(*response_value)); | 511 | response_value = realloc(response_value, response_size * sizeof(*response_value)); |
@@ -581,14 +616,16 @@ main (int argc, char **argv) | |||
581 | 616 | ||
582 | if (warning_thresholds) { | 617 | if (warning_thresholds) { |
583 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 618 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
584 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 619 | if(thlds[i]->warning && thlds[i]->warning->text) |
620 | strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
585 | } | 621 | } |
586 | 622 | ||
587 | if (critical_thresholds) { | 623 | if (critical_thresholds) { |
588 | if (!warning_thresholds) | 624 | if (!warning_thresholds) |
589 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 625 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
590 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 626 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
591 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 627 | if(thlds[i]->critical && thlds[i]->critical->text) |
628 | strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
592 | } | 629 | } |
593 | 630 | ||
594 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 631 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
@@ -602,7 +639,7 @@ main (int argc, char **argv) | |||
602 | state_string=malloc(string_length); | 639 | state_string=malloc(string_length); |
603 | if(state_string==NULL) | 640 | if(state_string==NULL) |
604 | die(STATE_UNKNOWN, _("Cannot malloc")); | 641 | die(STATE_UNKNOWN, _("Cannot malloc")); |
605 | 642 | ||
606 | current_length=0; | 643 | current_length=0; |
607 | for(i=0; i<total_oids; i++) { | 644 | for(i=0; i<total_oids; i++) { |
608 | xasprintf(&temp_string,"%.0f",response_value[i]); | 645 | xasprintf(&temp_string,"%.0f",response_value[i]); |
@@ -624,7 +661,7 @@ main (int argc, char **argv) | |||
624 | state_string[--current_length]='\0'; | 661 | state_string[--current_length]='\0'; |
625 | if (verbose > 2) | 662 | if (verbose > 2) |
626 | printf("State string=%s\n",state_string); | 663 | printf("State string=%s\n",state_string); |
627 | 664 | ||
628 | /* This is not strictly the same as time now, but any subtle variations will cancel out */ | 665 | /* This is not strictly the same as time now, but any subtle variations will cancel out */ |
629 | np_state_write_string(current_time, state_string ); | 666 | np_state_write_string(current_time, state_string ); |
630 | if(previous_state==NULL) { | 667 | if(previous_state==NULL) { |
@@ -656,6 +693,7 @@ process_arguments (int argc, char **argv) | |||
656 | {"oid", required_argument, 0, 'o'}, | 693 | {"oid", required_argument, 0, 'o'}, |
657 | {"object", required_argument, 0, 'o'}, | 694 | {"object", required_argument, 0, 'o'}, |
658 | {"delimiter", required_argument, 0, 'd'}, | 695 | {"delimiter", required_argument, 0, 'd'}, |
696 | {"nulloid", required_argument, 0, 'z'}, | ||
659 | {"output-delimiter", required_argument, 0, 'D'}, | 697 | {"output-delimiter", required_argument, 0, 'D'}, |
660 | {"string", required_argument, 0, 's'}, | 698 | {"string", required_argument, 0, 's'}, |
661 | {"timeout", required_argument, 0, 't'}, | 699 | {"timeout", required_argument, 0, 't'}, |
@@ -683,6 +721,9 @@ process_arguments (int argc, char **argv) | |||
683 | {"perf-oids", no_argument, 0, 'O'}, | 721 | {"perf-oids", no_argument, 0, 'O'}, |
684 | {"ipv4", no_argument, 0, '4'}, | 722 | {"ipv4", no_argument, 0, '4'}, |
685 | {"ipv6", no_argument, 0, '6'}, | 723 | {"ipv6", no_argument, 0, '6'}, |
724 | {"multiplier", required_argument, 0, 'M'}, | ||
725 | {"fmtstr", required_argument, 0, 'f'}, | ||
726 | {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS}, | ||
686 | {0, 0, 0, 0} | 727 | {0, 0, 0, 0} |
687 | }; | 728 | }; |
688 | 729 | ||
@@ -700,7 +741,7 @@ process_arguments (int argc, char **argv) | |||
700 | } | 741 | } |
701 | 742 | ||
702 | while (1) { | 743 | while (1) { |
703 | c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:", | 744 | c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:M:f:z:", |
704 | longopts, &option); | 745 | longopts, &option); |
705 | 746 | ||
706 | if (c == -1 || c == EOF) | 747 | if (c == -1 || c == EOF) |
@@ -811,6 +852,12 @@ process_arguments (int argc, char **argv) | |||
811 | eval_method[j+1] |= CRIT_PRESENT; | 852 | eval_method[j+1] |= CRIT_PRESENT; |
812 | } | 853 | } |
813 | break; | 854 | break; |
855 | case 'z': /* Null OID Return Check */ | ||
856 | if (!is_integer (optarg)) | ||
857 | usage2 (_("Exit status must be a positive integer"), optarg); | ||
858 | else | ||
859 | nulloid = atoi(optarg); | ||
860 | break; | ||
814 | case 's': /* string or substring */ | 861 | case 's': /* string or substring */ |
815 | strncpy (string_value, optarg, sizeof (string_value) - 1); | 862 | strncpy (string_value, optarg, sizeof (string_value) - 1); |
816 | string_value[sizeof (string_value) - 1] = 0; | 863 | string_value[sizeof (string_value) - 1] = 0; |
@@ -824,6 +871,7 @@ process_arguments (int argc, char **argv) | |||
824 | break; | 871 | break; |
825 | case 'R': /* regex */ | 872 | case 'R': /* regex */ |
826 | cflags = REG_ICASE; | 873 | cflags = REG_ICASE; |
874 | // fall through | ||
827 | case 'r': /* regex */ | 875 | case 'r': /* regex */ |
828 | cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; | 876 | cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; |
829 | strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); | 877 | strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); |
@@ -932,6 +980,18 @@ process_arguments (int argc, char **argv) | |||
932 | if(verbose>2) | 980 | if(verbose>2) |
933 | printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n"); | 981 | printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n"); |
934 | break; | 982 | break; |
983 | case 'M': | ||
984 | if ( strspn( optarg, "0123456789.," ) == strlen( optarg ) ) { | ||
985 | multiplier=strtod(optarg,NULL); | ||
986 | } | ||
987 | break; | ||
988 | case 'f': | ||
989 | if (multiplier != 1.0) { | ||
990 | fmtstr=optarg; | ||
991 | } | ||
992 | break; | ||
993 | case L_IGNORE_MIB_PARSING_ERRORS: | ||
994 | ignore_mib_parsing_errors = true; | ||
935 | } | 995 | } |
936 | } | 996 | } |
937 | 997 | ||
@@ -1001,7 +1061,7 @@ validate_arguments () | |||
1001 | contextargs[0] = strdup ("-n"); | 1061 | contextargs[0] = strdup ("-n"); |
1002 | contextargs[1] = strdup (context); | 1062 | contextargs[1] = strdup (context); |
1003 | } | 1063 | } |
1004 | 1064 | ||
1005 | if (seclevel == NULL) | 1065 | if (seclevel == NULL) |
1006 | xasprintf(&seclevel, "noAuthNoPriv"); | 1066 | xasprintf(&seclevel, "noAuthNoPriv"); |
1007 | 1067 | ||
@@ -1122,6 +1182,44 @@ nextarg (char *str) | |||
1122 | 1182 | ||
1123 | 1183 | ||
1124 | 1184 | ||
1185 | /* multiply result (values 0 < n < 1 work as divider) */ | ||
1186 | char * | ||
1187 | multiply (char *str) | ||
1188 | { | ||
1189 | char *endptr; | ||
1190 | double val; | ||
1191 | char *conv = "%f"; | ||
1192 | |||
1193 | if(multiplier == 1) | ||
1194 | return(str); | ||
1195 | |||
1196 | if(verbose>2) | ||
1197 | printf(" multiply input: %s\n", str); | ||
1198 | |||
1199 | val = strtod (str, &endptr); | ||
1200 | if ((val == 0.0) && (endptr == str)) { | ||
1201 | die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); | ||
1202 | } | ||
1203 | |||
1204 | if(verbose>2) | ||
1205 | printf(" multiply extracted double: %f\n", val); | ||
1206 | val *= multiplier; | ||
1207 | if (fmtstr != "") { | ||
1208 | conv = fmtstr; | ||
1209 | } | ||
1210 | if (val == (int)val) { | ||
1211 | snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val); | ||
1212 | } else { | ||
1213 | if(verbose>2) | ||
1214 | printf(" multiply using format: %s\n", conv); | ||
1215 | snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val); | ||
1216 | } | ||
1217 | if(verbose>2) | ||
1218 | printf(" multiply result: %s\n", buffer); | ||
1219 | return buffer; | ||
1220 | } | ||
1221 | |||
1222 | |||
1125 | void | 1223 | void |
1126 | print_help (void) | 1224 | print_help (void) |
1127 | { | 1225 | { |
@@ -1161,7 +1259,7 @@ print_help (void) | |||
1161 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); | 1259 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); |
1162 | printf (" %s\n", "-U, --secname=USERNAME"); | 1260 | printf (" %s\n", "-U, --secname=USERNAME"); |
1163 | printf (" %s\n", _("SNMPv3 username")); | 1261 | printf (" %s\n", _("SNMPv3 username")); |
1164 | printf (" %s\n", "-A, --authpassword=PASSWORD"); | 1262 | printf (" %s\n", "-A, --authpasswd=PASSWORD"); |
1165 | printf (" %s\n", _("SNMPv3 authentication password")); | 1263 | printf (" %s\n", _("SNMPv3 authentication password")); |
1166 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); | 1264 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); |
1167 | printf (" %s\n", _("SNMPv3 privacy password")); | 1265 | printf (" %s\n", _("SNMPv3 privacy password")); |
@@ -1176,6 +1274,14 @@ print_help (void) | |||
1176 | printf (" %s \"%s\"\n", _("Delimiter to use when parsing returned data. Default is"), DEFAULT_DELIMITER); | 1274 | printf (" %s \"%s\"\n", _("Delimiter to use when parsing returned data. Default is"), DEFAULT_DELIMITER); |
1177 | printf (" %s\n", _("Any data on the right hand side of the delimiter is considered")); | 1275 | printf (" %s\n", _("Any data on the right hand side of the delimiter is considered")); |
1178 | printf (" %s\n", _("to be the data that should be used in the evaluation.")); | 1276 | printf (" %s\n", _("to be the data that should be used in the evaluation.")); |
1277 | printf (" %s\n", "-z, --nulloid=#"); | ||
1278 | printf (" %s\n", _("If the check returns a 0 length string or NULL value")); | ||
1279 | printf (" %s\n", _("This option allows you to choose what status you want it to exit")); | ||
1280 | printf (" %s\n", _("Excluding this option renders the default exit of 3(STATE_UNKNOWN)")); | ||
1281 | printf (" %s\n", _("0 = OK")); | ||
1282 | printf (" %s\n", _("1 = WARNING")); | ||
1283 | printf (" %s\n", _("2 = CRITICAL")); | ||
1284 | printf (" %s\n", _("3 = UNKNOWN")); | ||
1179 | 1285 | ||
1180 | /* Tests Against Integers */ | 1286 | /* Tests Against Integers */ |
1181 | printf (" %s\n", "-w, --warning=THRESHOLD(s)"); | 1287 | printf (" %s\n", "-w, --warning=THRESHOLD(s)"); |
@@ -1187,7 +1293,7 @@ print_help (void) | |||
1187 | printf (" %s\n", "--rate-multiplier"); | 1293 | printf (" %s\n", "--rate-multiplier"); |
1188 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); | 1294 | printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); |
1189 | printf (" %s\n", "--offset=OFFSET"); | 1295 | printf (" %s\n", "--offset=OFFSET"); |
1190 | printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data")); | 1296 | printf (" %s\n", _("Add/subtract the specified OFFSET to numeric sensor data")); |
1191 | 1297 | ||
1192 | /* Tests Against Strings */ | 1298 | /* Tests Against Strings */ |
1193 | printf (" %s\n", "-s, --string=STRING"); | 1299 | printf (" %s\n", "-s, --string=STRING"); |
@@ -1206,6 +1312,10 @@ print_help (void) | |||
1206 | printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.').")); | 1312 | printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.').")); |
1207 | printf (" %s\n", "-D, --output-delimiter=STRING"); | 1313 | printf (" %s\n", "-D, --output-delimiter=STRING"); |
1208 | printf (" %s\n", _("Separates output on multiple OID requests")); | 1314 | printf (" %s\n", _("Separates output on multiple OID requests")); |
1315 | printf (" %s\n", "-M, --multiplier=FLOAT"); | ||
1316 | printf (" %s\n", _("Multiplies current value, 0 < n < 1 works as divider, defaults to 1")); | ||
1317 | printf (" %s\n", "-f, --fmtstr=STRING"); | ||
1318 | printf (" %s\n", _("C-style format string for float values (see option -M)")); | ||
1209 | 1319 | ||
1210 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 1320 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
1211 | printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5")); | 1321 | printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5")); |
@@ -1215,6 +1325,9 @@ print_help (void) | |||
1215 | printf (" %s\n", "-O, --perf-oids"); | 1325 | printf (" %s\n", "-O, --perf-oids"); |
1216 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1326 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
1217 | 1327 | ||
1328 | printf (" %s\n", "--ignore-mib-parsing-errors"); | ||
1329 | printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files")); | ||
1330 | |||
1218 | printf (UT_VERBOSE); | 1331 | printf (UT_VERBOSE); |
1219 | 1332 | ||
1220 | printf ("\n"); | 1333 | printf ("\n"); |
@@ -1258,4 +1371,5 @@ print_usage (void) | |||
1258 | printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); | 1371 | printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n"); |
1259 | printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); | 1372 | printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n"); |
1260 | printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n"); | 1373 | printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n"); |
1374 | printf ("[-M multiplier [-f format]]\n"); | ||
1261 | } | 1375 | } |