diff options
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 405ede3..01bee23 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -131,7 +131,7 @@ size_t nlabels = 0; | |||
131 | size_t labels_size = OID_COUNT_STEP; | 131 | size_t labels_size = OID_COUNT_STEP; |
132 | size_t nunits = 0; | 132 | size_t nunits = 0; |
133 | size_t unitv_size = OID_COUNT_STEP; | 133 | size_t unitv_size = OID_COUNT_STEP; |
134 | int numoids = 0; | 134 | size_t numoids = 0; |
135 | int numauthpriv = 0; | 135 | int numauthpriv = 0; |
136 | int numcontext = 0; | 136 | int numcontext = 0; |
137 | int verbose = 0; | 137 | int verbose = 0; |
@@ -187,7 +187,8 @@ static char *fix_snmp_range(char *th) | |||
187 | int | 187 | int |
188 | main (int argc, char **argv) | 188 | main (int argc, char **argv) |
189 | { | 189 | { |
190 | int i, len, line, total_oids; | 190 | int len, total_oids; |
191 | size_t line; | ||
191 | unsigned int bk_count = 0, dq_count = 0; | 192 | unsigned int bk_count = 0, dq_count = 0; |
192 | int iresult = STATE_UNKNOWN; | 193 | int iresult = STATE_UNKNOWN; |
193 | int result = STATE_UNKNOWN; | 194 | int result = STATE_UNKNOWN; |
@@ -253,7 +254,9 @@ main (int argc, char **argv) | |||
253 | if(calculate_rate) { | 254 | if(calculate_rate) { |
254 | if (!strcmp(label, "SNMP")) | 255 | if (!strcmp(label, "SNMP")) |
255 | label = strdup("SNMP RATE"); | 256 | label = strdup("SNMP RATE"); |
256 | i=0; | 257 | |
258 | size_t i = 0; | ||
259 | |||
257 | previous_state = np_state_read(); | 260 | previous_state = np_state_read(); |
258 | if(previous_state!=NULL) { | 261 | if(previous_state!=NULL) { |
259 | /* Split colon separated values */ | 262 | /* Split colon separated values */ |
@@ -273,7 +276,7 @@ main (int argc, char **argv) | |||
273 | /* Populate the thresholds */ | 276 | /* Populate the thresholds */ |
274 | th_warn=warning_thresholds; | 277 | th_warn=warning_thresholds; |
275 | th_crit=critical_thresholds; | 278 | th_crit=critical_thresholds; |
276 | for (i=0; i<numoids; i++) { | 279 | for (size_t i = 0; i < numoids; i++) { |
277 | char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; | 280 | char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; |
278 | char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; | 281 | char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; |
279 | /* translate "2:1" to "@1:2" for backwards compatibility */ | 282 | /* translate "2:1" to "@1:2" for backwards compatibility */ |
@@ -333,11 +336,11 @@ main (int argc, char **argv) | |||
333 | } | 336 | } |
334 | 337 | ||
335 | 338 | ||
336 | for (i = 0; i < numcontext; i++) { | 339 | for (int i = 0; i < numcontext; i++) { |
337 | command_line[index++] = contextargs[i]; | 340 | command_line[index++] = contextargs[i]; |
338 | } | 341 | } |
339 | 342 | ||
340 | for (i = 0; i < numauthpriv; i++) { | 343 | for (int i = 0; i < numauthpriv; i++) { |
341 | command_line[index++] = authpriv[i]; | 344 | command_line[index++] = authpriv[i]; |
342 | } | 345 | } |
343 | 346 | ||
@@ -348,7 +351,7 @@ main (int argc, char **argv) | |||
348 | server_address, | 351 | server_address, |
349 | port); | 352 | port); |
350 | 353 | ||
351 | for (i = 0; i < numoids; i++) { | 354 | for (size_t i = 0; i < numoids; i++) { |
352 | command_line[index++] = oids[i]; | 355 | command_line[index++] = oids[i]; |
353 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); | 356 | xasprintf(&cl_hidden_auth, "%s %s", cl_hidden_auth, oids[i]); |
354 | } | 357 | } |
@@ -382,7 +385,7 @@ main (int argc, char **argv) | |||
382 | if (external_error) { | 385 | if (external_error) { |
383 | if (chld_err.lines > 0) { | 386 | if (chld_err.lines > 0) { |
384 | printf (_("External command error: %s\n"), chld_err.line[0]); | 387 | printf (_("External command error: %s\n"), chld_err.line[0]); |
385 | for (i = 1; i < chld_err.lines; i++) { | 388 | for (size_t i = 1; i < chld_err.lines; i++) { |
386 | printf ("%s\n", chld_err.line[i]); | 389 | printf ("%s\n", chld_err.line[i]); |
387 | } | 390 | } |
388 | } else { | 391 | } else { |
@@ -392,12 +395,14 @@ main (int argc, char **argv) | |||
392 | } | 395 | } |
393 | 396 | ||
394 | if (verbose) { | 397 | if (verbose) { |
395 | for (i = 0; i < chld_out.lines; i++) { | 398 | for (size_t i = 0; i < chld_out.lines; i++) { |
396 | printf ("%s\n", chld_out.line[i]); | 399 | printf ("%s\n", chld_out.line[i]); |
397 | } | 400 | } |
398 | } | 401 | } |
399 | 402 | ||
400 | for (line=0, i=0; line < chld_out.lines && i < numoids ; line++, i++) { | 403 | line = 0; |
404 | total_oids = 0; | ||
405 | for (size_t i = 0; line < chld_out.lines && i < numoids ; line++, i++, total_oids++) { | ||
401 | if(calculate_rate) | 406 | if(calculate_rate) |
402 | conv = "%.10g"; | 407 | conv = "%.10g"; |
403 | else | 408 | else |
@@ -634,7 +639,6 @@ main (int argc, char **argv) | |||
634 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); | 639 | strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); |
635 | } | 640 | } |
636 | } | 641 | } |
637 | total_oids=i; | ||
638 | 642 | ||
639 | /* Save state data, as all data collected now */ | 643 | /* Save state data, as all data collected now */ |
640 | if(calculate_rate) { | 644 | if(calculate_rate) { |
@@ -644,7 +648,7 @@ main (int argc, char **argv) | |||
644 | die(STATE_UNKNOWN, _("Cannot malloc")); | 648 | die(STATE_UNKNOWN, _("Cannot malloc")); |
645 | 649 | ||
646 | current_length=0; | 650 | current_length=0; |
647 | for(i=0; i<total_oids; i++) { | 651 | for(int i = 0; i < total_oids; i++) { |
648 | xasprintf(&temp_string,"%.0f",response_value[i]); | 652 | xasprintf(&temp_string,"%.0f",response_value[i]); |
649 | if(temp_string==NULL) | 653 | if(temp_string==NULL) |
650 | die(STATE_UNKNOWN,_("Cannot asprintf()")); | 654 | die(STATE_UNKNOWN,_("Cannot asprintf()")); |
@@ -687,7 +691,8 @@ process_arguments (int argc, char **argv) | |||
687 | { | 691 | { |
688 | char *ptr; | 692 | char *ptr; |
689 | int c = 1; | 693 | int c = 1; |
690 | int j = 0, jj = 0, ii = 0; | 694 | int ii = 0; |
695 | size_t j = 0, jj = 0; | ||
691 | 696 | ||
692 | int option = 0; | 697 | int option = 0; |
693 | static struct option longopts[] = { | 698 | static struct option longopts[] = { |