diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_snmp.c | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index ef411e1..0ef0c65 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -31,6 +31,8 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
31 | #define DEFAULT_PORT "161" | 31 | #define DEFAULT_PORT "161" |
32 | #define DEFAULT_MIBLIST "ALL" | 32 | #define DEFAULT_MIBLIST "ALL" |
33 | #define DEFAULT_PROTOCOL "1" | 33 | #define DEFAULT_PROTOCOL "1" |
34 | #define DEFAULT_TIMEOUT 1 | ||
35 | #define DEFAULT_RETRIES 5 | ||
34 | #define DEFAULT_AUTH_PROTOCOL "MD5" | 36 | #define DEFAULT_AUTH_PROTOCOL "MD5" |
35 | #define DEFAULT_DELIMITER "=" | 37 | #define DEFAULT_DELIMITER "=" |
36 | #define DEFAULT_OUTPUT_DELIMITER " " | 38 | #define DEFAULT_OUTPUT_DELIMITER " " |
@@ -113,13 +115,12 @@ unsigned long upper_crit_lim[MAX_OIDS]; | |||
113 | unsigned long response_value[MAX_OIDS]; | 115 | unsigned long response_value[MAX_OIDS]; |
114 | int check_warning_value = FALSE; | 116 | int check_warning_value = FALSE; |
115 | int check_critical_value = FALSE; | 117 | int check_critical_value = FALSE; |
118 | int retries = 0; | ||
116 | unsigned long eval_method[MAX_OIDS]; | 119 | unsigned long eval_method[MAX_OIDS]; |
117 | char *delimiter; | 120 | char *delimiter; |
118 | char *output_delim; | 121 | char *output_delim; |
119 | char *miblist; | 122 | char *miblist; |
120 | 123 | ||
121 | |||
122 | |||
123 | int | 124 | int |
124 | main (int argc, char **argv) | 125 | main (int argc, char **argv) |
125 | { | 126 | { |
@@ -155,13 +156,15 @@ main (int argc, char **argv) | |||
155 | delimiter = strdup (DEFAULT_DELIMITER); | 156 | delimiter = strdup (DEFAULT_DELIMITER); |
156 | output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); | 157 | output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); |
157 | miblist = strdup (DEFAULT_MIBLIST); | 158 | miblist = strdup (DEFAULT_MIBLIST); |
159 | timeout_interval = DEFAULT_TIMEOUT; | ||
160 | retries = DEFAULT_RETRIES; | ||
158 | 161 | ||
159 | if (process_arguments (argc, argv) == ERROR) | 162 | if (process_arguments (argc, argv) == ERROR) |
160 | usage4 (_("Could not parse arguments")); | 163 | usage4 (_("Could not parse arguments")); |
161 | 164 | ||
162 | /* create the command line to execute */ | 165 | /* create the command line to execute */ |
163 | asprintf (&command_line, "%s -t 1 -r %d -m %s -v %s %s %s:%s %s", | 166 | asprintf (&command_line, "%s -t %d -r %d -m %s -v %s %s %s:%s %s", |
164 | PATH_TO_SNMPGET, timeout_interval - 1, miblist, proto, | 167 | PATH_TO_SNMPGET, timeout_interval, retries, miblist, proto, |
165 | authpriv, server_address, port, oid); | 168 | authpriv, server_address, port, oid); |
166 | if (verbose) | 169 | if (verbose) |
167 | printf ("%s\n", command_line); | 170 | printf ("%s\n", command_line); |
@@ -360,12 +363,14 @@ process_arguments (int argc, char **argv) | |||
360 | {"delimiter", required_argument, 0, 'd'}, | 363 | {"delimiter", required_argument, 0, 'd'}, |
361 | {"output-delimiter", required_argument, 0, 'D'}, | 364 | {"output-delimiter", required_argument, 0, 'D'}, |
362 | {"string", required_argument, 0, 's'}, | 365 | {"string", required_argument, 0, 's'}, |
366 | {"timeout", required_argument, 0, 't'}, | ||
363 | {"regex", required_argument, 0, 'r'}, | 367 | {"regex", required_argument, 0, 'r'}, |
364 | {"ereg", required_argument, 0, 'r'}, | 368 | {"ereg", required_argument, 0, 'r'}, |
365 | {"eregi", required_argument, 0, 'R'}, | 369 | {"eregi", required_argument, 0, 'R'}, |
366 | {"label", required_argument, 0, 'l'}, | 370 | {"label", required_argument, 0, 'l'}, |
367 | {"units", required_argument, 0, 'u'}, | 371 | {"units", required_argument, 0, 'u'}, |
368 | {"port", required_argument, 0, 'p'}, | 372 | {"port", required_argument, 0, 'p'}, |
373 | {"retries", required_argument, 0, 'e'}, | ||
369 | {"miblist", required_argument, 0, 'm'}, | 374 | {"miblist", required_argument, 0, 'm'}, |
370 | {"protocol", required_argument, 0, 'P'}, | 375 | {"protocol", required_argument, 0, 'P'}, |
371 | {"seclevel", required_argument, 0, 'L'}, | 376 | {"seclevel", required_argument, 0, 'L'}, |
@@ -390,7 +395,7 @@ process_arguments (int argc, char **argv) | |||
390 | } | 395 | } |
391 | 396 | ||
392 | while (1) { | 397 | while (1) { |
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:", | 398 | c = getopt_long (argc, argv, "hvVt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:A:X:", |
394 | longopts, &option); | 399 | longopts, &option); |
395 | 400 | ||
396 | if (c == -1 || c == EOF) | 401 | if (c == -1 || c == EOF) |
@@ -470,9 +475,14 @@ process_arguments (int argc, char **argv) | |||
470 | (ptr = index (ptr, ',')) ? ptr++ : ptr; | 475 | (ptr = index (ptr, ',')) ? ptr++ : ptr; |
471 | } | 476 | } |
472 | break; | 477 | break; |
473 | case 'o': /* object identifier */ | ||
474 | case 'e': /* PRELIMINARY - may change */ | 478 | case 'e': /* PRELIMINARY - may change */ |
475 | case 'E': /* PRELIMINARY - may change */ | 479 | case 'E': /* PRELIMINARY - may change */ |
480 | if (!is_integer (optarg)) | ||
481 | usage2 (_("Retries interval must be a positive integer"), optarg); | ||
482 | else | ||
483 | retries = atoi(optarg); | ||
484 | break; | ||
485 | case 'o': /* object identifier */ | ||
476 | for (ptr = optarg; (ptr = index (ptr, ',')); ptr++) | 486 | for (ptr = optarg; (ptr = index (ptr, ',')); ptr++) |
477 | ptr[0] = ' '; /* relpace comma with space */ | 487 | ptr[0] = ' '; /* relpace comma with space */ |
478 | for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++) | 488 | for (ptr = optarg; (ptr = index (ptr, ' ')); ptr++) |
@@ -944,7 +954,8 @@ print_usage (void) | |||
944 | { | 954 | { |
945 | printf ("\ | 955 | printf ("\ |
946 | Usage: %s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\ | 956 | Usage: %s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\ |
947 | [-C community] [-s string] [-r regex] [-R regexi] [-t timeout]\n\ | 957 | [-C community] [-s string] [-r regex] [-R regexi]\n\ |
958 | [-t timeout] [-e retries]\n\ | ||
948 | [-l label] [-u units] [-p port-number] [-d delimiter]\n\ | 959 | [-l label] [-u units] [-p port-number] [-d delimiter]\n\ |
949 | [-D output-delimiter] [-m miblist] [-P snmp version]\n\ | 960 | [-D output-delimiter] [-m miblist] [-P snmp version]\n\ |
950 | [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\ | 961 | [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\ |