summaryrefslogtreecommitdiffstats
path: root/plugins/check_snmp.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r--plugins/check_snmp.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index bf21022..d387104 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -62,6 +62,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
62/* Longopts only arguments */ 62/* Longopts only arguments */
63#define L_CALCULATE_RATE CHAR_MAX+1 63#define L_CALCULATE_RATE CHAR_MAX+1
64#define L_RATE_MULTIPLIER CHAR_MAX+2 64#define L_RATE_MULTIPLIER CHAR_MAX+2
65#define L_INVERT_SEARCH CHAR_MAX+3
65 66
66/* Gobble to string - stop incrementing c when c[0] match one of the 67/* Gobble to string - stop incrementing c when c[0] match one of the
67 * characters in s */ 68 * characters in s */
@@ -115,6 +116,7 @@ char *units;
115char *port; 116char *port;
116char *snmpcmd; 117char *snmpcmd;
117char string_value[MAX_INPUT_BUFFER] = ""; 118char string_value[MAX_INPUT_BUFFER] = "";
119int invert_search=0;
118char **labels = NULL; 120char **labels = NULL;
119char **unitv = NULL; 121char **unitv = NULL;
120size_t nlabels = 0; 122size_t nlabels = 0;
@@ -433,16 +435,16 @@ main (int argc, char **argv)
433 /* Process this block for string matching */ 435 /* Process this block for string matching */
434 else if (eval_method[i] & CRIT_STRING) { 436 else if (eval_method[i] & CRIT_STRING) {
435 if (strcmp (show, string_value)) 437 if (strcmp (show, string_value))
436 iresult = STATE_CRITICAL; 438 iresult = (invert_search==0) ? STATE_CRITICAL : STATE_OK;
437 else 439 else
438 iresult = STATE_OK; 440 iresult = (invert_search==0) ? STATE_OK : STATE_CRITICAL;
439 } 441 }
440 442
441 /* Process this block for regex matching */ 443 /* Process this block for regex matching */
442 else if (eval_method[i] & CRIT_REGEX) { 444 else if (eval_method[i] & CRIT_REGEX) {
443 excode = regexec (&preg, response, 10, pmatch, eflags); 445 excode = regexec (&preg, response, 10, pmatch, eflags);
444 if (excode == 0) { 446 if (excode == 0) {
445 iresult = STATE_OK; 447 iresult = (invert_search==0) ? STATE_OK : STATE_CRITICAL;
446 } 448 }
447 else if (excode != REG_NOMATCH) { 449 else if (excode != REG_NOMATCH) {
448 regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER); 450 regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER);
@@ -450,7 +452,7 @@ main (int argc, char **argv)
450 exit (STATE_CRITICAL); 452 exit (STATE_CRITICAL);
451 } 453 }
452 else { 454 else {
453 iresult = STATE_CRITICAL; 455 iresult = (invert_search==0) ? STATE_CRITICAL : STATE_OK;
454 } 456 }
455 } 457 }
456 458
@@ -584,6 +586,7 @@ process_arguments (int argc, char **argv)
584 {"next", no_argument, 0, 'n'}, 586 {"next", no_argument, 0, 'n'},
585 {"rate", no_argument, 0, L_CALCULATE_RATE}, 587 {"rate", no_argument, 0, L_CALCULATE_RATE},
586 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, 588 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER},
589 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
587 {0, 0, 0, 0} 590 {0, 0, 0, 0}
588 }; 591 };
589 592
@@ -796,6 +799,9 @@ process_arguments (int argc, char **argv)
796 if(!is_integer(optarg)||(rate_multiplier=atoi(optarg)<=0)) 799 if(!is_integer(optarg)||(rate_multiplier=atoi(optarg)<=0))
797 usage2(_("Rate multiplier must be a positive integer"),optarg); 800 usage2(_("Rate multiplier must be a positive integer"),optarg);
798 break; 801 break;
802 case L_INVERT_SEARCH:
803 invert_search=1;
804 break;
799 } 805 }
800 } 806 }
801 807
@@ -1044,10 +1050,12 @@ print_help (void)
1044 printf (" %s\n", _("Return OK state (for that OID) if extended regular expression REGEX matches")); 1050 printf (" %s\n", _("Return OK state (for that OID) if extended regular expression REGEX matches"));
1045 printf (" %s\n", "-R, --eregi=REGEX"); 1051 printf (" %s\n", "-R, --eregi=REGEX");
1046 printf (" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches")); 1052 printf (" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches"));
1047 printf (" %s\n", "-l, --label=STRING"); 1053 printf (" %s\n", "--invert-search");
1048 printf (" %s\n", _("Prefix label for output from plugin (default -l 'SNMP')")); 1054 printf (" %s\n", _("Invert search result (CRITICAL if found)"));
1049 1055
1050 /* Output Formatting */ 1056 /* Output Formatting */
1057 printf (" %s\n", "-l, --label=STRING");
1058 printf (" %s\n", _("Prefix label for output from plugin"));
1051 printf (" %s\n", "-u, --units=STRING"); 1059 printf (" %s\n", "-u, --units=STRING");
1052 printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.').")); 1060 printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.')."));
1053 printf (" %s\n", "-D, --output-delimiter=STRING"); 1061 printf (" %s\n", "-D, --output-delimiter=STRING");