diff options
Diffstat (limited to 'plugins/check_snmp.c')
| -rw-r--r-- | plugins/check_snmp.c | 49 |
1 files changed, 40 insertions, 9 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index da9638c4..bd13e579 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
| @@ -113,6 +113,7 @@ char *authproto = NULL; | |||
| 113 | char *privproto = NULL; | 113 | char *privproto = NULL; |
| 114 | char *authpasswd = NULL; | 114 | char *authpasswd = NULL; |
| 115 | char *privpasswd = NULL; | 115 | char *privpasswd = NULL; |
| 116 | int nulloid = STATE_UNKNOWN; | ||
| 116 | char **oids = NULL; | 117 | char **oids = NULL; |
| 117 | size_t oids_size = 0; | 118 | size_t oids_size = 0; |
| 118 | char *label; | 119 | char *label; |
| @@ -468,9 +469,20 @@ main (int argc, char **argv) | |||
| 468 | /* Process this block for numeric comparisons */ | 469 | /* Process this block for numeric comparisons */ |
| 469 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ | 470 | /* Make some special values,like Timeticks numeric only if a threshold is defined */ |
| 470 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { | 471 | if (thlds[i]->warning || thlds[i]->critical || calculate_rate) { |
| 472 | if (verbose > 2) { | ||
| 473 | print_thresholds(" thresholds", thlds[i]); | ||
| 474 | } | ||
| 471 | ptr = strpbrk (show, "-0123456789"); | 475 | ptr = strpbrk (show, "-0123456789"); |
| 472 | if (ptr == NULL) | 476 | if (ptr == NULL){ |
| 473 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | 477 | if (nulloid == 3) |
| 478 | die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); | ||
| 479 | else if (nulloid == 0) | ||
| 480 | die (STATE_OK,_("No valid data returned (%s)\n"), show); | ||
| 481 | else if (nulloid == 1) | ||
| 482 | die (STATE_WARNING,_("No valid data returned (%s)\n"), show); | ||
| 483 | else if (nulloid == 2) | ||
| 484 | die (STATE_CRITICAL,_("No valid data returned (%s)\n"), show); | ||
| 485 | } | ||
| 474 | while (i >= response_size) { | 486 | while (i >= response_size) { |
| 475 | response_size += OID_COUNT_STEP; | 487 | response_size += OID_COUNT_STEP; |
| 476 | response_value = realloc(response_value, response_size * sizeof(*response_value)); | 488 | response_value = realloc(response_value, response_size * sizeof(*response_value)); |
| @@ -576,20 +588,23 @@ main (int argc, char **argv) | |||
| 576 | len = sizeof(perfstr)-strlen(perfstr)-1; | 588 | len = sizeof(perfstr)-strlen(perfstr)-1; |
| 577 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); | 589 | strncat(perfstr, show, len>ptr-show ? ptr-show : len); |
| 578 | 590 | ||
| 591 | if (type) | ||
| 592 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 593 | |||
| 579 | if (warning_thresholds) { | 594 | if (warning_thresholds) { |
| 580 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 595 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
| 581 | strncat(perfstr, warning_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 596 | if(thlds[i]->warning && thlds[i]->warning->text) |
| 597 | strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 582 | } | 598 | } |
| 583 | 599 | ||
| 584 | if (critical_thresholds) { | 600 | if (critical_thresholds) { |
| 585 | if (!warning_thresholds) | 601 | if (!warning_thresholds) |
| 586 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 602 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
| 587 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); | 603 | strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); |
| 588 | strncat(perfstr, critical_thresholds, sizeof(perfstr)-strlen(perfstr)-1); | 604 | if(thlds[i]->critical && thlds[i]->critical->text) |
| 605 | strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 589 | } | 606 | } |
| 590 | 607 | ||
| 591 | if (type) | ||
| 592 | strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); | ||
| 593 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 608 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
| 594 | } | 609 | } |
| 595 | } | 610 | } |
| @@ -655,6 +670,7 @@ process_arguments (int argc, char **argv) | |||
| 655 | {"oid", required_argument, 0, 'o'}, | 670 | {"oid", required_argument, 0, 'o'}, |
| 656 | {"object", required_argument, 0, 'o'}, | 671 | {"object", required_argument, 0, 'o'}, |
| 657 | {"delimiter", required_argument, 0, 'd'}, | 672 | {"delimiter", required_argument, 0, 'd'}, |
| 673 | {"nulloid", required_argument, 0, 'z'}, | ||
| 658 | {"output-delimiter", required_argument, 0, 'D'}, | 674 | {"output-delimiter", required_argument, 0, 'D'}, |
| 659 | {"string", required_argument, 0, 's'}, | 675 | {"string", required_argument, 0, 's'}, |
| 660 | {"timeout", required_argument, 0, 't'}, | 676 | {"timeout", required_argument, 0, 't'}, |
| @@ -699,7 +715,7 @@ process_arguments (int argc, char **argv) | |||
| 699 | } | 715 | } |
| 700 | 716 | ||
| 701 | while (1) { | 717 | while (1) { |
| 702 | 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:", | 718 | 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:z:", |
| 703 | longopts, &option); | 719 | longopts, &option); |
| 704 | 720 | ||
| 705 | if (c == -1 || c == EOF) | 721 | if (c == -1 || c == EOF) |
| @@ -810,6 +826,12 @@ process_arguments (int argc, char **argv) | |||
| 810 | eval_method[j+1] |= CRIT_PRESENT; | 826 | eval_method[j+1] |= CRIT_PRESENT; |
| 811 | } | 827 | } |
| 812 | break; | 828 | break; |
| 829 | case 'z': /* Null OID Return Check */ | ||
| 830 | if (!is_integer (optarg)) | ||
| 831 | usage2 (_("Exit status must be a positive integer"), optarg); | ||
| 832 | else | ||
| 833 | nulloid = atoi(optarg); | ||
| 834 | break; | ||
| 813 | case 's': /* string or substring */ | 835 | case 's': /* string or substring */ |
| 814 | strncpy (string_value, optarg, sizeof (string_value) - 1); | 836 | strncpy (string_value, optarg, sizeof (string_value) - 1); |
| 815 | string_value[sizeof (string_value) - 1] = 0; | 837 | string_value[sizeof (string_value) - 1] = 0; |
| @@ -1160,7 +1182,7 @@ print_help (void) | |||
| 1160 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); | 1182 | printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); |
| 1161 | printf (" %s\n", "-U, --secname=USERNAME"); | 1183 | printf (" %s\n", "-U, --secname=USERNAME"); |
| 1162 | printf (" %s\n", _("SNMPv3 username")); | 1184 | printf (" %s\n", _("SNMPv3 username")); |
| 1163 | printf (" %s\n", "-A, --authpassword=PASSWORD"); | 1185 | printf (" %s\n", "-A, --authpasswd=PASSWORD"); |
| 1164 | printf (" %s\n", _("SNMPv3 authentication password")); | 1186 | printf (" %s\n", _("SNMPv3 authentication password")); |
| 1165 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); | 1187 | printf (" %s\n", "-X, --privpasswd=PASSWORD"); |
| 1166 | printf (" %s\n", _("SNMPv3 privacy password")); | 1188 | printf (" %s\n", _("SNMPv3 privacy password")); |
| @@ -1175,6 +1197,14 @@ print_help (void) | |||
| 1175 | printf (" %s \"%s\"\n", _("Delimiter to use when parsing returned data. Default is"), DEFAULT_DELIMITER); | 1197 | printf (" %s \"%s\"\n", _("Delimiter to use when parsing returned data. Default is"), DEFAULT_DELIMITER); |
| 1176 | printf (" %s\n", _("Any data on the right hand side of the delimiter is considered")); | 1198 | printf (" %s\n", _("Any data on the right hand side of the delimiter is considered")); |
| 1177 | printf (" %s\n", _("to be the data that should be used in the evaluation.")); | 1199 | printf (" %s\n", _("to be the data that should be used in the evaluation.")); |
| 1200 | printf (" %s\n", "-z, --nulloid=#"); | ||
| 1201 | printf (" %s\n", _("If the check returns a 0 length string or NULL value")); | ||
| 1202 | printf (" %s\n", _("This option allows you to choose what status you want it to exit")); | ||
| 1203 | printf (" %s\n", _("Excluding this option renders the default exit of 3(STATE_UNKNOWN)")); | ||
| 1204 | printf (" %s\n", _("0 = OK")); | ||
| 1205 | printf (" %s\n", _("1 = WARNING")); | ||
| 1206 | printf (" %s\n", _("2 = CRITICAL")); | ||
| 1207 | printf (" %s\n", _("3 = UNKNOWN")); | ||
| 1178 | 1208 | ||
| 1179 | /* Tests Against Integers */ | 1209 | /* Tests Against Integers */ |
| 1180 | printf (" %s\n", "-w, --warning=THRESHOLD(s)"); | 1210 | printf (" %s\n", "-w, --warning=THRESHOLD(s)"); |
| @@ -1207,8 +1237,9 @@ print_help (void) | |||
| 1207 | printf (" %s\n", _("Separates output on multiple OID requests")); | 1237 | printf (" %s\n", _("Separates output on multiple OID requests")); |
| 1208 | 1238 | ||
| 1209 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); | 1239 | printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); |
| 1240 | printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5")); | ||
| 1210 | printf (" %s\n", "-e, --retries=INTEGER"); | 1241 | printf (" %s\n", "-e, --retries=INTEGER"); |
| 1211 | printf (" %s\n", _("Number of retries to be used in the requests")); | 1242 | printf (" %s%i\n", _("Number of retries to be used in the requests, default: "), DEFAULT_RETRIES); |
| 1212 | 1243 | ||
| 1213 | printf (" %s\n", "-O, --perf-oids"); | 1244 | printf (" %s\n", "-O, --perf-oids"); |
| 1214 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); | 1245 | printf (" %s\n", _("Label performance data with OIDs instead of --label's")); |
