summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLorenz <12514511+RincewindsHat@users.noreply.github.com>2022-01-14 15:04:36 (GMT)
committerGitHub <noreply@github.com>2022-01-14 15:04:36 (GMT)
commit54a3a5ea623e5cfd65d810f4b6792f199470b2d4 (patch)
treeedf2b66cfa4d9473255bf98263396aea69b095a6
parentd999db01c07558ec9242f6e6a435a5d215d76ed6 (diff)
parent69fed9d08363085e8f6689bc8c9df2e9ad0f4cdb (diff)
downloadmonitoring-plugins-54a3a5ea623e5cfd65d810f4b6792f199470b2d4.tar.gz
Merge pull request #1496 from FracKenA/Add-NullOID-Exit
Added option for null zero length string exit codes
-rw-r--r--plugins/check_snmp.c30
1 files changed, 27 insertions, 3 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index abe54cf..bd13e57 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -113,6 +113,7 @@ char *authproto = NULL;
113char *privproto = NULL; 113char *privproto = NULL;
114char *authpasswd = NULL; 114char *authpasswd = NULL;
115char *privpasswd = NULL; 115char *privpasswd = NULL;
116int nulloid = STATE_UNKNOWN;
116char **oids = NULL; 117char **oids = NULL;
117size_t oids_size = 0; 118size_t oids_size = 0;
118char *label; 119char *label;
@@ -472,8 +473,16 @@ main (int argc, char **argv)
472 print_thresholds(" thresholds", thlds[i]); 473 print_thresholds(" thresholds", thlds[i]);
473 } 474 }
474 ptr = strpbrk (show, "-0123456789"); 475 ptr = strpbrk (show, "-0123456789");
475 if (ptr == NULL) 476 if (ptr == NULL){
476 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 }
477 while (i >= response_size) { 486 while (i >= response_size) {
478 response_size += OID_COUNT_STEP; 487 response_size += OID_COUNT_STEP;
479 response_value = realloc(response_value, response_size * sizeof(*response_value)); 488 response_value = realloc(response_value, response_size * sizeof(*response_value));
@@ -661,6 +670,7 @@ process_arguments (int argc, char **argv)
661 {"oid", required_argument, 0, 'o'}, 670 {"oid", required_argument, 0, 'o'},
662 {"object", required_argument, 0, 'o'}, 671 {"object", required_argument, 0, 'o'},
663 {"delimiter", required_argument, 0, 'd'}, 672 {"delimiter", required_argument, 0, 'd'},
673 {"nulloid", required_argument, 0, 'z'},
664 {"output-delimiter", required_argument, 0, 'D'}, 674 {"output-delimiter", required_argument, 0, 'D'},
665 {"string", required_argument, 0, 's'}, 675 {"string", required_argument, 0, 's'},
666 {"timeout", required_argument, 0, 't'}, 676 {"timeout", required_argument, 0, 't'},
@@ -705,7 +715,7 @@ process_arguments (int argc, char **argv)
705 } 715 }
706 716
707 while (1) { 717 while (1) {
708 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:",
709 longopts, &option); 719 longopts, &option);
710 720
711 if (c == -1 || c == EOF) 721 if (c == -1 || c == EOF)
@@ -816,6 +826,12 @@ process_arguments (int argc, char **argv)
816 eval_method[j+1] |= CRIT_PRESENT; 826 eval_method[j+1] |= CRIT_PRESENT;
817 } 827 }
818 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;
819 case 's': /* string or substring */ 835 case 's': /* string or substring */
820 strncpy (string_value, optarg, sizeof (string_value) - 1); 836 strncpy (string_value, optarg, sizeof (string_value) - 1);
821 string_value[sizeof (string_value) - 1] = 0; 837 string_value[sizeof (string_value) - 1] = 0;
@@ -1181,6 +1197,14 @@ print_help (void)
1181 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);
1182 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"));
1183 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"));
1184 1208
1185 /* Tests Against Integers */ 1209 /* Tests Against Integers */
1186 printf (" %s\n", "-w, --warning=THRESHOLD(s)"); 1210 printf (" %s\n", "-w, --warning=THRESHOLD(s)");