diff options
Diffstat (limited to 'plugins/check_snmp.c')
-rw-r--r-- | plugins/check_snmp.c | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index e22d8a0b..af8f1198 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -84,7 +84,7 @@ int errcode, excode; | |||
84 | #endif | 84 | #endif |
85 | 85 | ||
86 | char *server_address = NULL; | 86 | char *server_address = NULL; |
87 | char *community = DEFAULT_COMMUNITY; | 87 | char *community = NULL; |
88 | char *authpriv = NULL; | 88 | char *authpriv = NULL; |
89 | char *proto = NULL; | 89 | char *proto = NULL; |
90 | char *seclevel = NULL; | 90 | char *seclevel = NULL; |
@@ -92,17 +92,17 @@ char *secname = NULL; | |||
92 | char *authproto = NULL; | 92 | char *authproto = NULL; |
93 | char *authpasswd = NULL; | 93 | char *authpasswd = NULL; |
94 | char *privpasswd = NULL; | 94 | char *privpasswd = NULL; |
95 | char *oid = ""; | 95 | char *oid; |
96 | char *label = "SNMP"; | 96 | char *label; |
97 | char *units = ""; | 97 | char *units; |
98 | char *port = DEFAULT_PORT; | 98 | char *port; |
99 | char string_value[MAX_INPUT_BUFFER] = ""; | 99 | char string_value[MAX_INPUT_BUFFER] = ""; |
100 | char **labels = NULL; | 100 | char **labels = NULL; |
101 | char **unitv = NULL; | 101 | char **unitv = NULL; |
102 | int nlabels = 0; | 102 | size_t nlabels = 0; |
103 | int labels_size = 8; | 103 | size_t labels_size = 8; |
104 | int nunits = 0; | 104 | size_t nunits = 0; |
105 | int unitv_size = 8; | 105 | size_t unitv_size = 8; |
106 | int verbose = FALSE; | 106 | int verbose = FALSE; |
107 | unsigned long lower_warn_lim[MAX_OIDS]; | 107 | unsigned long lower_warn_lim[MAX_OIDS]; |
108 | unsigned long upper_warn_lim[MAX_OIDS]; | 108 | unsigned long upper_warn_lim[MAX_OIDS]; |
@@ -112,9 +112,9 @@ unsigned long response_value[MAX_OIDS]; | |||
112 | int check_warning_value = FALSE; | 112 | int check_warning_value = FALSE; |
113 | int check_critical_value = FALSE; | 113 | int check_critical_value = FALSE; |
114 | int eval_method[MAX_OIDS]; | 114 | int eval_method[MAX_OIDS]; |
115 | char *delimiter = DEFAULT_DELIMITER; | 115 | char *delimiter; |
116 | char *output_delim = DEFAULT_OUTPUT_DELIMITER; | 116 | char *output_delim; |
117 | char *miblist = DEFAULT_MIBLIST; | 117 | char *miblist; |
118 | 118 | ||
119 | 119 | ||
120 | 120 | ||
@@ -131,8 +131,8 @@ main (int argc, char **argv) | |||
131 | char input_buffer[MAX_INPUT_BUFFER]; | 131 | char input_buffer[MAX_INPUT_BUFFER]; |
132 | char *command_line = NULL; | 132 | char *command_line = NULL; |
133 | char *response = NULL; | 133 | char *response = NULL; |
134 | char *outbuff = ""; | 134 | char *outbuff; |
135 | char *output = ""; | 135 | char *output; |
136 | char *ptr = NULL; | 136 | char *ptr = NULL; |
137 | char *p2 = NULL; | 137 | char *p2 = NULL; |
138 | char *show = NULL; | 138 | char *show = NULL; |
@@ -143,6 +143,16 @@ main (int argc, char **argv) | |||
143 | eval_method[i] = CHECK_UNDEF; | 143 | eval_method[i] = CHECK_UNDEF; |
144 | i = 0; | 144 | i = 0; |
145 | 145 | ||
146 | oid = strdup (""); | ||
147 | label = strdup ("SNMP"); | ||
148 | units = strdup (""); | ||
149 | port = strdup (DEFAULT_PORT); | ||
150 | outbuff = strdup (""); | ||
151 | output = strdup (""); | ||
152 | delimiter = strdup (DEFAULT_DELIMITER); | ||
153 | output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); | ||
154 | miblist = strdup (DEFAULT_MIBLIST); | ||
155 | |||
146 | if (process_arguments (argc, argv) == ERROR) | 156 | if (process_arguments (argc, argv) == ERROR) |
147 | usage (_("Incorrect arguments supplied\n")); | 157 | usage (_("Incorrect arguments supplied\n")); |
148 | 158 | ||
@@ -287,7 +297,7 @@ main (int argc, char **argv) | |||
287 | result = max_state (result, iresult); | 297 | result = max_state (result, iresult); |
288 | 298 | ||
289 | /* Prepend a label for this OID if there is one */ | 299 | /* Prepend a label for this OID if there is one */ |
290 | if (nlabels > 1 && i < nlabels && labels[i] != NULL) | 300 | if (nlabels > (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) |
291 | asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, | 301 | asprintf (&outbuff, "%s%s%s %s%s%s", outbuff, |
292 | (i == 0) ? " " : output_delim, | 302 | (i == 0) ? " " : output_delim, |
293 | labels[i], mark (iresult), show, mark (iresult)); | 303 | labels[i], mark (iresult), show, mark (iresult)); |
@@ -296,7 +306,7 @@ main (int argc, char **argv) | |||
296 | mark (iresult), show, mark (iresult)); | 306 | mark (iresult), show, mark (iresult)); |
297 | 307 | ||
298 | /* Append a unit string for this OID if there is one */ | 308 | /* Append a unit string for this OID if there is one */ |
299 | if (nunits > 0 && i < nunits && unitv[i] != NULL) | 309 | if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) |
300 | asprintf (&outbuff, "%s %s", outbuff, unitv[i]); | 310 | asprintf (&outbuff, "%s %s", outbuff, unitv[i]); |
301 | 311 | ||
302 | i++; | 312 | i++; |
@@ -341,8 +351,8 @@ process_arguments (int argc, char **argv) | |||
341 | int c = 1; | 351 | int c = 1; |
342 | int j = 0, jj = 0, ii = 0; | 352 | int j = 0, jj = 0, ii = 0; |
343 | 353 | ||
344 | int option_index = 0; | 354 | int option = 0; |
345 | static struct option long_options[] = { | 355 | static struct option longopts[] = { |
346 | STD_LONG_OPTS, | 356 | STD_LONG_OPTS, |
347 | {"community", required_argument, 0, 'C'}, | 357 | {"community", required_argument, 0, 'C'}, |
348 | {"oid", required_argument, 0, 'o'}, | 358 | {"oid", required_argument, 0, 'o'}, |
@@ -381,7 +391,7 @@ process_arguments (int argc, char **argv) | |||
381 | 391 | ||
382 | while (1) { | 392 | while (1) { |
383 | c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:", | 393 | c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:R:r:l:u:p:m:P:L:U:a:A:X:", |
384 | long_options, &option_index); | 394 | longopts, &option); |
385 | 395 | ||
386 | if (c == -1 || c == EOF) | 396 | if (c == -1 || c == EOF) |
387 | break; | 397 | break; |
@@ -401,34 +411,34 @@ process_arguments (int argc, char **argv) | |||
401 | 411 | ||
402 | /* Connection info */ | 412 | /* Connection info */ |
403 | case 'C': /* group or community */ | 413 | case 'C': /* group or community */ |
404 | community = strscpy (community, optarg); | 414 | community = optarg; |
405 | break; | 415 | break; |
406 | case 'H': /* Host or server */ | 416 | case 'H': /* Host or server */ |
407 | server_address = strscpy (server_address, optarg); | 417 | server_address = optarg; |
408 | break; | 418 | break; |
409 | case 'p': /* TCP port number */ | 419 | case 'p': /* TCP port number */ |
410 | port = strscpy(port, optarg); | 420 | port = optarg; |
411 | break; | 421 | break; |
412 | case 'm': /* List of MIBS */ | 422 | case 'm': /* List of MIBS */ |
413 | miblist = strscpy(miblist, optarg); | 423 | miblist = optarg; |
414 | break; | 424 | break; |
415 | case 'P': /* SNMP protocol version */ | 425 | case 'P': /* SNMP protocol version */ |
416 | proto = strscpy(proto, optarg); | 426 | proto = optarg; |
417 | break; | 427 | break; |
418 | case 'L': /* security level */ | 428 | case 'L': /* security level */ |
419 | seclevel = strscpy(seclevel,optarg); | 429 | seclevel = optarg; |
420 | break; | 430 | break; |
421 | case 'U': /* security username */ | 431 | case 'U': /* security username */ |
422 | secname = strscpy(secname, optarg); | 432 | secname = optarg; |
423 | break; | 433 | break; |
424 | case 'a': /* auth protocol */ | 434 | case 'a': /* auth protocol */ |
425 | asprintf (&authproto, optarg); | 435 | authproto = optarg; |
426 | break; | 436 | break; |
427 | case 'A': /* auth passwd */ | 437 | case 'A': /* auth passwd */ |
428 | authpasswd = strscpy(authpasswd, optarg); | 438 | authpasswd = optarg; |
429 | break; | 439 | break; |
430 | case 'X': /* priv passwd */ | 440 | case 'X': /* priv passwd */ |
431 | privpasswd = strscpy(privpasswd, optarg); | 441 | privpasswd = optarg; |
432 | break; | 442 | break; |
433 | case 't': /* timeout period */ | 443 | case 't': /* timeout period */ |
434 | if (!is_integer (optarg)) | 444 | if (!is_integer (optarg)) |
@@ -585,7 +595,10 @@ process_arguments (int argc, char **argv) | |||
585 | } | 595 | } |
586 | 596 | ||
587 | if (server_address == NULL) | 597 | if (server_address == NULL) |
588 | asprintf (&server_address, argv[optind]); | 598 | server_address = argv[optind]; |
599 | |||
600 | if (community == NULL) | ||
601 | community = strdup (DEFAULT_COMMUNITY); | ||
589 | 602 | ||
590 | return validate_arguments (); | 603 | return validate_arguments (); |
591 | } | 604 | } |