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.c63
1 files changed, 36 insertions, 27 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 8a8ee18..7c3bc4b 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 */
@@ -138,6 +139,7 @@ char *output_delim;
138char *miblist = NULL; 139char *miblist = NULL;
139int needmibs = FALSE; 140int needmibs = FALSE;
140int calculate_rate = 0; 141int calculate_rate = 0;
142double offset = 0.0;
141int rate_multiplier = 1; 143int rate_multiplier = 1;
142state_data *previous_state; 144state_data *previous_state;
143double previous_value[MAX_OIDS]; 145double previous_value[MAX_OIDS];
@@ -200,8 +202,8 @@ main (int argc, char **argv)
200 bindtextdomain (PACKAGE, LOCALEDIR); 202 bindtextdomain (PACKAGE, LOCALEDIR);
201 textdomain (PACKAGE); 203 textdomain (PACKAGE);
202 204
203 labels = malloc (labels_size); 205 labels = malloc (labels_size * sizeof(*labels));
204 unitv = malloc (unitv_size); 206 unitv = malloc (unitv_size * sizeof(*unitv));
205 for (i = 0; i < MAX_OIDS; i++) 207 for (i = 0; i < MAX_OIDS; i++)
206 eval_method[i] = CHECK_UNDEF; 208 eval_method[i] = CHECK_UNDEF;
207 209
@@ -274,35 +276,36 @@ main (int argc, char **argv)
274 snmpcmd = strdup (PATH_TO_SNMPGET); 276 snmpcmd = strdup (PATH_TO_SNMPGET);
275 } 277 }
276 278
277 /* 9 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */ 279 /* 10 arguments to pass before authpriv options + 1 for host and numoids. Add one for terminating NULL */
278 command_line = calloc (9 + numauthpriv + 1 + numoids + 1, sizeof (char *)); 280 command_line = calloc (10 + numauthpriv + 1 + numoids + 1, sizeof (char *));
279 command_line[0] = snmpcmd; 281 command_line[0] = snmpcmd;
280 command_line[1] = strdup ("-t"); 282 command_line[1] = strdup ("-Le");
281 xasprintf (&command_line[2], "%d", timeout_interval); 283 command_line[2] = strdup ("-t");
282 command_line[3] = strdup ("-r"); 284 xasprintf (&command_line[3], "%d", timeout_interval);
283 xasprintf (&command_line[4], "%d", retries); 285 command_line[4] = strdup ("-r");
284 command_line[5] = strdup ("-m"); 286 xasprintf (&command_line[5], "%d", retries);
285 command_line[6] = strdup (miblist); 287 command_line[6] = strdup ("-m");
286 command_line[7] = "-v"; 288 command_line[7] = strdup (miblist);
287 command_line[8] = strdup (proto); 289 command_line[8] = "-v";
290 command_line[9] = strdup (proto);
288 291
289 for (i = 0; i < numauthpriv; i++) { 292 for (i = 0; i < numauthpriv; i++) {
290 command_line[9 + i] = authpriv[i]; 293 command_line[10 + i] = authpriv[i];
291 } 294 }
292 295
293 xasprintf (&command_line[9 + numauthpriv], "%s:%s", server_address, port); 296 xasprintf (&command_line[10 + numauthpriv], "%s:%s", server_address, port);
294 297
295 /* This is just for display purposes, so it can remain a string */ 298 /* This is just for display purposes, so it can remain a string */
296 xasprintf(&cl_hidden_auth, "%s -t %d -r %d -m %s -v %s %s %s:%s", 299 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s %s %s:%s",
297 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]", 300 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto, "[authpriv]",
298 server_address, port); 301 server_address, port);
299 302
300 for (i = 0; i < numoids; i++) { 303 for (i = 0; i < numoids; i++) {
301 command_line[9 + numauthpriv + 1 + i] = oids[i]; 304 command_line[10 + numauthpriv + 1 + i] = oids[i];
302 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); 305 xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]);
303 } 306 }
304 307
305 command_line[9 + numauthpriv + 1 + numoids] = NULL; 308 command_line[10 + numauthpriv + 1 + numoids] = NULL;
306 309
307 if (verbose) 310 if (verbose)
308 printf ("%s\n", cl_hidden_auth); 311 printf ("%s\n", cl_hidden_auth);
@@ -429,7 +432,7 @@ main (int argc, char **argv)
429 ptr = strpbrk (show, "0123456789"); 432 ptr = strpbrk (show, "0123456789");
430 if (ptr == NULL) 433 if (ptr == NULL)
431 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); 434 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show);
432 response_value[i] = strtod (ptr, NULL); 435 response_value[i] = strtod (ptr, NULL) + offset;
433 436
434 if(calculate_rate) { 437 if(calculate_rate) {
435 if (previous_state!=NULL) { 438 if (previous_state!=NULL) {
@@ -618,6 +621,7 @@ process_arguments (int argc, char **argv)
618 {"next", no_argument, 0, 'n'}, 621 {"next", no_argument, 0, 'n'},
619 {"rate", no_argument, 0, L_CALCULATE_RATE}, 622 {"rate", no_argument, 0, L_CALCULATE_RATE},
620 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, 623 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER},
624 {"offset", required_argument, 0, L_OFFSET},
621 {"invert-search", no_argument, 0, L_INVERT_SEARCH}, 625 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
622 {"perf-oids", no_argument, 0, 'O'}, 626 {"perf-oids", no_argument, 0, 'O'},
623 {0, 0, 0, 0} 627 {0, 0, 0, 0}
@@ -768,9 +772,9 @@ process_arguments (int argc, char **argv)
768 break; 772 break;
769 case 'l': /* label */ 773 case 'l': /* label */
770 nlabels++; 774 nlabels++;
771 if (nlabels >= labels_size) { 775 if (nlabels > labels_size) {
772 labels_size += 8; 776 labels_size += 8;
773 labels = realloc (labels, labels_size); 777 labels = realloc (labels, labels_size * sizeof(*labels));
774 if (labels == NULL) 778 if (labels == NULL)
775 die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); 779 die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels);
776 } 780 }
@@ -780,13 +784,13 @@ process_arguments (int argc, char **argv)
780 if (ptr[0] == '\'') 784 if (ptr[0] == '\'')
781 labels[nlabels - 1] = ptr + 1; 785 labels[nlabels - 1] = ptr + 1;
782 while (ptr && (ptr = nextarg (ptr))) { 786 while (ptr && (ptr = nextarg (ptr))) {
783 if (nlabels >= labels_size) { 787 nlabels++;
788 if (nlabels > labels_size) {
784 labels_size += 8; 789 labels_size += 8;
785 labels = realloc (labels, labels_size); 790 labels = realloc (labels, labels_size * sizeof(*labels));
786 if (labels == NULL) 791 if (labels == NULL)
787 die (STATE_UNKNOWN, _("Could not reallocate labels\n")); 792 die (STATE_UNKNOWN, _("Could not reallocate labels\n"));
788 } 793 }
789 nlabels++;
790 ptr = thisarg (ptr); 794 ptr = thisarg (ptr);
791 if (ptr[0] == '\'') 795 if (ptr[0] == '\'')
792 labels[nlabels - 1] = ptr + 1; 796 labels[nlabels - 1] = ptr + 1;
@@ -797,9 +801,9 @@ process_arguments (int argc, char **argv)
797 case 'u': /* units */ 801 case 'u': /* units */
798 units = optarg; 802 units = optarg;
799 nunits++; 803 nunits++;
800 if (nunits >= unitv_size) { 804 if (nunits > unitv_size) {
801 unitv_size += 8; 805 unitv_size += 8;
802 unitv = realloc (unitv, unitv_size); 806 unitv = realloc (unitv, unitv_size * sizeof(*unitv));
803 if (unitv == NULL) 807 if (unitv == NULL)
804 die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); 808 die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits);
805 } 809 }
@@ -809,9 +813,9 @@ process_arguments (int argc, char **argv)
809 if (ptr[0] == '\'') 813 if (ptr[0] == '\'')
810 unitv[nunits - 1] = ptr + 1; 814 unitv[nunits - 1] = ptr + 1;
811 while (ptr && (ptr = nextarg (ptr))) { 815 while (ptr && (ptr = nextarg (ptr))) {
812 if (nunits >= unitv_size) { 816 if (nunits > unitv_size) {
813 unitv_size += 8; 817 unitv_size += 8;
814 unitv = realloc (unitv, unitv_size); 818 unitv = realloc (unitv, unitv_size * sizeof(*unitv));
815 if (units == NULL) 819 if (units == NULL)
816 die (STATE_UNKNOWN, _("Could not realloc() units\n")); 820 die (STATE_UNKNOWN, _("Could not realloc() units\n"));
817 } 821 }
@@ -832,6 +836,9 @@ process_arguments (int argc, char **argv)
832 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) 836 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0))
833 usage2(_("Rate multiplier must be a positive integer"),optarg); 837 usage2(_("Rate multiplier must be a positive integer"),optarg);
834 break; 838 break;
839 case L_OFFSET:
840 offset=strtod(optarg,NULL);
841 break;
835 case L_INVERT_SEARCH: 842 case L_INVERT_SEARCH:
836 invert_search=1; 843 invert_search=1;
837 break; 844 break;
@@ -1080,6 +1087,8 @@ print_help (void)
1080 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); 1087 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below"));
1081 printf (" %s\n", "--rate-multiplier"); 1088 printf (" %s\n", "--rate-multiplier");
1082 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); 1089 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute"));
1090 printf (" %s\n", "--offset=OFFSET");
1091 printf (" %s\n", _("Add/substract the specified OFFSET to numeric sensor data"));
1083 1092
1084 /* Tests Against Strings */ 1093 /* Tests Against Strings */
1085 printf (" %s\n", "-s, --string=STRING"); 1094 printf (" %s\n", "-s, --string=STRING");