From dc1d1c46d6f9ca1a15609c126cf212bf3bb5ee4e Mon Sep 17 00:00:00 2001 From: Simon Kainz Date: Mon, 5 Aug 2013 23:00:21 +0200 Subject: added --offset option to allow adjustment of sensor data diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 3e8a9cf..cd50389 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c @@ -63,6 +63,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; #define L_CALCULATE_RATE CHAR_MAX+1 #define L_RATE_MULTIPLIER CHAR_MAX+2 #define L_INVERT_SEARCH CHAR_MAX+3 +#define L_OFFSET CHAR_MAX+4 /* Gobble to string - stop incrementing c when c[0] match one of the * characters in s */ @@ -138,6 +139,7 @@ char *output_delim; char *miblist = NULL; int needmibs = FALSE; int calculate_rate = 0; +double offset = 0.0; int rate_multiplier = 1; state_data *previous_state; double previous_value[MAX_OIDS]; @@ -430,7 +432,7 @@ main (int argc, char **argv) ptr = strpbrk (show, "0123456789"); if (ptr == NULL) die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); - response_value[i] = strtod (ptr, NULL); + response_value[i] = strtod (ptr, NULL)+offset; if(calculate_rate) { if (previous_state!=NULL) { @@ -619,6 +621,7 @@ process_arguments (int argc, char **argv) {"next", no_argument, 0, 'n'}, {"rate", no_argument, 0, L_CALCULATE_RATE}, {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, + {"offset", required_argument, 0, L_OFFSET}, {"invert-search", no_argument, 0, L_INVERT_SEARCH}, {"perf-oids", no_argument, 0, 'O'}, {0, 0, 0, 0} @@ -833,6 +836,9 @@ process_arguments (int argc, char **argv) if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) usage2(_("Rate multiplier must be a positive integer"),optarg); break; + case L_OFFSET: + offset=strtod(optarg,NULL); + break; case L_INVERT_SEARCH: invert_search=1; break; @@ -1081,6 +1087,8 @@ print_help (void) printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); printf (" %s\n", "--rate-multiplier"); printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); + printf (" %s\n", "--offset=OFFSET"); + printf (" %s\n", _("Allows to add/substract a value to numeric sensor data.")); /* Tests Against Strings */ printf (" %s\n", "-s, --string=STRING"); -- cgit v0.10-9-g596f