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.c53
1 files changed, 32 insertions, 21 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index c73562ba..9ca845d7 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -63,6 +63,7 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net";
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#define L_INVERT_SEARCH CHAR_MAX+3
66#define L_OFFSET CHAR_MAX+4
66 67
67/* Gobble to string - stop incrementing c when c[0] match one of the 68/* Gobble to string - stop incrementing c when c[0] match one of the
68 * characters in s */ 69 * characters in s */
@@ -142,6 +143,7 @@ char *output_delim;
142char *miblist = NULL; 143char *miblist = NULL;
143int needmibs = FALSE; 144int needmibs = FALSE;
144int calculate_rate = 0; 145int calculate_rate = 0;
146double offset = 0.0;
145int rate_multiplier = 1; 147int rate_multiplier = 1;
146state_data *previous_state; 148state_data *previous_state;
147double *previous_value; 149double *previous_value;
@@ -153,16 +155,18 @@ static char *fix_snmp_range(char *th)
153{ 155{
154 double left, right; 156 double left, right;
155 char *colon, *ret; 157 char *colon, *ret;
156 if (!(colon = strchr(th, ':'))) 158
159 if ((colon = strchr(th, ':')) == NULL || *(colon + 1) == '\0')
157 return th; 160 return th;
158 *colon = 0;
159 161
160 left = strtod(th, NULL); 162 left = strtod(th, NULL);
161 right = strtod(colon + 1, NULL); 163 right = strtod(colon + 1, NULL);
162 if (right >= left) { 164 if (right >= left)
163 return th; 165 return th;
164 } 166
165 ret = malloc(strlen(th) + strlen(colon + 1) + 2); 167 if ((ret = malloc(strlen(th) + 2)) == NULL)
168 die(STATE_UNKNOWN, _("Cannot malloc"));
169 *colon = '\0';
166 sprintf(ret, "@%s:%s", colon + 1, th); 170 sprintf(ret, "@%s:%s", colon + 1, th);
167 free(th); 171 free(th);
168 return ret; 172 return ret;
@@ -292,35 +296,36 @@ main (int argc, char **argv)
292 snmpcmd = strdup (PATH_TO_SNMPGET); 296 snmpcmd = strdup (PATH_TO_SNMPGET);
293 } 297 }
294 298
295 /* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ 299 /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */
296 command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); 300 command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *));
297 command_line[0] = snmpcmd; 301 command_line[0] = snmpcmd;
298 command_line[1] = strdup ("-t"); 302 command_line[1] = strdup ("-Le");
299 xasprintf (&command_line[2], "%d", timeout_interval); 303 command_line[2] = strdup ("-t");
300 command_line[3] = strdup ("-r"); 304 xasprintf (&command_line[3], "%d", timeout_interval);
301 xasprintf (&command_line[4], "%d", retries); 305 command_line[4] = strdup ("-r");
302 command_line[5] = strdup ("-m"); 306 xasprintf (&command_line[5], "%d", retries);
303 command_line[6] = strdup (miblist); 307 command_line[6] = strdup ("-m");
304 command_line[7] = "-v"; 308 command_line[7] = strdup (miblist);
305 command_line[8] = strdup (proto); 309 command_line[8] = "-v";
310 command_line[9] = strdup (proto);
306 311
307 for (i = 0; i < numauthpriv; i++) { 312 for (i = 0; i < numauthpriv; i++) {
308 command_line[9 + i] = authpriv[i]; 313 command_line[10 + i] = authpriv[i];
309 } 314 }
310 315
311 xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); 316 xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port);
312 317
313 /* This is just for display purposes, so it can remain a string */ 318 /* This is just for display purposes, so it can remain a string */
314 xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", 319 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s",
315 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", 320 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]",
316 server_address, port); 321 server_address, port);
317 322
318 for (i = 0; i < numoids; i++) { 323 for (i = 0; i < numoids; i++) {
319 command_line[9 + numauthpriv + 1 + i] = oids[i]; 324 command_line[10 + numauthpriv + 1 + i] = oids[i];
320 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 325 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
321 } 326 }
322 327
323 command_line[9 + numauthpriv + 1 + numoids] = NULL; 328 command_line[10 + numauthpriv + 1 + numoids] = NULL;
324 329
325 if (verbose) 330 if (verbose)
326 printf ("%s\n", cl_hidden_auth); 331 printf ("%s\n", cl_hidden_auth);
@@ -451,7 +456,7 @@ main (int argc, char **argv)
451 response_size += OID_COUNT_STEP; 456 response_size += OID_COUNT_STEP;
452 response_value = realloc(response_value, response_size * sizeof(*response_value)); 457 response_value = realloc(response_value, response_size * sizeof(*response_value));
453 } 458 }
454 response_value[i] = strtod (ptr, NULL); 459 response_value[i] = strtod (ptr, NULL) + offset;
455 460
456 if(calculate_rate) { 461 if(calculate_rate) {
457 if (previous_state!=NULL) { 462 if (previous_state!=NULL) {
@@ -640,6 +645,7 @@ process_arguments (int argc, char **argv)
640 {"next", no_argument, 0, 'n'}, 645 {"next", no_argument, 0, 'n'},
641 {"rate", no_argument, 0, L_CALCULATE_RATE}, 646 {"rate", no_argument, 0, L_CALCULATE_RATE},
642 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, 647 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER},
648 {"offset", required_argument, 0, L_OFFSET},
643 {"invert-search", no_argument, 0, L_INVERT_SEARCH}, 649 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
644 {"perf-oids", no_argument, 0, 'O'}, 650 {"perf-oids", no_argument, 0, 'O'},
645 {0, 0, 0, 0} 651 {0, 0, 0, 0}
@@ -872,6 +878,9 @@ process_arguments (int argc, char **argv)
872 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) 878 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0))
873 usage2(_("Rate multiplier must be a positive integer"),optarg); 879 usage2(_("Rate multiplier must be a positive integer"),optarg);
874 break; 880 break;
881 case L_OFFSET:
882 offset=strtod(optarg,NULL);
883 break;
875 case L_INVERT_SEARCH: 884 case L_INVERT_SEARCH:
876 invert_search=1; 885 invert_search=1;
877 break; 886 break;
@@ -1120,6 +1129,8 @@ print_help (void)
1120 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); 1129 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below"));
1121 printf (" %s\n", "--rate-multiplier"); 1130 printf (" %s\n", "--rate-multiplier");
1122 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); 1131 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute"));
1132 printf (" %s\n", "--offset=OFFSET");
1133 printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data"));
1123 1134
1124 /* Tests Against Strings */ 1135 /* Tests Against Strings */
1125 printf (" %s\n", "-s, --string=STRING"); 1136 printf (" %s\n", "-s, --string=STRING");