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.c1265
1 files changed, 614 insertions, 651 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 90a0402..c1d8e2d 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -1,35 +1,35 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_snmp plugin 3 * Monitoring check_snmp plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 1999-2007 Monitoring Plugins Development Team 6 * Copyright (c) 1999-2024 Monitoring Plugins Development Team
7* 7 *
8* Description: 8 * Description:
9* 9 *
10* This file contains the check_snmp plugin 10 * This file contains the check_snmp plugin
11* 11 *
12* Check status of remote machines and obtain system information via SNMP 12 * Check status of remote machines and obtain system information via SNMP
13* 13 *
14* 14 *
15* This program is free software: you can redistribute it and/or modify 15 * This program is free software: you can redistribute it and/or modify
16* it under the terms of the GNU General Public License as published by 16 * it under the terms of the GNU General Public License as published by
17* the Free Software Foundation, either version 3 of the License, or 17 * the Free Software Foundation, either version 3 of the License, or
18* (at your option) any later version. 18 * (at your option) any later version.
19* 19 *
20* This program is distributed in the hope that it will be useful, 20 * This program is distributed in the hope that it will be useful,
21* but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23* GNU General Public License for more details. 23 * GNU General Public License for more details.
24* 24 *
25* You should have received a copy of the GNU General Public License 25 * You should have received a copy of the GNU General Public License
26* along with this program. If not, see <http://www.gnu.org/licenses/>. 26 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27* 27 *
28* 28 *
29*****************************************************************************/ 29 *****************************************************************************/
30 30
31const char *progname = "check_snmp"; 31const char *progname = "check_snmp";
32const char *copyright = "1999-2007"; 32const char *copyright = "1999-2024";
33const char *email = "devel@monitoring-plugins.org"; 33const char *email = "devel@monitoring-plugins.org";
34 34
35#include "common.h" 35#include "common.h"
@@ -37,60 +37,68 @@ const char *email = "devel@monitoring-plugins.org";
37#include "utils.h" 37#include "utils.h"
38#include "utils_cmd.h" 38#include "utils_cmd.h"
39 39
40#define DEFAULT_COMMUNITY "public" 40#define DEFAULT_COMMUNITY "public"
41#define DEFAULT_PORT "161" 41#define DEFAULT_PORT "161"
42#define DEFAULT_MIBLIST "ALL" 42#define DEFAULT_MIBLIST "ALL"
43#define DEFAULT_PROTOCOL "1" 43#define DEFAULT_PROTOCOL "1"
44#define DEFAULT_RETRIES 5 44#define DEFAULT_RETRIES 5
45#define DEFAULT_AUTH_PROTOCOL "MD5" 45#define DEFAULT_AUTH_PROTOCOL "MD5"
46#define DEFAULT_PRIV_PROTOCOL "DES" 46#define DEFAULT_PRIV_PROTOCOL "DES"
47#define DEFAULT_DELIMITER "=" 47#define DEFAULT_DELIMITER "="
48#define DEFAULT_OUTPUT_DELIMITER " " 48#define DEFAULT_OUTPUT_DELIMITER " "
49#define DEFAULT_BUFFER_SIZE 100 49#define DEFAULT_BUFFER_SIZE 100
50 50
51#define mark(a) ((a)!=0?"*":"") 51#define mark(a) ((a) != 0 ? "*" : "")
52 52
53#define CHECK_UNDEF 0 53#define CHECK_UNDEF 0
54#define CRIT_PRESENT 1 54#define CRIT_PRESENT 1
55#define CRIT_STRING 2 55#define CRIT_STRING 2
56#define CRIT_REGEX 4 56#define CRIT_REGEX 4
57#define WARN_PRESENT 8 57#define WARN_PRESENT 8
58 58
59#define OID_COUNT_STEP 8 59#define OID_COUNT_STEP 8
60 60
61/* Longopts only arguments */ 61/* Longopts only arguments */
62#define L_CALCULATE_RATE CHAR_MAX+1 62#define L_CALCULATE_RATE CHAR_MAX + 1
63#define L_RATE_MULTIPLIER CHAR_MAX+2 63#define L_RATE_MULTIPLIER CHAR_MAX + 2
64#define L_INVERT_SEARCH CHAR_MAX+3 64#define L_INVERT_SEARCH CHAR_MAX + 3
65#define L_OFFSET CHAR_MAX+4 65#define L_OFFSET CHAR_MAX + 4
66#define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX+5 66#define L_IGNORE_MIB_PARSING_ERRORS CHAR_MAX + 5
67 67
68/* 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
69 * characters in s */ 69 * characters in s */
70#define GOBBLE_TOS(c, s) while(c[0]!='\0' && strchr(s, c[0])==NULL) { c++; } 70#define GOBBLE_TOS(c, s) \
71 while (c[0] != '\0' && strchr(s, c[0]) == NULL) { \
72 c++; \
73 }
71/* Given c, keep track of backslashes (bk) and double-quotes (dq) 74/* Given c, keep track of backslashes (bk) and double-quotes (dq)
72 * from c[0] */ 75 * from c[0] */
73#define COUNT_SEQ(c, bk, dq) switch(c[0]) {\ 76#define COUNT_SEQ(c, bk, dq) \
74 case '\\': \ 77 switch (c[0]) { \
75 if (bk) bk--; \ 78 case '\\': \
76 else bk++; \ 79 if (bk) \
77 break; \ 80 bk--; \
78 case '"': \ 81 else \
79 if (!dq) { dq++; } \ 82 bk++; \
80 else if(!bk) { dq--; } \ 83 break; \
81 else { bk--; } \ 84 case '"': \
82 break; \ 85 if (!dq) { \
86 dq++; \
87 } else if (!bk) { \
88 dq--; \
89 } else { \
90 bk--; \
91 } \
92 break; \
83 } 93 }
84 94
85 95static int process_arguments(int, char **);
86 96static int validate_arguments(void);
87static int process_arguments (int, char **); 97static char *thisarg(char *str);
88static int validate_arguments (void); 98static char *nextarg(char *str);
89static char *thisarg (char *str); 99void print_usage(void);
90static char *nextarg (char *str); 100static void print_help(void);
91void print_usage (void); 101static char *multiply(char *str);
92static void print_help (void);
93static char *multiply (char *str);
94 102
95#include "regex.h" 103#include "regex.h"
96static char regex_expect[MAX_INPUT_BUFFER] = ""; 104static char regex_expect[MAX_INPUT_BUFFER] = "";
@@ -122,7 +130,7 @@ static char *units;
122static char *port; 130static char *port;
123static char *snmpcmd; 131static char *snmpcmd;
124static char string_value[MAX_INPUT_BUFFER] = ""; 132static char string_value[MAX_INPUT_BUFFER] = "";
125static int invert_search=0; 133static int invert_search = 0;
126static char **labels = NULL; 134static char **labels = NULL;
127static char **unitv = NULL; 135static char **unitv = NULL;
128static size_t nlabels = 0; 136static size_t nlabels = 0;
@@ -154,17 +162,18 @@ static state_data *previous_state;
154static double *previous_value; 162static double *previous_value;
155static size_t previous_size = OID_COUNT_STEP; 163static size_t previous_size = OID_COUNT_STEP;
156static int perf_labels = 1; 164static int perf_labels = 1;
157static char* ip_version = ""; 165static char *ip_version = "";
158static double multiplier = 1.0; 166static double multiplier = 1.0;
159static char *fmtstr = ""; 167static char *fmtstr = "";
160static bool fmtstr_set = false; 168static bool fmtstr_set = false;
161static char buffer[DEFAULT_BUFFER_SIZE]; 169static char buffer[DEFAULT_BUFFER_SIZE];
162static bool ignore_mib_parsing_errors = false; 170static bool ignore_mib_parsing_errors = false;
163 171
164static char *fix_snmp_range(char *th) 172static char *fix_snmp_range(char *th) {
165{ 173 double left;
166 double left, right; 174 double right;
167 char *colon, *ret; 175 char *colon;
176 char *ret;
168 177
169 if ((colon = strchr(th, ':')) == NULL || *(colon + 1) == '\0') 178 if ((colon = strchr(th, ':')) == NULL || *(colon + 1) == '\0')
170 return th; 179 return th;
@@ -182,12 +191,12 @@ static char *fix_snmp_range(char *th)
182 return ret; 191 return ret;
183} 192}
184 193
185int 194int main(int argc, char **argv) {
186main (int argc, char **argv) 195 int len;
187{ 196 int total_oids;
188 int len, total_oids;
189 size_t line; 197 size_t line;
190 unsigned int bk_count = 0, dq_count = 0; 198 unsigned int bk_count = 0;
199 unsigned int dq_count = 0;
191 int iresult = STATE_UNKNOWN; 200 int iresult = STATE_UNKNOWN;
192 int result = STATE_UNKNOWN; 201 int result = STATE_UNKNOWN;
193 int return_code = 0; 202 int return_code = 0;
@@ -200,80 +209,83 @@ main (int argc, char **argv)
200 char *outbuff; 209 char *outbuff;
201 char *ptr = NULL; 210 char *ptr = NULL;
202 char *show = NULL; 211 char *show = NULL;
203 char *th_warn=NULL; 212 char *th_warn = NULL;
204 char *th_crit=NULL; 213 char *th_crit = NULL;
205 char type[8] = ""; 214 char type[8] = "";
206 output chld_out, chld_err; 215 output chld_out;
207 char *previous_string=NULL; 216 output chld_err;
208 char *ap=NULL; 217 char *previous_string = NULL;
209 char *state_string=NULL; 218 char *ap = NULL;
210 size_t response_length, current_length, string_length; 219 char *state_string = NULL;
211 char *temp_string=NULL; 220 size_t response_length;
212 char *quote_string=NULL; 221 size_t current_length;
222 size_t string_length;
223 char *temp_string = NULL;
224 char *quote_string = NULL;
213 time_t current_time; 225 time_t current_time;
214 double temp_double; 226 double temp_double;
215 time_t duration; 227 time_t duration;
216 char *conv = "12345678"; 228 char *conv = "12345678";
217 int is_counter=0; 229 int is_counter = 0;
218 230
219 setlocale (LC_ALL, ""); 231 setlocale(LC_ALL, "");
220 bindtextdomain (PACKAGE, LOCALEDIR); 232 bindtextdomain(PACKAGE, LOCALEDIR);
221 textdomain (PACKAGE); 233 textdomain(PACKAGE);
222 234
223 labels = malloc (labels_size * sizeof(*labels)); 235 labels = malloc(labels_size * sizeof(*labels));
224 unitv = malloc (unitv_size * sizeof(*unitv)); 236 unitv = malloc(unitv_size * sizeof(*unitv));
225 thlds = malloc (thlds_size * sizeof(*thlds)); 237 thlds = malloc(thlds_size * sizeof(*thlds));
226 response_value = malloc (response_size * sizeof(*response_value)); 238 response_value = malloc(response_size * sizeof(*response_value));
227 previous_value = malloc (previous_size * sizeof(*previous_value)); 239 previous_value = malloc(previous_size * sizeof(*previous_value));
228 eval_method = calloc (eval_size, sizeof(*eval_method)); 240 eval_method = calloc(eval_size, sizeof(*eval_method));
229 oids = calloc(oids_size, sizeof (char *)); 241 oids = calloc(oids_size, sizeof(char *));
230 242
231 label = strdup ("SNMP"); 243 label = strdup("SNMP");
232 units = strdup (""); 244 units = strdup("");
233 port = strdup (DEFAULT_PORT); 245 port = strdup(DEFAULT_PORT);
234 outbuff = strdup (""); 246 outbuff = strdup("");
235 delimiter = strdup (" = "); 247 delimiter = strdup(" = ");
236 output_delim = strdup (DEFAULT_OUTPUT_DELIMITER); 248 output_delim = strdup(DEFAULT_OUTPUT_DELIMITER);
237 timeout_interval = DEFAULT_SOCKET_TIMEOUT; 249 timeout_interval = DEFAULT_SOCKET_TIMEOUT;
238 retries = DEFAULT_RETRIES; 250 retries = DEFAULT_RETRIES;
239 251
240 np_init( (char *) progname, argc, argv ); 252 np_init((char *)progname, argc, argv);
241 253
242 /* Parse extra opts if any */ 254 /* Parse extra opts if any */
243 argv=np_extra_opts (&argc, argv, progname); 255 argv = np_extra_opts(&argc, argv, progname);
244 256
245 np_set_args(argc, argv); 257 np_set_args(argc, argv);
246 258
247 time(&current_time); 259 time(&current_time);
248 260
249 if (process_arguments (argc, argv) == ERROR) 261 if (process_arguments(argc, argv) == ERROR)
250 usage4 (_("Could not parse arguments")); 262 usage4(_("Could not parse arguments"));
251 263
252 if(calculate_rate) { 264 if (calculate_rate) {
253 if (!strcmp(label, "SNMP")) 265 if (!strcmp(label, "SNMP"))
254 label = strdup("SNMP RATE"); 266 label = strdup("SNMP RATE");
255 267
256 size_t i = 0; 268 size_t i = 0;
257 269
258 previous_state = np_state_read(); 270 previous_state = np_state_read();
259 if(previous_state!=NULL) { 271 if (previous_state != NULL) {
260 /* Split colon separated values */ 272 /* Split colon separated values */
261 previous_string = strdup((char *) previous_state->data); 273 previous_string = strdup((char *)previous_state->data);
262 while((ap = strsep(&previous_string, ":")) != NULL) { 274 while ((ap = strsep(&previous_string, ":")) != NULL) {
263 if(verbose>2) 275 if (verbose > 2)
264 printf("State for %zd=%s\n", i, ap); 276 printf("State for %zd=%s\n", i, ap);
265 while (i >= previous_size) { 277 while (i >= previous_size) {
266 previous_size += OID_COUNT_STEP; 278 previous_size += OID_COUNT_STEP;
267 previous_value = realloc(previous_value, previous_size * sizeof(*previous_value)); 279 previous_value = realloc(previous_value, previous_size * sizeof(*previous_value));
268 } 280 }
269 previous_value[i++]=strtod(ap,NULL); 281 previous_value[i++] = strtod(ap, NULL);
270 } 282 }
271 } 283 }
272 } 284 }
273 285
274 /* Populate the thresholds */ 286 /* Populate the thresholds */
275 th_warn=warning_thresholds; 287 th_warn = warning_thresholds;
276 th_crit=critical_thresholds; 288 th_crit = critical_thresholds;
277 for (size_t i = 0; i < numoids; i++) { 289 for (size_t i = 0; i < numoids; i++) {
278 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL; 290 char *w = th_warn ? strndup(th_warn, strcspn(th_warn, ",")) : NULL;
279 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL; 291 char *c = th_crit ? strndup(th_crit, strcspn(th_crit, ",")) : NULL;
@@ -287,53 +299,52 @@ main (int argc, char **argv)
287 } 299 }
288 300
289 /* Skip empty thresholds, while avoiding segfault */ 301 /* Skip empty thresholds, while avoiding segfault */
290 set_thresholds(&thlds[i], 302 set_thresholds(&thlds[i], w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL, c ? strpbrk(c, NP_THRESHOLDS_CHARS) : NULL);
291 w ? strpbrk(w, NP_THRESHOLDS_CHARS) : NULL,
292 c ? strpbrk(c, NP_THRESHOLDS_CHARS) : NULL);
293 if (w) { 303 if (w) {
294 th_warn=strchr(th_warn, ','); 304 th_warn = strchr(th_warn, ',');
295 if (th_warn) th_warn++; 305 if (th_warn)
306 th_warn++;
296 free(w); 307 free(w);
297 } 308 }
298 if (c) { 309 if (c) {
299 th_crit=strchr(th_crit, ','); 310 th_crit = strchr(th_crit, ',');
300 if (th_crit) th_crit++; 311 if (th_crit)
312 th_crit++;
301 free(c); 313 free(c);
302 } 314 }
303 } 315 }
304 316
305 /* Create the command array to execute */ 317 /* Create the command array to execute */
306 if(usesnmpgetnext) { 318 if (usesnmpgetnext) {
307 snmpcmd = strdup (PATH_TO_SNMPGETNEXT); 319 snmpcmd = strdup(PATH_TO_SNMPGETNEXT);
308 }else{ 320 } else {
309 snmpcmd = strdup (PATH_TO_SNMPGET); 321 snmpcmd = strdup(PATH_TO_SNMPGET);
310 } 322 }
311 323
312 /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */ 324 /* 10 arguments to pass before context and authpriv options + 1 for host and numoids. Add one for terminating NULL */
313 325
314 unsigned index = 0; 326 unsigned index = 0;
315 command_line = calloc (11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof (char *)); 327 command_line = calloc(11 + numcontext + numauthpriv + 1 + numoids + 1, sizeof(char *));
316 328
317 command_line[index++] = snmpcmd; 329 command_line[index++] = snmpcmd;
318 command_line[index++] = strdup ("-Le"); 330 command_line[index++] = strdup("-Le");
319 command_line[index++] = strdup ("-t"); 331 command_line[index++] = strdup("-t");
320 xasprintf (&command_line[index++], "%d", timeout_interval); 332 xasprintf(&command_line[index++], "%d", timeout_interval);
321 command_line[index++] = strdup ("-r"); 333 command_line[index++] = strdup("-r");
322 xasprintf (&command_line[index++], "%d", retries); 334 xasprintf(&command_line[index++], "%d", retries);
323 command_line[index++] = strdup ("-m"); 335 command_line[index++] = strdup("-m");
324 command_line[index++] = strdup (miblist); 336 command_line[index++] = strdup(miblist);
325 command_line[index++] = "-v"; 337 command_line[index++] = "-v";
326 command_line[index++] = strdup (proto); 338 command_line[index++] = strdup(proto);
327 339
328 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", 340 xasprintf(&cl_hidden_auth, "%s -Le -t %d -r %d -m %s -v %s", snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''",
329 snmpcmd, timeout_interval, retries, strlen(miblist) ? miblist : "''", proto); 341 proto);
330 342
331 if (ignore_mib_parsing_errors) { 343 if (ignore_mib_parsing_errors) {
332 command_line[index++] = "-Pe"; 344 command_line[index++] = "-Pe";
333 xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth); 345 xasprintf(&cl_hidden_auth, "%s -Pe", cl_hidden_auth);
334 } 346 }
335 347
336
337 for (int i = 0; i < numcontext; i++) { 348 for (int i = 0; i < numcontext; i++) {
338 command_line[index++] = contextargs[i]; 349 command_line[index++] = contextargs[i];
339 } 350 }
@@ -342,12 +353,9 @@ main (int argc, char **argv)
342 command_line[index++] = authpriv[i]; 353 command_line[index++] = authpriv[i];
343 } 354 }
344 355
345 xasprintf (&command_line[index++], "%s:%s", server_address, port); 356 xasprintf(&command_line[index++], "%s:%s", server_address, port);
346 357
347 xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", 358 xasprintf(&cl_hidden_auth, "%s [context] [authpriv] %s:%s", cl_hidden_auth, server_address, port);
348 cl_hidden_auth,
349 server_address,
350 port);
351 359
352 for (size_t i = 0; i < numoids; i++) { 360 for (size_t i = 0; i < numoids; i++) {
353 command_line[index++] = oids[i]; 361 command_line[index++] = oids[i];
@@ -357,17 +365,17 @@ main (int argc, char **argv)
357 command_line[index++] = NULL; 365 command_line[index++] = NULL;
358 366
359 if (verbose) { 367 if (verbose) {
360 printf ("%s\n", cl_hidden_auth); 368 printf("%s\n", cl_hidden_auth);
361 } 369 }
362 370
363 /* Set signal handling and alarm */ 371 /* Set signal handling and alarm */
364 if (signal (SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) { 372 if (signal(SIGALRM, runcmd_timeout_alarm_handler) == SIG_ERR) {
365 usage4 (_("Cannot catch SIGALRM")); 373 usage4(_("Cannot catch SIGALRM"));
366 } 374 }
367 alarm(timeout_interval * retries + 5); 375 alarm(timeout_interval * retries + 5);
368 376
369 /* Run the command */ 377 /* Run the command */
370 return_code = cmd_run_array (command_line, &chld_out, &chld_err, 0); 378 return_code = cmd_run_array(command_line, &chld_out, &chld_err, 0);
371 379
372 /* disable alarm again */ 380 /* disable alarm again */
373 alarm(0); 381 alarm(0);
@@ -377,80 +385,74 @@ main (int argc, char **argv)
377 Do this way so that if there is stderr, will get added to output, which helps problem diagnosis 385 Do this way so that if there is stderr, will get added to output, which helps problem diagnosis
378 */ 386 */
379 if (return_code != 0) 387 if (return_code != 0)
380 external_error=1; 388 external_error = 1;
381 if (chld_out.lines == 0) 389 if (chld_out.lines == 0)
382 external_error=1; 390 external_error = 1;
383 if (external_error) { 391 if (external_error) {
384 if (chld_err.lines > 0) { 392 if (chld_err.lines > 0) {
385 printf (_("External command error: %s\n"), chld_err.line[0]); 393 printf(_("External command error: %s\n"), chld_err.line[0]);
386 for (size_t i = 1; i < chld_err.lines; i++) { 394 for (size_t i = 1; i < chld_err.lines; i++) {
387 printf ("%s\n", chld_err.line[i]); 395 printf("%s\n", chld_err.line[i]);
388 } 396 }
389 } else { 397 } else {
390 printf(_("External command error with no output (return code: %d)\n"), return_code); 398 printf(_("External command error with no output (return code: %d)\n"), return_code);
391 } 399 }
392 exit (STATE_UNKNOWN); 400 exit(STATE_UNKNOWN);
393 } 401 }
394 402
395 if (verbose) { 403 if (verbose) {
396 for (size_t i = 0; i < chld_out.lines; i++) { 404 for (size_t i = 0; i < chld_out.lines; i++) {
397 printf ("%s\n", chld_out.line[i]); 405 printf("%s\n", chld_out.line[i]);
398 } 406 }
399 } 407 }
400 408
401 line = 0; 409 line = 0;
402 total_oids = 0; 410 total_oids = 0;
403 for (size_t i = 0; line < chld_out.lines && i < numoids ; line++, i++, total_oids++) { 411 for (size_t i = 0; line < chld_out.lines && i < numoids; line++, i++, total_oids++) {
404 if(calculate_rate) 412 if (calculate_rate)
405 conv = "%.10g"; 413 conv = "%.10g";
406 else 414 else
407 conv = "%.0f"; 415 conv = "%.0f";
408 416
409 ptr = chld_out.line[line]; 417 ptr = chld_out.line[line];
410 oidname = strpcpy (oidname, ptr, delimiter); 418 oidname = strpcpy(oidname, ptr, delimiter);
411 response = strstr (ptr, delimiter); 419 response = strstr(ptr, delimiter);
412 if (response == NULL) 420 if (response == NULL)
413 break; 421 break;
414 422
415 if (verbose > 2) { 423 if (verbose > 2) {
416 printf("Processing oid %zi (line %zi)\n oidname: %s\n response: %s\n", i+1, line+1, oidname, response); 424 printf("Processing oid %zi (line %zi)\n oidname: %s\n response: %s\n", i + 1, line + 1, oidname, response);
417 } 425 }
418 426
419 /* Clean up type array - Sol10 does not necessarily zero it out */ 427 /* Clean up type array - Sol10 does not necessarily zero it out */
420 bzero(type, sizeof(type)); 428 bzero(type, sizeof(type));
421 429
422 is_counter=0; 430 is_counter = 0;
423 /* We strip out the datatype indicator for PHBs */ 431 /* We strip out the datatype indicator for PHBs */
424 if (strstr (response, "Gauge: ")) { 432 if (strstr(response, "Gauge: ")) {
425 show = multiply (strstr (response, "Gauge: ") + 7); 433 show = multiply(strstr(response, "Gauge: ") + 7);
426 } 434 } else if (strstr(response, "Gauge32: ")) {
427 else if (strstr (response, "Gauge32: ")) { 435 show = multiply(strstr(response, "Gauge32: ") + 9);
428 show = multiply (strstr (response, "Gauge32: ") + 9); 436 } else if (strstr(response, "Counter32: ")) {
429 } 437 show = strstr(response, "Counter32: ") + 11;
430 else if (strstr (response, "Counter32: ")) { 438 is_counter = 1;
431 show = strstr (response, "Counter32: ") + 11; 439 if (!calculate_rate)
432 is_counter=1;
433 if(!calculate_rate)
434 strcpy(type, "c"); 440 strcpy(type, "c");
435 } 441 } else if (strstr(response, "Counter64: ")) {
436 else if (strstr (response, "Counter64: ")) { 442 show = strstr(response, "Counter64: ") + 11;
437 show = strstr (response, "Counter64: ") + 11; 443 is_counter = 1;
438 is_counter=1; 444 if (!calculate_rate)
439 if(!calculate_rate)
440 strcpy(type, "c"); 445 strcpy(type, "c");
441 } 446 } else if (strstr(response, "INTEGER: ")) {
442 else if (strstr (response, "INTEGER: ")) { 447 show = multiply(strstr(response, "INTEGER: ") + 9);
443 show = multiply (strstr (response, "INTEGER: ") + 9);
444 448
445 if (fmtstr_set) { 449 if (fmtstr_set) {
446 conv = fmtstr; 450 conv = fmtstr;
447 } 451 }
448 } 452 } else if (strstr(response, "OID: ")) {
449 else if (strstr (response, "OID: ")) { 453 show = strstr(response, "OID: ") + 5;
450 show = strstr (response, "OID: ") + 5; 454 } else if (strstr(response, "STRING: ")) {
451 } 455 show = strstr(response, "STRING: ") + 8;
452 else if (strstr (response, "STRING: ")) {
453 show = strstr (response, "STRING: ") + 8;
454 conv = "%.10g"; 456 conv = "%.10g";
455 457
456 /* Get the rest of the string on multi-line strings */ 458 /* Get the rest of the string on multi-line strings */
@@ -464,15 +466,17 @@ main (int argc, char **argv)
464 466
465 if (dq_count) { /* unfinished line */ 467 if (dq_count) { /* unfinished line */
466 /* copy show verbatim first */ 468 /* copy show verbatim first */
467 if (!mult_resp) mult_resp = strdup(""); 469 if (!mult_resp)
468 xasprintf (&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show); 470 mult_resp = strdup("");
471 xasprintf(&mult_resp, "%s%s:\n%s\n", mult_resp, oids[i], show);
469 /* then strip out unmatched double-quote from single-line output */ 472 /* then strip out unmatched double-quote from single-line output */
470 if (show[0] == '"') show++; 473 if (show[0] == '"')
474 show++;
471 475
472 /* Keep reading until we match end of double-quoted string */ 476 /* Keep reading until we match end of double-quoted string */
473 for (line++; line < chld_out.lines; line++) { 477 for (line++; line < chld_out.lines; line++) {
474 ptr = chld_out.line[line]; 478 ptr = chld_out.line[line];
475 xasprintf (&mult_resp, "%s%s\n", mult_resp, ptr); 479 xasprintf(&mult_resp, "%s%s\n", mult_resp, ptr);
476 480
477 COUNT_SEQ(ptr, bk_count, dq_count) 481 COUNT_SEQ(ptr, bk_count, dq_count)
478 while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') { 482 while (dq_count && ptr[0] != '\n' && ptr[0] != '\0') {
@@ -481,15 +485,14 @@ main (int argc, char **argv)
481 COUNT_SEQ(ptr, bk_count, dq_count) 485 COUNT_SEQ(ptr, bk_count, dq_count)
482 } 486 }
483 /* Break for loop before next line increment when done */ 487 /* Break for loop before next line increment when done */
484 if (!dq_count) break; 488 if (!dq_count)
489 break;
485 } 490 }
486 } 491 }
487 492
488 } 493 } else if (strstr(response, "Timeticks: ")) {
489 else if (strstr (response, "Timeticks: ")) { 494 show = strstr(response, "Timeticks: ");
490 show = strstr (response, "Timeticks: "); 495 } else
491 }
492 else
493 show = response + 3; 496 show = response + 3;
494 497
495 iresult = STATE_DEPENDENT; 498 iresult = STATE_DEPENDENT;
@@ -500,68 +503,67 @@ main (int argc, char **argv)
500 if (verbose > 2) { 503 if (verbose > 2) {
501 print_thresholds(" thresholds", thlds[i]); 504 print_thresholds(" thresholds", thlds[i]);
502 } 505 }
503 ptr = strpbrk (show, "-0123456789"); 506 ptr = strpbrk(show, "-0123456789");
504 if (ptr == NULL){ 507 if (ptr == NULL) {
505 if (nulloid == 3) 508 if (nulloid == 3)
506 die (STATE_UNKNOWN,_("No valid data returned (%s)\n"), show); 509 die(STATE_UNKNOWN, _("No valid data returned (%s)\n"), show);
507 else if (nulloid == 0) 510 else if (nulloid == 0)
508 die (STATE_OK,_("No valid data returned (%s)\n"), show); 511 die(STATE_OK, _("No valid data returned (%s)\n"), show);
509 else if (nulloid == 1) 512 else if (nulloid == 1)
510 die (STATE_WARNING,_("No valid data returned (%s)\n"), show); 513 die(STATE_WARNING, _("No valid data returned (%s)\n"), show);
511 else if (nulloid == 2) 514 else if (nulloid == 2)
512 die (STATE_CRITICAL,_("No valid data returned (%s)\n"), show); 515 die(STATE_CRITICAL, _("No valid data returned (%s)\n"), show);
513 } 516 }
514 while (i >= response_size) { 517 while (i >= response_size) {
515 response_size += OID_COUNT_STEP; 518 response_size += OID_COUNT_STEP;
516 response_value = realloc(response_value, response_size * sizeof(*response_value)); 519 response_value = realloc(response_value, response_size * sizeof(*response_value));
517 } 520 }
518 response_value[i] = strtod (ptr, NULL) + offset; 521 response_value[i] = strtod(ptr, NULL) + offset;
519 522
520 if(calculate_rate) { 523 if (calculate_rate) {
521 if (previous_state!=NULL) { 524 if (previous_state != NULL) {
522 duration = current_time-previous_state->time; 525 duration = current_time - previous_state->time;
523 if(duration<=0) 526 if (duration <= 0)
524 die(STATE_UNKNOWN,_("Time duration between plugin calls is invalid")); 527 die(STATE_UNKNOWN, _("Time duration between plugin calls is invalid"));
525 temp_double = response_value[i]-previous_value[i]; 528 temp_double = response_value[i] - previous_value[i];
526 /* Simple overflow catcher (same as in rrdtool, rrd_update.c) */ 529 /* Simple overflow catcher (same as in rrdtool, rrd_update.c) */
527 if(is_counter) { 530 if (is_counter) {
528 if(temp_double<(double)0.0) 531 if (temp_double < (double)0.0)
529 temp_double+=(double)4294967296.0; /* 2^32 */ 532 temp_double += (double)4294967296.0; /* 2^32 */
530 if(temp_double<(double)0.0) 533 if (temp_double < (double)0.0)
531 temp_double+=(double)18446744069414584320.0; /* 2^64-2^32 */; 534 temp_double += (double)18446744069414584320.0; /* 2^64-2^32 */
535 ;
532 } 536 }
533 /* Convert to per second, then use multiplier */ 537 /* Convert to per second, then use multiplier */
534 temp_double = temp_double/duration*rate_multiplier; 538 temp_double = temp_double / duration * rate_multiplier;
535 iresult = get_status(temp_double, thlds[i]); 539 iresult = get_status(temp_double, thlds[i]);
536 xasprintf (&show, conv, temp_double); 540 xasprintf(&show, conv, temp_double);
537 } 541 }
538 } else { 542 } else {
539 iresult = get_status(response_value[i], thlds[i]); 543 iresult = get_status(response_value[i], thlds[i]);
540 xasprintf (&show, conv, response_value[i]); 544 xasprintf(&show, conv, response_value[i]);
541 } 545 }
542 } 546 }
543 547
544 /* Process this block for string matching */ 548 /* Process this block for string matching */
545 else if (eval_size > i && eval_method[i] & CRIT_STRING) { 549 else if (eval_size > i && eval_method[i] & CRIT_STRING) {
546 if (strcmp (show, string_value)) 550 if (strcmp(show, string_value))
547 iresult = (invert_search==0) ? STATE_CRITICAL : STATE_OK; 551 iresult = (invert_search == 0) ? STATE_CRITICAL : STATE_OK;
548 else 552 else
549 iresult = (invert_search==0) ? STATE_OK : STATE_CRITICAL; 553 iresult = (invert_search == 0) ? STATE_OK : STATE_CRITICAL;
550 } 554 }
551 555
552 /* Process this block for regex matching */ 556 /* Process this block for regex matching */
553 else if (eval_size > i && eval_method[i] & CRIT_REGEX) { 557 else if (eval_size > i && eval_method[i] & CRIT_REGEX) {
554 excode = regexec (&preg, response, 10, pmatch, eflags); 558 excode = regexec(&preg, response, 10, pmatch, eflags);
555 if (excode == 0) { 559 if (excode == 0) {
556 iresult = (invert_search==0) ? STATE_OK : STATE_CRITICAL; 560 iresult = (invert_search == 0) ? STATE_OK : STATE_CRITICAL;
557 } 561 } else if (excode != REG_NOMATCH) {
558 else if (excode != REG_NOMATCH) { 562 regerror(excode, &preg, errbuf, MAX_INPUT_BUFFER);
559 regerror (excode, &preg, errbuf, MAX_INPUT_BUFFER); 563 printf(_("Execute Error: %s\n"), errbuf);
560 printf (_("Execute Error: %s\n"), errbuf); 564 exit(STATE_CRITICAL);
561 exit (STATE_CRITICAL); 565 } else {
562 } 566 iresult = (invert_search == 0) ? STATE_CRITICAL : STATE_OK;
563 else {
564 iresult = (invert_search==0) ? STATE_CRITICAL : STATE_OK;
565 } 567 }
566 } 568 }
567 569
@@ -577,294 +579,283 @@ main (int argc, char **argv)
577 } 579 }
578 580
579 /* Result is the worst outcome of all the OIDs tested */ 581 /* Result is the worst outcome of all the OIDs tested */
580 result = max_state (result, iresult); 582 result = max_state(result, iresult);
581 583
582 /* Prepend a label for this OID if there is one */ 584 /* Prepend a label for this OID if there is one */
583 if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) 585 if (nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL)
584 xasprintf (&outbuff, "%s%s%s %s%s%s", outbuff, 586 xasprintf(&outbuff, "%s%s%s %s%s%s", outbuff, (i == 0) ? " " : output_delim, labels[i], mark(iresult), show, mark(iresult));
585 (i == 0) ? " " : output_delim,
586 labels[i], mark (iresult), show, mark (iresult));
587 else 587 else
588 xasprintf (&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim, 588 xasprintf(&outbuff, "%s%s%s%s%s", outbuff, (i == 0) ? " " : output_delim, mark(iresult), show, mark(iresult));
589 mark (iresult), show, mark (iresult));
590 589
591 /* Append a unit string for this OID if there is one */ 590 /* Append a unit string for this OID if there is one */
592 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL) 591 if (nunits > (size_t)0 && (size_t)i < nunits && unitv[i] != NULL)
593 xasprintf (&outbuff, "%s %s", outbuff, unitv[i]); 592 xasprintf(&outbuff, "%s %s", outbuff, unitv[i]);
594 593
595 /* Write perfdata with whatever can be parsed by strtod, if possible */ 594 /* Write perfdata with whatever can be parsed by strtod, if possible */
596 ptr = NULL; 595 ptr = NULL;
597 strtod(show, &ptr); 596 strtod(show, &ptr);
598 if (ptr > show) { 597 if (ptr > show) {
599 if (perf_labels && nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL) 598 if (perf_labels && nlabels >= (size_t)1 && (size_t)i < nlabels && labels[i] != NULL)
600 temp_string=labels[i]; 599 temp_string = labels[i];
601 else 600 else
602 temp_string=oidname; 601 temp_string = oidname;
603 if (strpbrk (temp_string, " ='\"") == NULL) { 602 if (strpbrk(temp_string, " ='\"") == NULL) {
604 strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1); 603 strncat(perfstr, temp_string, sizeof(perfstr) - strlen(perfstr) - 1);
605 } else { 604 } else {
606 if (strpbrk (temp_string, "'") == NULL) { 605 if (strpbrk(temp_string, "'") == NULL) {
607 quote_string="'"; 606 quote_string = "'";
608 } else { 607 } else {
609 quote_string="\""; 608 quote_string = "\"";
610 } 609 }
611 strncat(perfstr, quote_string, sizeof(perfstr)-strlen(perfstr)-1); 610 strncat(perfstr, quote_string, sizeof(perfstr) - strlen(perfstr) - 1);
612 strncat(perfstr, temp_string, sizeof(perfstr)-strlen(perfstr)-1); 611 strncat(perfstr, temp_string, sizeof(perfstr) - strlen(perfstr) - 1);
613 strncat(perfstr, quote_string, sizeof(perfstr)-strlen(perfstr)-1); 612 strncat(perfstr, quote_string, sizeof(perfstr) - strlen(perfstr) - 1);
614 } 613 }
615 strncat(perfstr, "=", sizeof(perfstr)-strlen(perfstr)-1); 614 strncat(perfstr, "=", sizeof(perfstr) - strlen(perfstr) - 1);
616 len = sizeof(perfstr)-strlen(perfstr)-1; 615 len = sizeof(perfstr) - strlen(perfstr) - 1;
617 strncat(perfstr, show, len>ptr-show ? ptr-show : len); 616 strncat(perfstr, show, len > ptr - show ? ptr - show : len);
618 617
619 if (strcmp(type, "") != 0) { 618 if (strcmp(type, "") != 0) {
620 strncat(perfstr, type, sizeof(perfstr)-strlen(perfstr)-1); 619 strncat(perfstr, type, sizeof(perfstr) - strlen(perfstr) - 1);
621 } 620 }
622 621
623 if (warning_thresholds) { 622 if (warning_thresholds) {
624 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); 623 strncat(perfstr, ";", sizeof(perfstr) - strlen(perfstr) - 1);
625 if(thlds[i]->warning && thlds[i]->warning->text) 624 if (thlds[i]->warning && thlds[i]->warning->text)
626 strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr)-strlen(perfstr)-1); 625 strncat(perfstr, thlds[i]->warning->text, sizeof(perfstr) - strlen(perfstr) - 1);
627 } 626 }
628 627
629 if (critical_thresholds) { 628 if (critical_thresholds) {
630 if (!warning_thresholds) 629 if (!warning_thresholds)
631 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); 630 strncat(perfstr, ";", sizeof(perfstr) - strlen(perfstr) - 1);
632 strncat(perfstr, ";", sizeof(perfstr)-strlen(perfstr)-1); 631 strncat(perfstr, ";", sizeof(perfstr) - strlen(perfstr) - 1);
633 if(thlds[i]->critical && thlds[i]->critical->text) 632 if (thlds[i]->critical && thlds[i]->critical->text)
634 strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr)-strlen(perfstr)-1); 633 strncat(perfstr, thlds[i]->critical->text, sizeof(perfstr) - strlen(perfstr) - 1);
635 } 634 }
636 635
637 strncat(perfstr, " ", sizeof(perfstr)-strlen(perfstr)-1); 636 strncat(perfstr, " ", sizeof(perfstr) - strlen(perfstr) - 1);
638 } 637 }
639 } 638 }
640 639
641 /* Save state data, as all data collected now */ 640 /* Save state data, as all data collected now */
642 if(calculate_rate) { 641 if (calculate_rate) {
643 string_length=1024; 642 string_length = 1024;
644 state_string=malloc(string_length); 643 state_string = malloc(string_length);
645 if(state_string==NULL) 644 if (state_string == NULL)
646 die(STATE_UNKNOWN, _("Cannot malloc")); 645 die(STATE_UNKNOWN, _("Cannot malloc"));
647 646
648 current_length=0; 647 current_length = 0;
649 for(int i = 0; i < total_oids; i++) { 648 for (int i = 0; i < total_oids; i++) {
650 xasprintf(&temp_string,"%.0f",response_value[i]); 649 xasprintf(&temp_string, "%.0f", response_value[i]);
651 if(temp_string==NULL) 650 if (temp_string == NULL)
652 die(STATE_UNKNOWN,_("Cannot asprintf()")); 651 die(STATE_UNKNOWN, _("Cannot asprintf()"));
653 response_length = strlen(temp_string); 652 response_length = strlen(temp_string);
654 if(current_length+response_length>string_length) { 653 if (current_length + response_length > string_length) {
655 string_length=current_length+1024; 654 string_length = current_length + 1024;
656 state_string=realloc(state_string,string_length); 655 state_string = realloc(state_string, string_length);
657 if(state_string==NULL) 656 if (state_string == NULL)
658 die(STATE_UNKNOWN, _("Cannot realloc()")); 657 die(STATE_UNKNOWN, _("Cannot realloc()"));
659 } 658 }
660 strcpy(&state_string[current_length],temp_string); 659 strcpy(&state_string[current_length], temp_string);
661 current_length=current_length+response_length; 660 current_length = current_length + response_length;
662 state_string[current_length]=':'; 661 state_string[current_length] = ':';
663 current_length++; 662 current_length++;
664 free(temp_string); 663 free(temp_string);
665 } 664 }
666 state_string[--current_length]='\0'; 665 state_string[--current_length] = '\0';
667 if (verbose > 2) 666 if (verbose > 2)
668 printf("State string=%s\n",state_string); 667 printf("State string=%s\n", state_string);
669 668
670 /* This is not strictly the same as time now, but any subtle variations will cancel out */ 669 /* This is not strictly the same as time now, but any subtle variations will cancel out */
671 np_state_write_string(current_time, state_string ); 670 np_state_write_string(current_time, state_string);
672 if(previous_state==NULL) { 671 if (previous_state == NULL) {
673 /* Or should this be highest state? */ 672 /* Or should this be highest state? */
674 die( STATE_OK, _("No previous data to calculate rate - assume okay" ) ); 673 die(STATE_OK, _("No previous data to calculate rate - assume okay"));
675 } 674 }
676 } 675 }
677 676
678 printf ("%s %s -%s %s\n", label, state_text (result), outbuff, perfstr); 677 printf("%s %s -%s %s\n", label, state_text(result), outbuff, perfstr);
679 if (mult_resp) printf ("%s", mult_resp); 678 if (mult_resp)
679 printf("%s", mult_resp);
680 680
681 return result; 681 return result;
682} 682}
683 683
684
685
686/* process command-line arguments */ 684/* process command-line arguments */
687int 685int process_arguments(int argc, char **argv) {
688process_arguments (int argc, char **argv) 686 static struct option longopts[] = {STD_LONG_OPTS,
689{ 687 {"community", required_argument, 0, 'C'},
690 char *ptr; 688 {"oid", required_argument, 0, 'o'},
691 int c = 1; 689 {"object", required_argument, 0, 'o'},
692 size_t j = 0, jj = 0; 690 {"delimiter", required_argument, 0, 'd'},
693 691 {"nulloid", required_argument, 0, 'z'},
694 int option = 0; 692 {"output-delimiter", required_argument, 0, 'D'},
695 static struct option longopts[] = { 693 {"string", required_argument, 0, 's'},
696 STD_LONG_OPTS, 694 {"timeout", required_argument, 0, 't'},
697 {"community", required_argument, 0, 'C'}, 695 {"regex", required_argument, 0, 'r'},
698 {"oid", required_argument, 0, 'o'}, 696 {"ereg", required_argument, 0, 'r'},
699 {"object", required_argument, 0, 'o'}, 697 {"eregi", required_argument, 0, 'R'},
700 {"delimiter", required_argument, 0, 'd'}, 698 {"label", required_argument, 0, 'l'},
701 {"nulloid", required_argument, 0, 'z'}, 699 {"units", required_argument, 0, 'u'},
702 {"output-delimiter", required_argument, 0, 'D'}, 700 {"port", required_argument, 0, 'p'},
703 {"string", required_argument, 0, 's'}, 701 {"retries", required_argument, 0, 'e'},
704 {"timeout", required_argument, 0, 't'}, 702 {"miblist", required_argument, 0, 'm'},
705 {"regex", required_argument, 0, 'r'}, 703 {"protocol", required_argument, 0, 'P'},
706 {"ereg", required_argument, 0, 'r'}, 704 {"context", required_argument, 0, 'N'},
707 {"eregi", required_argument, 0, 'R'}, 705 {"seclevel", required_argument, 0, 'L'},
708 {"label", required_argument, 0, 'l'}, 706 {"secname", required_argument, 0, 'U'},
709 {"units", required_argument, 0, 'u'}, 707 {"authproto", required_argument, 0, 'a'},
710 {"port", required_argument, 0, 'p'}, 708 {"privproto", required_argument, 0, 'x'},
711 {"retries", required_argument, 0, 'e'}, 709 {"authpasswd", required_argument, 0, 'A'},
712 {"miblist", required_argument, 0, 'm'}, 710 {"privpasswd", required_argument, 0, 'X'},
713 {"protocol", required_argument, 0, 'P'}, 711 {"next", no_argument, 0, 'n'},
714 {"context", required_argument, 0, 'N'}, 712 {"rate", no_argument, 0, L_CALCULATE_RATE},
715 {"seclevel", required_argument, 0, 'L'}, 713 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER},
716 {"secname", required_argument, 0, 'U'}, 714 {"offset", required_argument, 0, L_OFFSET},
717 {"authproto", required_argument, 0, 'a'}, 715 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
718 {"privproto", required_argument, 0, 'x'}, 716 {"perf-oids", no_argument, 0, 'O'},
719 {"authpasswd", required_argument, 0, 'A'}, 717 {"ipv4", no_argument, 0, '4'},
720 {"privpasswd", required_argument, 0, 'X'}, 718 {"ipv6", no_argument, 0, '6'},
721 {"next", no_argument, 0, 'n'}, 719 {"multiplier", required_argument, 0, 'M'},
722 {"rate", no_argument, 0, L_CALCULATE_RATE}, 720 {"fmtstr", required_argument, 0, 'f'},
723 {"rate-multiplier", required_argument, 0, L_RATE_MULTIPLIER}, 721 {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS},
724 {"offset", required_argument, 0, L_OFFSET}, 722 {0, 0, 0, 0}};
725 {"invert-search", no_argument, 0, L_INVERT_SEARCH},
726 {"perf-oids", no_argument, 0, 'O'},
727 {"ipv4", no_argument, 0, '4'},
728 {"ipv6", no_argument, 0, '6'},
729 {"multiplier", required_argument, 0, 'M'},
730 {"fmtstr", required_argument, 0, 'f'},
731 {"ignore-mib-parsing-errors", no_argument, false, L_IGNORE_MIB_PARSING_ERRORS},
732 {0, 0, 0, 0}
733 };
734 723
735 if (argc < 2) 724 if (argc < 2)
736 return ERROR; 725 return ERROR;
737 726
738 /* reverse compatibility for very old non-POSIX usage forms */ 727 /* reverse compatibility for very old non-POSIX usage forms */
739 for (c = 1; c < argc; c++) { 728 for (int c = 1; c < argc; c++) {
740 if (strcmp ("-to", argv[c]) == 0) 729 if (strcmp("-to", argv[c]) == 0)
741 strcpy (argv[c], "-t"); 730 strcpy(argv[c], "-t");
742 if (strcmp ("-wv", argv[c]) == 0) 731 if (strcmp("-wv", argv[c]) == 0)
743 strcpy (argv[c], "-w"); 732 strcpy(argv[c], "-w");
744 if (strcmp ("-cv", argv[c]) == 0) 733 if (strcmp("-cv", argv[c]) == 0)
745 strcpy (argv[c], "-c"); 734 strcpy(argv[c], "-c");
746 } 735 }
747 736
748 while (1) { 737 size_t j = 0;
749 c = getopt_long (argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:M:f:z:", 738 size_t jj = 0;
750 longopts, &option); 739 while (true) {
740 int option = 0;
741 int option_char = getopt_long(argc, argv, "nhvVO46t:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:N:L:U:a:x:A:X:M:f:z:", longopts, &option);
751 742
752 if (c == -1 || c == EOF) 743 if (option_char == -1 || option_char == EOF)
753 break; 744 break;
754 745
755 switch (c) { 746 switch (option_char) {
756 case '?': /* usage */ 747 case '?': /* usage */
757 usage5 (); 748 usage5();
758 case 'h': /* help */ 749 case 'h': /* help */
759 print_help (); 750 print_help();
760 exit (STATE_UNKNOWN); 751 exit(STATE_UNKNOWN);
761 case 'V': /* version */ 752 case 'V': /* version */
762 print_revision (progname, NP_VERSION); 753 print_revision(progname, NP_VERSION);
763 exit (STATE_UNKNOWN); 754 exit(STATE_UNKNOWN);
764 case 'v': /* verbose */ 755 case 'v': /* verbose */
765 verbose++; 756 verbose++;
766 break; 757 break;
767 758
768 /* Connection info */ 759 /* Connection info */
769 case 'C': /* group or community */ 760 case 'C': /* group or community */
770 community = optarg; 761 community = optarg;
771 break; 762 break;
772 case 'H': /* Host or server */ 763 case 'H': /* Host or server */
773 server_address = optarg; 764 server_address = optarg;
774 break; 765 break;
775 case 'p': /* TCP port number */ 766 case 'p': /* TCP port number */
776 port = optarg; 767 port = optarg;
777 break; 768 break;
778 case 'm': /* List of MIBS */ 769 case 'm': /* List of MIBS */
779 miblist = optarg; 770 miblist = optarg;
780 break; 771 break;
781 case 'n': /* usesnmpgetnext */ 772 case 'n': /* usesnmpgetnext */
782 usesnmpgetnext = true; 773 usesnmpgetnext = true;
783 break; 774 break;
784 case 'P': /* SNMP protocol version */ 775 case 'P': /* SNMP protocol version */
785 proto = optarg; 776 proto = optarg;
786 break; 777 break;
787 case 'N': /* SNMPv3 context */ 778 case 'N': /* SNMPv3 context */
788 context = optarg; 779 context = optarg;
789 break; 780 break;
790 case 'L': /* security level */ 781 case 'L': /* security level */
791 seclevel = optarg; 782 seclevel = optarg;
792 break; 783 break;
793 case 'U': /* security username */ 784 case 'U': /* security username */
794 secname = optarg; 785 secname = optarg;
795 break; 786 break;
796 case 'a': /* auth protocol */ 787 case 'a': /* auth protocol */
797 authproto = optarg; 788 authproto = optarg;
798 break; 789 break;
799 case 'x': /* priv protocol */ 790 case 'x': /* priv protocol */
800 privproto = optarg; 791 privproto = optarg;
801 break; 792 break;
802 case 'A': /* auth passwd */ 793 case 'A': /* auth passwd */
803 authpasswd = optarg; 794 authpasswd = optarg;
804 break; 795 break;
805 case 'X': /* priv passwd */ 796 case 'X': /* priv passwd */
806 privpasswd = optarg; 797 privpasswd = optarg;
807 break; 798 break;
808 case 't': /* timeout period */ 799 case 't': /* timeout period */
809 if (!is_integer (optarg)) 800 if (!is_integer(optarg))
810 usage2 (_("Timeout interval must be a positive integer"), optarg); 801 usage2(_("Timeout interval must be a positive integer"), optarg);
811 else 802 else
812 timeout_interval = atoi (optarg); 803 timeout_interval = atoi(optarg);
813 break; 804 break;
814 805
815 /* Test parameters */ 806 /* Test parameters */
816 case 'c': /* critical threshold */ 807 case 'c': /* critical threshold */
817 critical_thresholds = optarg; 808 critical_thresholds = optarg;
818 break; 809 break;
819 case 'w': /* warning threshold */ 810 case 'w': /* warning threshold */
820 warning_thresholds = optarg; 811 warning_thresholds = optarg;
821 break; 812 break;
822 case 'e': /* PRELIMINARY - may change */ 813 case 'e': /* PRELIMINARY - may change */
823 case 'E': /* PRELIMINARY - may change */ 814 case 'E': /* PRELIMINARY - may change */
824 if (!is_integer (optarg)) 815 if (!is_integer(optarg))
825 usage2 (_("Retries interval must be a positive integer"), optarg); 816 usage2(_("Retries interval must be a positive integer"), optarg);
826 else 817 else
827 retries = atoi(optarg); 818 retries = atoi(optarg);
828 break; 819 break;
829 case 'o': /* object identifier */ 820 case 'o': /* object identifier */
830 if ( strspn( optarg, "0123456789.," ) != strlen( optarg ) ) { 821 if (strspn(optarg, "0123456789.,") != strlen(optarg)) {
831 /* 822 /*
832 * we have something other than digits, periods and comas, 823 * we have something other than digits, periods and comas,
833 * so we have a mib variable, rather than just an SNMP OID, 824 * so we have a mib variable, rather than just an SNMP OID,
834 * so we have to actually read the mib files 825 * so we have to actually read the mib files
835 */ 826 */
836 needmibs = true; 827 needmibs = true;
837 } 828 }
838 for (ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) { 829 for (char *ptr = strtok(optarg, ", "); ptr != NULL; ptr = strtok(NULL, ", "), j++) {
839 while (j >= oids_size) { 830 while (j >= oids_size) {
840 oids_size += OID_COUNT_STEP; 831 oids_size += OID_COUNT_STEP;
841 oids = realloc(oids, oids_size * sizeof (*oids)); 832 oids = realloc(oids, oids_size * sizeof(*oids));
842 } 833 }
843 oids[j] = strdup(ptr); 834 oids[j] = strdup(ptr);
844 } 835 }
845 numoids = j; 836 numoids = j;
846 if (c == 'E' || c == 'e') { 837 if (option_char == 'E' || option_char == 'e') {
847 jj++; 838 jj++;
848 while (j+1 >= eval_size) { 839 while (j + 1 >= eval_size) {
849 eval_size += OID_COUNT_STEP; 840 eval_size += OID_COUNT_STEP;
850 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); 841 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
851 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8); 842 memset(eval_method + eval_size - OID_COUNT_STEP, 0, 8);
852 } 843 }
853 if (c == 'E') 844 if (option_char == 'E')
854 eval_method[j+1] |= WARN_PRESENT; 845 eval_method[j + 1] |= WARN_PRESENT;
855 else if (c == 'e') 846 else if (option_char == 'e')
856 eval_method[j+1] |= CRIT_PRESENT; 847 eval_method[j + 1] |= CRIT_PRESENT;
857 } 848 }
858 break; 849 break;
859 case 'z': /* Null OID Return Check */ 850 case 'z': /* Null OID Return Check */
860 if (!is_integer (optarg)) 851 if (!is_integer(optarg))
861 usage2 (_("Exit status must be a positive integer"), optarg); 852 usage2(_("Exit status must be a positive integer"), optarg);
862 else 853 else
863 nulloid = atoi(optarg); 854 nulloid = atoi(optarg);
864 break; 855 break;
865 case 's': /* string or substring */ 856 case 's': /* string or substring */
866 strncpy (string_value, optarg, sizeof (string_value) - 1); 857 strncpy(string_value, optarg, sizeof(string_value) - 1);
867 string_value[sizeof (string_value) - 1] = 0; 858 string_value[sizeof(string_value) - 1] = 0;
868 while (jj >= eval_size) { 859 while (jj >= eval_size) {
869 eval_size += OID_COUNT_STEP; 860 eval_size += OID_COUNT_STEP;
870 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method)); 861 eval_method = realloc(eval_method, eval_size * sizeof(*eval_method));
@@ -872,17 +863,17 @@ process_arguments (int argc, char **argv)
872 } 863 }
873 eval_method[jj++] = CRIT_STRING; 864 eval_method[jj++] = CRIT_STRING;
874 break; 865 break;
875 case 'R': /* regex */ 866 case 'R': /* regex */
876 cflags = REG_ICASE; 867 cflags = REG_ICASE;
877 // fall through 868 // fall through
878 case 'r': /* regex */ 869 case 'r': /* regex */
879 cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE; 870 cflags |= REG_EXTENDED | REG_NOSUB | REG_NEWLINE;
880 strncpy (regex_expect, optarg, sizeof (regex_expect) - 1); 871 strncpy(regex_expect, optarg, sizeof(regex_expect) - 1);
881 regex_expect[sizeof (regex_expect) - 1] = 0; 872 regex_expect[sizeof(regex_expect) - 1] = 0;
882 errcode = regcomp (&preg, regex_expect, cflags); 873 errcode = regcomp(&preg, regex_expect, cflags);
883 if (errcode != 0) { 874 if (errcode != 0) {
884 regerror (errcode, &preg, errbuf, MAX_INPUT_BUFFER); 875 regerror(errcode, &preg, errbuf, MAX_INPUT_BUFFER);
885 printf (_("Could Not Compile Regular Expression")); 876 printf(_("Could Not Compile Regular Expression"));
886 return ERROR; 877 return ERROR;
887 } 878 }
888 while (jj >= eval_size) { 879 while (jj >= eval_size) {
@@ -893,64 +884,64 @@ process_arguments (int argc, char **argv)
893 eval_method[jj++] = CRIT_REGEX; 884 eval_method[jj++] = CRIT_REGEX;
894 break; 885 break;
895 886
896 /* Format */ 887 /* Format */
897 case 'd': /* delimiter */ 888 case 'd': /* delimiter */
898 delimiter = strscpy (delimiter, optarg); 889 delimiter = strscpy(delimiter, optarg);
899 break; 890 break;
900 case 'D': /* output-delimiter */ 891 case 'D': /* output-delimiter */
901 output_delim = strscpy (output_delim, optarg); 892 output_delim = strscpy(output_delim, optarg);
902 break; 893 break;
903 case 'l': /* label */ 894 case 'l': /* label */
904 nlabels++; 895 nlabels++;
905 if (nlabels > labels_size) { 896 if (nlabels > labels_size) {
906 labels_size += 8; 897 labels_size += 8;
907 labels = realloc (labels, labels_size * sizeof(*labels)); 898 labels = realloc(labels, labels_size * sizeof(*labels));
908 if (labels == NULL) 899 if (labels == NULL)
909 die (STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels); 900 die(STATE_UNKNOWN, _("Could not reallocate labels[%d]"), (int)nlabels);
910 } 901 }
911 labels[nlabels - 1] = optarg; 902 labels[nlabels - 1] = optarg;
912 ptr = thisarg (optarg); 903 char *ptr = thisarg(optarg);
913 labels[nlabels - 1] = ptr; 904 labels[nlabels - 1] = ptr;
914 if (ptr[0] == '\'') 905 if (ptr[0] == '\'')
915 labels[nlabels - 1] = ptr + 1; 906 labels[nlabels - 1] = ptr + 1;
916 while (ptr && (ptr = nextarg (ptr))) { 907 while (ptr && (ptr = nextarg(ptr))) {
917 nlabels++; 908 nlabels++;
918 if (nlabels > labels_size) { 909 if (nlabels > labels_size) {
919 labels_size += 8; 910 labels_size += 8;
920 labels = realloc (labels, labels_size * sizeof(*labels)); 911 labels = realloc(labels, labels_size * sizeof(*labels));
921 if (labels == NULL) 912 if (labels == NULL)
922 die (STATE_UNKNOWN, _("Could not reallocate labels\n")); 913 die(STATE_UNKNOWN, _("Could not reallocate labels\n"));
923 } 914 }
924 ptr = thisarg (ptr); 915 ptr = thisarg(ptr);
925 if (ptr[0] == '\'') 916 if (ptr[0] == '\'')
926 labels[nlabels - 1] = ptr + 1; 917 labels[nlabels - 1] = ptr + 1;
927 else 918 else
928 labels[nlabels - 1] = ptr; 919 labels[nlabels - 1] = ptr;
929 } 920 }
930 break; 921 break;
931 case 'u': /* units */ 922 case 'u': /* units */
932 units = optarg; 923 units = optarg;
933 nunits++; 924 nunits++;
934 if (nunits > unitv_size) { 925 if (nunits > unitv_size) {
935 unitv_size += 8; 926 unitv_size += 8;
936 unitv = realloc (unitv, unitv_size * sizeof(*unitv)); 927 unitv = realloc(unitv, unitv_size * sizeof(*unitv));
937 if (unitv == NULL) 928 if (unitv == NULL)
938 die (STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits); 929 die(STATE_UNKNOWN, _("Could not reallocate units [%d]\n"), (int)nunits);
939 } 930 }
940 unitv[nunits - 1] = optarg; 931 unitv[nunits - 1] = optarg;
941 ptr = thisarg (optarg); 932 ptr = thisarg(optarg);
942 unitv[nunits - 1] = ptr; 933 unitv[nunits - 1] = ptr;
943 if (ptr[0] == '\'') 934 if (ptr[0] == '\'')
944 unitv[nunits - 1] = ptr + 1; 935 unitv[nunits - 1] = ptr + 1;
945 while (ptr && (ptr = nextarg (ptr))) { 936 while (ptr && (ptr = nextarg(ptr))) {
946 if (nunits > unitv_size) { 937 if (nunits > unitv_size) {
947 unitv_size += 8; 938 unitv_size += 8;
948 unitv = realloc (unitv, unitv_size * sizeof(*unitv)); 939 unitv = realloc(unitv, unitv_size * sizeof(*unitv));
949 if (units == NULL) 940 if (units == NULL)
950 die (STATE_UNKNOWN, _("Could not realloc() units\n")); 941 die(STATE_UNKNOWN, _("Could not realloc() units\n"));
951 } 942 }
952 nunits++; 943 nunits++;
953 ptr = thisarg (ptr); 944 ptr = thisarg(ptr);
954 if (ptr[0] == '\'') 945 if (ptr[0] == '\'')
955 unitv[nunits - 1] = ptr + 1; 946 unitv[nunits - 1] = ptr + 1;
956 else 947 else
@@ -958,38 +949,38 @@ process_arguments (int argc, char **argv)
958 } 949 }
959 break; 950 break;
960 case L_CALCULATE_RATE: 951 case L_CALCULATE_RATE:
961 if(calculate_rate==0) 952 if (calculate_rate == 0)
962 np_enable_state(NULL, 1); 953 np_enable_state(NULL, 1);
963 calculate_rate = 1; 954 calculate_rate = 1;
964 break; 955 break;
965 case L_RATE_MULTIPLIER: 956 case L_RATE_MULTIPLIER:
966 if(!is_integer(optarg)||((rate_multiplier=atoi(optarg))<=0)) 957 if (!is_integer(optarg) || ((rate_multiplier = atoi(optarg)) <= 0))
967 usage2(_("Rate multiplier must be a positive integer"),optarg); 958 usage2(_("Rate multiplier must be a positive integer"), optarg);
968 break; 959 break;
969 case L_OFFSET: 960 case L_OFFSET:
970 offset=strtod(optarg,NULL); 961 offset = strtod(optarg, NULL);
971 break; 962 break;
972 case L_INVERT_SEARCH: 963 case L_INVERT_SEARCH:
973 invert_search=1; 964 invert_search = 1;
974 break; 965 break;
975 case 'O': 966 case 'O':
976 perf_labels=0; 967 perf_labels = 0;
977 break; 968 break;
978 case '4': 969 case '4':
979 break; 970 break;
980 case '6': 971 case '6':
981 xasprintf(&ip_version, "udp6:"); 972 xasprintf(&ip_version, "udp6:");
982 if(verbose>2) 973 if (verbose > 2)
983 printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n"); 974 printf("IPv6 detected! Will pass \"udp6:\" to snmpget.\n");
984 break; 975 break;
985 case 'M': 976 case 'M':
986 if ( strspn( optarg, "0123456789.," ) == strlen( optarg ) ) { 977 if (strspn(optarg, "0123456789.,") == strlen(optarg)) {
987 multiplier=strtod(optarg,NULL); 978 multiplier = strtod(optarg, NULL);
988 } 979 }
989 break; 980 break;
990 case 'f': 981 case 'f':
991 if (multiplier != 1.0) { 982 if (multiplier != 1.0) {
992 fmtstr=optarg; 983 fmtstr = optarg;
993 fmtstr_set = true; 984 fmtstr_set = true;
994 } 985 }
995 break; 986 break;
@@ -1002,12 +993,11 @@ process_arguments (int argc, char **argv)
1002 server_address = argv[optind]; 993 server_address = argv[optind];
1003 994
1004 if (community == NULL) 995 if (community == NULL)
1005 community = strdup (DEFAULT_COMMUNITY); 996 community = strdup(DEFAULT_COMMUNITY);
1006 997
1007 return validate_arguments (); 998 return validate_arguments();
1008} 999}
1009 1000
1010
1011/****************************************************************************** 1001/******************************************************************************
1012 1002
1013@@- 1003@@-
@@ -1026,17 +1016,13 @@ selected.</para>
1026-@@ 1016-@@
1027******************************************************************************/ 1017******************************************************************************/
1028 1018
1029 1019static int validate_arguments() {
1030
1031static int
1032validate_arguments ()
1033{
1034 /* check whether to load locally installed MIBS (CPU/disk intensive) */ 1020 /* check whether to load locally installed MIBS (CPU/disk intensive) */
1035 if (miblist == NULL) { 1021 if (miblist == NULL) {
1036 if (needmibs) { 1022 if (needmibs) {
1037 miblist = strdup (DEFAULT_MIBLIST); 1023 miblist = strdup(DEFAULT_MIBLIST);
1038 }else{ 1024 } else {
1039 miblist = ""; /* don't read any mib files for numeric oids */ 1025 miblist = ""; /* don't read any mib files for numeric oids */
1040 } 1026 }
1041 } 1027 }
1042 1028
@@ -1051,18 +1037,17 @@ validate_arguments ()
1051 if (proto == NULL) 1037 if (proto == NULL)
1052 xasprintf(&proto, DEFAULT_PROTOCOL); 1038 xasprintf(&proto, DEFAULT_PROTOCOL);
1053 1039
1054 if ((strcmp(proto,"1") == 0) || (strcmp(proto, "2c")==0)) { /* snmpv1 or snmpv2c */ 1040 if ((strcmp(proto, "1") == 0) || (strcmp(proto, "2c") == 0)) { /* snmpv1 or snmpv2c */
1055 numauthpriv = 2; 1041 numauthpriv = 2;
1056 authpriv = calloc (numauthpriv, sizeof (char *)); 1042 authpriv = calloc(numauthpriv, sizeof(char *));
1057 authpriv[0] = strdup ("-c"); 1043 authpriv[0] = strdup("-c");
1058 authpriv[1] = strdup (community); 1044 authpriv[1] = strdup(community);
1059 } 1045 } else if (strcmp(proto, "3") == 0) { /* snmpv3 args */
1060 else if ( strcmp (proto, "3") == 0 ) { /* snmpv3 args */
1061 if (!(context == NULL)) { 1046 if (!(context == NULL)) {
1062 numcontext = 2; 1047 numcontext = 2;
1063 contextargs = calloc (numcontext, sizeof (char *)); 1048 contextargs = calloc(numcontext, sizeof(char *));
1064 contextargs[0] = strdup ("-n"); 1049 contextargs[0] = strdup("-n");
1065 contextargs[1] = strdup (context); 1050 contextargs[1] = strdup(context);
1066 } 1051 }
1067 1052
1068 if (seclevel == NULL) 1053 if (seclevel == NULL)
@@ -1073,284 +1058,266 @@ validate_arguments ()
1073 1058
1074 if (strcmp(seclevel, "noAuthNoPriv") == 0) { 1059 if (strcmp(seclevel, "noAuthNoPriv") == 0) {
1075 numauthpriv = 4; 1060 numauthpriv = 4;
1076 authpriv = calloc (numauthpriv, sizeof (char *)); 1061 authpriv = calloc(numauthpriv, sizeof(char *));
1077 authpriv[0] = strdup ("-l"); 1062 authpriv[0] = strdup("-l");
1078 authpriv[1] = strdup ("noAuthNoPriv"); 1063 authpriv[1] = strdup("noAuthNoPriv");
1079 authpriv[2] = strdup ("-u"); 1064 authpriv[2] = strdup("-u");
1080 authpriv[3] = strdup (secname); 1065 authpriv[3] = strdup(secname);
1081 } else { 1066 } else {
1082 if (! ( (strcmp(seclevel, "authNoPriv")==0) || (strcmp(seclevel, "authPriv")==0) ) ) { 1067 if (!((strcmp(seclevel, "authNoPriv") == 0) || (strcmp(seclevel, "authPriv") == 0))) {
1083 usage2 (_("Invalid seclevel"), seclevel); 1068 usage2(_("Invalid seclevel"), seclevel);
1084 } 1069 }
1085 1070
1086 if (authproto == NULL ) 1071 if (authproto == NULL)
1087 xasprintf(&authproto, DEFAULT_AUTH_PROTOCOL); 1072 xasprintf(&authproto, DEFAULT_AUTH_PROTOCOL);
1088 1073
1089 if (authpasswd == NULL) 1074 if (authpasswd == NULL)
1090 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "authpasswd"); 1075 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "authpasswd");
1091 1076
1092 if ( strcmp(seclevel, "authNoPriv") == 0 ) { 1077 if (strcmp(seclevel, "authNoPriv") == 0) {
1093 numauthpriv = 8; 1078 numauthpriv = 8;
1094 authpriv = calloc (numauthpriv, sizeof (char *)); 1079 authpriv = calloc(numauthpriv, sizeof(char *));
1095 authpriv[0] = strdup ("-l"); 1080 authpriv[0] = strdup("-l");
1096 authpriv[1] = strdup ("authNoPriv"); 1081 authpriv[1] = strdup("authNoPriv");
1097 authpriv[2] = strdup ("-a"); 1082 authpriv[2] = strdup("-a");
1098 authpriv[3] = strdup (authproto); 1083 authpriv[3] = strdup(authproto);
1099 authpriv[4] = strdup ("-u"); 1084 authpriv[4] = strdup("-u");
1100 authpriv[5] = strdup (secname); 1085 authpriv[5] = strdup(secname);
1101 authpriv[6] = strdup ("-A"); 1086 authpriv[6] = strdup("-A");
1102 authpriv[7] = strdup (authpasswd); 1087 authpriv[7] = strdup(authpasswd);
1103 } else if ( strcmp(seclevel, "authPriv") == 0 ) { 1088 } else if (strcmp(seclevel, "authPriv") == 0) {
1104 if (privproto == NULL ) 1089 if (privproto == NULL)
1105 xasprintf(&privproto, DEFAULT_PRIV_PROTOCOL); 1090 xasprintf(&privproto, DEFAULT_PRIV_PROTOCOL);
1106 1091
1107 if (privpasswd == NULL) 1092 if (privpasswd == NULL)
1108 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "privpasswd"); 1093 die(STATE_UNKNOWN, _("Required parameter: %s\n"), "privpasswd");
1109 1094
1110 numauthpriv = 12; 1095 numauthpriv = 12;
1111 authpriv = calloc (numauthpriv, sizeof (char *)); 1096 authpriv = calloc(numauthpriv, sizeof(char *));
1112 authpriv[0] = strdup ("-l"); 1097 authpriv[0] = strdup("-l");
1113 authpriv[1] = strdup ("authPriv"); 1098 authpriv[1] = strdup("authPriv");
1114 authpriv[2] = strdup ("-a"); 1099 authpriv[2] = strdup("-a");
1115 authpriv[3] = strdup (authproto); 1100 authpriv[3] = strdup(authproto);
1116 authpriv[4] = strdup ("-u"); 1101 authpriv[4] = strdup("-u");
1117 authpriv[5] = strdup (secname); 1102 authpriv[5] = strdup(secname);
1118 authpriv[6] = strdup ("-A"); 1103 authpriv[6] = strdup("-A");
1119 authpriv[7] = strdup (authpasswd); 1104 authpriv[7] = strdup(authpasswd);
1120 authpriv[8] = strdup ("-x"); 1105 authpriv[8] = strdup("-x");
1121 authpriv[9] = strdup (privproto); 1106 authpriv[9] = strdup(privproto);
1122 authpriv[10] = strdup ("-X"); 1107 authpriv[10] = strdup("-X");
1123 authpriv[11] = strdup (privpasswd); 1108 authpriv[11] = strdup(privpasswd);
1124 } 1109 }
1125 } 1110 }
1126 1111
1127 } 1112 } else {
1128 else { 1113 usage2(_("Invalid SNMP version"), proto);
1129 usage2 (_("Invalid SNMP version"), proto);
1130 } 1114 }
1131 1115
1132 return OK; 1116 return OK;
1133} 1117}
1134 1118
1135
1136
1137/* trim leading whitespace 1119/* trim leading whitespace
1138 if there is a leading quote, make sure it balances */ 1120 if there is a leading quote, make sure it balances */
1139 1121
1140static char * 1122static char *thisarg(char *str) {
1141thisarg (char *str) 1123 str += strspn(str, " \t\r\n"); /* trim any leading whitespace */
1142{ 1124 if (str[0] == '\'') { /* handle SIMPLE quoted strings */
1143 str += strspn (str, " \t\r\n"); /* trim any leading whitespace */ 1125 if (strlen(str) == 1 || !strstr(str + 1, "'"))
1144 if (str[0] == '\'') { /* handle SIMPLE quoted strings */ 1126 die(STATE_UNKNOWN, _("Unbalanced quotes\n"));
1145 if (strlen (str) == 1 || !strstr (str + 1, "'"))
1146 die (STATE_UNKNOWN, _("Unbalanced quotes\n"));
1147 } 1127 }
1148 return str; 1128 return str;
1149} 1129}
1150 1130
1151
1152
1153/* if there's a leading quote, advance to the trailing quote 1131/* if there's a leading quote, advance to the trailing quote
1154 set the trailing quote to '\x0' 1132 set the trailing quote to '\x0'
1155 if the string continues, advance beyond the comma */ 1133 if the string continues, advance beyond the comma */
1156 1134
1157static char * 1135static char *nextarg(char *str) {
1158nextarg (char *str)
1159{
1160 if (str[0] == '\'') { 1136 if (str[0] == '\'') {
1161 str[0] = 0; 1137 str[0] = 0;
1162 if (strlen (str) > 1) { 1138 if (strlen(str) > 1) {
1163 str = strstr (str + 1, "'"); 1139 str = strstr(str + 1, "'");
1164 return (++str); 1140 return (++str);
1165 } 1141 } else {
1166 else {
1167 return NULL; 1142 return NULL;
1168 } 1143 }
1169 } 1144 }
1170 if (str[0] == ',') { 1145 if (str[0] == ',') {
1171 str[0] = 0; 1146 str[0] = 0;
1172 if (strlen (str) > 1) { 1147 if (strlen(str) > 1) {
1173 return (++str); 1148 return (++str);
1174 } 1149 } else {
1175 else {
1176 return NULL; 1150 return NULL;
1177 } 1151 }
1178 } 1152 }
1179 if ((str = strstr (str, ",")) && strlen (str) > 1) { 1153 if ((str = strstr(str, ",")) && strlen(str) > 1) {
1180 str[0] = 0; 1154 str[0] = 0;
1181 return (++str); 1155 return (++str);
1182 } 1156 }
1183 return NULL; 1157 return NULL;
1184} 1158}
1185 1159
1186
1187
1188/* multiply result (values 0 < n < 1 work as divider) */ 1160/* multiply result (values 0 < n < 1 work as divider) */
1189static char * 1161static char *multiply(char *str) {
1190multiply (char *str) 1162 if (multiplier == 1)
1191{ 1163 return (str);
1192 char *endptr;
1193 double val;
1194 char *conv = "%f";
1195
1196 if(multiplier == 1)
1197 return(str);
1198 1164
1199 if(verbose>2) 1165 if (verbose > 2)
1200 printf(" multiply input: %s\n", str); 1166 printf(" multiply input: %s\n", str);
1201 1167
1202 val = strtod (str, &endptr); 1168 char *endptr;
1169 double val = strtod(str, &endptr);
1203 if ((val == 0.0) && (endptr == str)) { 1170 if ((val == 0.0) && (endptr == str)) {
1204 die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str); 1171 die(STATE_UNKNOWN, _("multiplier set (%.1f), but input is not a number: %s"), multiplier, str);
1205 } 1172 }
1206 1173
1207 if(verbose>2) 1174 if (verbose > 2)
1208 printf(" multiply extracted double: %f\n", val); 1175 printf(" multiply extracted double: %f\n", val);
1176
1209 val *= multiplier; 1177 val *= multiplier;
1178 char *conv = "%f";
1210 if (fmtstr_set) { 1179 if (fmtstr_set) {
1211 conv = fmtstr; 1180 conv = fmtstr;
1212 } 1181 }
1213 if (val == (int)val) { 1182 if (val == (int)val) {
1214 snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val); 1183 snprintf(buffer, DEFAULT_BUFFER_SIZE, "%.0f", val);
1215 } else { 1184 } else {
1216 if(verbose>2) 1185 if (verbose > 2)
1217 printf(" multiply using format: %s\n", conv); 1186 printf(" multiply using format: %s\n", conv);
1218 snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val); 1187 snprintf(buffer, DEFAULT_BUFFER_SIZE, conv, val);
1219 } 1188 }
1220 if(verbose>2) 1189 if (verbose > 2)
1221 printf(" multiply result: %s\n", buffer); 1190 printf(" multiply result: %s\n", buffer);
1222 return buffer; 1191 return buffer;
1223} 1192}
1224 1193
1194static void print_help(void) {
1195 print_revision(progname, NP_VERSION);
1225 1196
1226static void 1197 printf(COPYRIGHT, copyright, email);
1227print_help (void)
1228{
1229 print_revision (progname, NP_VERSION);
1230
1231 printf (COPYRIGHT, copyright, email);
1232 1198
1233 printf ("%s\n", _("Check status of remote machines and obtain system information via SNMP")); 1199 printf("%s\n", _("Check status of remote machines and obtain system information via SNMP"));
1234 1200
1235 printf ("\n\n"); 1201 printf("\n\n");
1236 1202
1237 print_usage (); 1203 print_usage();
1238 1204
1239 printf (UT_HELP_VRSN); 1205 printf(UT_HELP_VRSN);
1240 printf (UT_EXTRA_OPTS); 1206 printf(UT_EXTRA_OPTS);
1241 printf (UT_IPv46); 1207 printf(UT_IPv46);
1242 1208
1243 printf (UT_HOST_PORT, 'p', DEFAULT_PORT); 1209 printf(UT_HOST_PORT, 'p', DEFAULT_PORT);
1244 1210
1245 /* SNMP and Authentication Protocol */ 1211 /* SNMP and Authentication Protocol */
1246 printf (" %s\n", "-n, --next"); 1212 printf(" %s\n", "-n, --next");
1247 printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET")); 1213 printf(" %s\n", _("Use SNMP GETNEXT instead of SNMP GET"));
1248 printf (" %s\n", "-P, --protocol=[1|2c|3]"); 1214 printf(" %s\n", "-P, --protocol=[1|2c|3]");
1249 printf (" %s\n", _("SNMP protocol version")); 1215 printf(" %s\n", _("SNMP protocol version"));
1250 printf (" %s\n", "-N, --context=CONTEXT"); 1216 printf(" %s\n", "-N, --context=CONTEXT");
1251 printf (" %s\n", _("SNMPv3 context")); 1217 printf(" %s\n", _("SNMPv3 context"));
1252 printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]"); 1218 printf(" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]");
1253 printf (" %s\n", _("SNMPv3 securityLevel")); 1219 printf(" %s\n", _("SNMPv3 securityLevel"));
1254 printf (" %s\n", "-a, --authproto=AUTHENTICATION_PROTOCOL"); 1220 printf(" %s\n", "-a, --authproto=AUTHENTICATION_PROTOCOL");
1255 printf (" %s\n", _("SNMPv3 authentication protocol (default MD5), available options depend on the specific version of the net-snmp tools")); 1221 printf(" %s\n",
1256 printf (" %s\n", _("if < 5.8 SHA (1) and MD5 should be available, if >= 5.8 additionally SHA-224, SHA-256, SHA-384 and SHA-512")); 1222 _("SNMPv3 authentication protocol (default MD5), available options depend on the specific version of the net-snmp tools"));
1257 printf (" %s\n", "-x, --privproto=PRIVACY_PROTOCOL"); 1223 printf(" %s\n", _("if < 5.8 SHA (1) and MD5 should be available, if >= 5.8 additionally SHA-224, SHA-256, SHA-384 and SHA-512"));
1258 printf (" %s\n", _("SNMPv3 privacy protocol (default DES), available options depend on the specific version of the net-snmp tools")); 1224 printf(" %s\n", "-x, --privproto=PRIVACY_PROTOCOL");
1259 printf (" %s\n", _("if < 5.8 DES and AES should be available, if >= 5.8 additionally AES-192 and AES-256")); 1225 printf(" %s\n", _("SNMPv3 privacy protocol (default DES), available options depend on the specific version of the net-snmp tools"));
1226 printf(" %s\n", _("if < 5.8 DES and AES should be available, if >= 5.8 additionally AES-192 and AES-256"));
1260 1227
1261 /* Authentication Tokens*/ 1228 /* Authentication Tokens*/
1262 printf (" %s\n", "-C, --community=STRING"); 1229 printf(" %s\n", "-C, --community=STRING");
1263 printf (" %s ", _("Optional community string for SNMP communication")); 1230 printf(" %s ", _("Optional community string for SNMP communication"));
1264 printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY); 1231 printf("(%s \"%s\")\n", _("default is"), DEFAULT_COMMUNITY);
1265 printf (" %s\n", "-U, --secname=USERNAME"); 1232 printf(" %s\n", "-U, --secname=USERNAME");
1266 printf (" %s\n", _("SNMPv3 username")); 1233 printf(" %s\n", _("SNMPv3 username"));
1267 printf (" %s\n", "-A, --authpasswd=PASSWORD"); 1234 printf(" %s\n", "-A, --authpasswd=PASSWORD");
1268 printf (" %s\n", _("SNMPv3 authentication password")); 1235 printf(" %s\n", _("SNMPv3 authentication password"));
1269 printf (" %s\n", "-X, --privpasswd=PASSWORD"); 1236 printf(" %s\n", "-X, --privpasswd=PASSWORD");
1270 printf (" %s\n", _("SNMPv3 privacy password")); 1237 printf(" %s\n", _("SNMPv3 privacy password"));
1271 1238
1272 /* OID Stuff */ 1239 /* OID Stuff */
1273 printf (" %s\n", "-o, --oid=OID(s)"); 1240 printf(" %s\n", "-o, --oid=OID(s)");
1274 printf (" %s\n", _("Object identifier(s) or SNMP variables whose value you wish to query")); 1241 printf(" %s\n", _("Object identifier(s) or SNMP variables whose value you wish to query"));
1275 printf (" %s\n", "-m, --miblist=STRING"); 1242 printf(" %s\n", "-m, --miblist=STRING");
1276 printf (" %s\n", _("List of MIBS to be loaded (default = none if using numeric OIDs or 'ALL'")); 1243 printf(" %s\n", _("List of MIBS to be loaded (default = none if using numeric OIDs or 'ALL'"));
1277 printf (" %s\n", _("for symbolic OIDs.)")); 1244 printf(" %s\n", _("for symbolic OIDs.)"));
1278 printf (" %s\n", "-d, --delimiter=STRING"); 1245 printf(" %s\n", "-d, --delimiter=STRING");
1279 printf (" %s \"%s\"\n", _("Delimiter to use when parsing returned data. Default is"), DEFAULT_DELIMITER); 1246 printf(" %s \"%s\"\n", _("Delimiter to use when parsing returned data. Default is"), DEFAULT_DELIMITER);
1280 printf (" %s\n", _("Any data on the right hand side of the delimiter is considered")); 1247 printf(" %s\n", _("Any data on the right hand side of the delimiter is considered"));
1281 printf (" %s\n", _("to be the data that should be used in the evaluation.")); 1248 printf(" %s\n", _("to be the data that should be used in the evaluation."));
1282 printf (" %s\n", "-z, --nulloid=#"); 1249 printf(" %s\n", "-z, --nulloid=#");
1283 printf (" %s\n", _("If the check returns a 0 length string or NULL value")); 1250 printf(" %s\n", _("If the check returns a 0 length string or NULL value"));
1284 printf (" %s\n", _("This option allows you to choose what status you want it to exit")); 1251 printf(" %s\n", _("This option allows you to choose what status you want it to exit"));
1285 printf (" %s\n", _("Excluding this option renders the default exit of 3(STATE_UNKNOWN)")); 1252 printf(" %s\n", _("Excluding this option renders the default exit of 3(STATE_UNKNOWN)"));
1286 printf (" %s\n", _("0 = OK")); 1253 printf(" %s\n", _("0 = OK"));
1287 printf (" %s\n", _("1 = WARNING")); 1254 printf(" %s\n", _("1 = WARNING"));
1288 printf (" %s\n", _("2 = CRITICAL")); 1255 printf(" %s\n", _("2 = CRITICAL"));
1289 printf (" %s\n", _("3 = UNKNOWN")); 1256 printf(" %s\n", _("3 = UNKNOWN"));
1290 1257
1291 /* Tests Against Integers */ 1258 /* Tests Against Integers */
1292 printf (" %s\n", "-w, --warning=THRESHOLD(s)"); 1259 printf(" %s\n", "-w, --warning=THRESHOLD(s)");
1293 printf (" %s\n", _("Warning threshold range(s)")); 1260 printf(" %s\n", _("Warning threshold range(s)"));
1294 printf (" %s\n", "-c, --critical=THRESHOLD(s)"); 1261 printf(" %s\n", "-c, --critical=THRESHOLD(s)");
1295 printf (" %s\n", _("Critical threshold range(s)")); 1262 printf(" %s\n", _("Critical threshold range(s)"));
1296 printf (" %s\n", "--rate"); 1263 printf(" %s\n", "--rate");
1297 printf (" %s\n", _("Enable rate calculation. See 'Rate Calculation' below")); 1264 printf(" %s\n", _("Enable rate calculation. See 'Rate Calculation' below"));
1298 printf (" %s\n", "--rate-multiplier"); 1265 printf(" %s\n", "--rate-multiplier");
1299 printf (" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute")); 1266 printf(" %s\n", _("Converts rate per second. For example, set to 60 to convert to per minute"));
1300 printf (" %s\n", "--offset=OFFSET"); 1267 printf(" %s\n", "--offset=OFFSET");
1301 printf (" %s\n", _("Add/subtract the specified OFFSET to numeric sensor data")); 1268 printf(" %s\n", _("Add/subtract the specified OFFSET to numeric sensor data"));
1302 1269
1303 /* Tests Against Strings */ 1270 /* Tests Against Strings */
1304 printf (" %s\n", "-s, --string=STRING"); 1271 printf(" %s\n", "-s, --string=STRING");
1305 printf (" %s\n", _("Return OK state (for that OID) if STRING is an exact match")); 1272 printf(" %s\n", _("Return OK state (for that OID) if STRING is an exact match"));
1306 printf (" %s\n", "-r, --ereg=REGEX"); 1273 printf(" %s\n", "-r, --ereg=REGEX");
1307 printf (" %s\n", _("Return OK state (for that OID) if extended regular expression REGEX matches")); 1274 printf(" %s\n", _("Return OK state (for that OID) if extended regular expression REGEX matches"));
1308 printf (" %s\n", "-R, --eregi=REGEX"); 1275 printf(" %s\n", "-R, --eregi=REGEX");
1309 printf (" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches")); 1276 printf(" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches"));
1310 printf (" %s\n", "--invert-search"); 1277 printf(" %s\n", "--invert-search");
1311 printf (" %s\n", _("Invert search result (CRITICAL if found)")); 1278 printf(" %s\n", _("Invert search result (CRITICAL if found)"));
1312 1279
1313 /* Output Formatting */ 1280 /* Output Formatting */
1314 printf (" %s\n", "-l, --label=STRING"); 1281 printf(" %s\n", "-l, --label=STRING");
1315 printf (" %s\n", _("Prefix label for output from plugin")); 1282 printf(" %s\n", _("Prefix label for output from plugin"));
1316 printf (" %s\n", "-u, --units=STRING"); 1283 printf(" %s\n", "-u, --units=STRING");
1317 printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.').")); 1284 printf(" %s\n", _("Units label(s) for output data (e.g., 'sec.')."));
1318 printf (" %s\n", "-D, --output-delimiter=STRING"); 1285 printf(" %s\n", "-D, --output-delimiter=STRING");
1319 printf (" %s\n", _("Separates output on multiple OID requests")); 1286 printf(" %s\n", _("Separates output on multiple OID requests"));
1320 printf (" %s\n", "-M, --multiplier=FLOAT"); 1287 printf(" %s\n", "-M, --multiplier=FLOAT");
1321 printf (" %s\n", _("Multiplies current value, 0 < n < 1 works as divider, defaults to 1")); 1288 printf(" %s\n", _("Multiplies current value, 0 < n < 1 works as divider, defaults to 1"));
1322 printf (" %s\n", "-f, --fmtstr=STRING"); 1289 printf(" %s\n", "-f, --fmtstr=STRING");
1323 printf (" %s\n", _("C-style format string for float values (see option -M)")); 1290 printf(" %s\n", _("C-style format string for float values (see option -M)"));
1324 1291
1325 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 1292 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
1326 printf (" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5")); 1293 printf(" %s\n", _("NOTE the final timeout value is calculated using this formula: timeout_interval * retries + 5"));
1327 printf (" %s\n", "-e, --retries=INTEGER"); 1294 printf(" %s\n", "-e, --retries=INTEGER");
1328 printf (" %s%i\n", _("Number of retries to be used in the requests, default: "), DEFAULT_RETRIES); 1295 printf(" %s%i\n", _("Number of retries to be used in the requests, default: "), DEFAULT_RETRIES);
1329 1296
1330 printf (" %s\n", "-O, --perf-oids"); 1297 printf(" %s\n", "-O, --perf-oids");
1331 printf (" %s\n", _("Label performance data with OIDs instead of --label's")); 1298 printf(" %s\n", _("Label performance data with OIDs instead of --label's"));
1332 1299
1333 printf (" %s\n", "--ignore-mib-parsing-errors"); 1300 printf(" %s\n", "--ignore-mib-parsing-errors");
1334 printf (" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files")); 1301 printf(" %s\n", _("Tell snmpget to not print errors encountered when parsing MIB files"));
1335 1302
1336 printf (UT_VERBOSE); 1303 printf(UT_VERBOSE);
1337 1304
1338 printf ("\n"); 1305 printf("\n");
1339 printf ("%s\n", _("This plugin uses the 'snmpget' command included with the NET-SNMP package.")); 1306 printf("%s\n", _("This plugin uses the 'snmpget' command included with the NET-SNMP package."));
1340 printf ("%s\n", _("if you don't have the package installed, you will need to download it from")); 1307 printf("%s\n", _("if you don't have the package installed, you will need to download it from"));
1341 printf ("%s\n", _("http://net-snmp.sourceforge.net before you can use this plugin.")); 1308 printf("%s\n", _("http://net-snmp.sourceforge.net before you can use this plugin."));
1342 1309
1343 printf ("\n"); 1310 printf("\n");
1344 printf ("%s\n", _("Notes:")); 1311 printf("%s\n", _("Notes:"));
1345 printf (" %s\n", _("- Multiple OIDs (and labels) may be indicated by a comma or space-delimited ")); 1312 printf(" %s\n", _("- Multiple OIDs (and labels) may be indicated by a comma or space-delimited "));
1346 printf (" %s\n", _("list (lists with internal spaces must be quoted).")); 1313 printf(" %s\n", _("list (lists with internal spaces must be quoted)."));
1347 1314
1348 printf(" -%s", UT_THRESHOLDS_NOTES); 1315 printf(" -%s", UT_THRESHOLDS_NOTES);
1349 1316
1350 printf (" %s\n", _("- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'")); 1317 printf(" %s\n", _("- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'"));
1351 printf (" %s\n", _("- Note that only one string and one regex may be checked at present")); 1318 printf(" %s\n", _("- Note that only one string and one regex may be checked at present"));
1352 printf (" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value")); 1319 printf(" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value"));
1353 printf (" %s\n", _("returned from the SNMP query is an unsigned integer.")); 1320 printf(" %s\n", _("returned from the SNMP query is an unsigned integer."));
1354 1321
1355 printf("\n"); 1322 printf("\n");
1356 printf("%s\n", _("Rate Calculation:")); 1323 printf("%s\n", _("Rate Calculation:"));
@@ -1362,19 +1329,15 @@ print_help (void)
1362 printf(" %s\n", _("The state is uniquely determined by the arguments to the plugin, so")); 1329 printf(" %s\n", _("The state is uniquely determined by the arguments to the plugin, so"));
1363 printf(" %s\n", _("changing the arguments will create a new state file.")); 1330 printf(" %s\n", _("changing the arguments will create a new state file."));
1364 1331
1365 printf (UT_SUPPORT); 1332 printf(UT_SUPPORT);
1366} 1333}
1367 1334
1368 1335void print_usage(void) {
1369 1336 printf("%s\n", _("Usage:"));
1370void 1337 printf("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n", progname);
1371print_usage (void) 1338 printf("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n");
1372{ 1339 printf("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");
1373 printf ("%s\n", _("Usage:")); 1340 printf("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n");
1374 printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname); 1341 printf("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n");
1375 printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n"); 1342 printf("[-M multiplier [-f format]]\n");
1376 printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");
1377 printf ("[-m miblist] [-P snmp version] [-N context] [-L seclevel] [-U secname]\n");
1378 printf ("[-a authproto] [-A authpasswd] [-x privproto] [-X privpasswd] [-4|6]\n");
1379 printf ("[-M multiplier [-f format]]\n");
1380} 1343}