1 /******************************************************************************
3 * Nagios check_snmp plugin
6 * Copyright (c) 1999-2006 nagios-plugins team
8 * Last Modified: $Date$
12 * This file contains the check_snmp plugin
14 * License Information:
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 ******************************************************************************/
34 const char *progname
= "check_snmp";
35 const char *revision
= "$Revision$";
36 const char *copyright
= "1999-2006";
37 const char *email
= "nagiosplug-devel@lists.sourceforge.net";
43 #define DEFAULT_COMMUNITY "public"
44 #define DEFAULT_PORT "161"
45 #define DEFAULT_MIBLIST "ALL"
46 #define DEFAULT_PROTOCOL "1"
47 #define DEFAULT_TIMEOUT 1
48 #define DEFAULT_RETRIES 5
49 #define DEFAULT_AUTH_PROTOCOL "MD5"
50 #define DEFAULT_DELIMITER "="
51 #define DEFAULT_OUTPUT_DELIMITER " "
53 #define mark(a) ((a)!=0?"*":"")
56 #define CRIT_PRESENT 1
65 #define CRIT_RANGE 512
66 #define WARN_PRESENT 1024
67 #define WARN_STRING 2048
68 #define WARN_REGEX 4096
73 #define WARN_EQ 131072
74 #define WARN_NE 262144
75 #define WARN_RANGE 524288
78 #define MAX_DELIM_LENGTH 8
80 int process_arguments (int, char **);
81 int validate_arguments (void);
82 char *clarify_message (char *);
84 int lu_getll (unsigned long *, char *);
85 int lu_getul (unsigned long *, char *);
86 char *thisarg (char *str
);
87 char *nextarg (char *str
);
88 void print_usage (void);
89 void print_help (void);
92 char regex_expect
[MAX_INPUT_BUFFER
] = "";
94 regmatch_t pmatch
[10];
95 char timestamp
[10] = "";
96 char errbuf
[MAX_INPUT_BUFFER
];
97 char perfstr
[MAX_INPUT_BUFFER
];
98 int cflags
= REG_EXTENDED
| REG_NOSUB
| REG_NEWLINE
;
102 char *server_address
= NULL
;
103 char *community
= NULL
;
104 char *authpriv
= NULL
;
106 char *seclevel
= NULL
;
107 char *secname
= NULL
;
108 char *authproto
= NULL
;
109 char *authpasswd
= NULL
;
110 char *privpasswd
= NULL
;
115 char string_value
[MAX_INPUT_BUFFER
] = "";
116 char **labels
= NULL
;
119 size_t labels_size
= 8;
121 size_t unitv_size
= 8;
123 int usesnmpgetnext
= FALSE
;
124 unsigned long lower_warn_lim
[MAX_OIDS
];
125 unsigned long upper_warn_lim
[MAX_OIDS
];
126 unsigned long lower_crit_lim
[MAX_OIDS
];
127 unsigned long upper_crit_lim
[MAX_OIDS
];
128 unsigned long response_value
[MAX_OIDS
];
129 int check_warning_value
= FALSE
;
130 int check_critical_value
= FALSE
;
132 unsigned long eval_method
[MAX_OIDS
];
135 char *miblist
= NULL
;
136 int needmibs
= FALSE
;
140 main (int argc
, char **argv
)
143 int iresult
= STATE_UNKNOWN
;
145 int result
= STATE_DEPENDENT
;
146 char input_buffer
[MAX_INPUT_BUFFER
];
147 char *command_line
= NULL
;
148 char *response
= NULL
;
155 char *str
[MAX_INPUT_BUFFER
];
157 setlocale (LC_ALL
, "");
158 bindtextdomain (PACKAGE
, LOCALEDIR
);
159 textdomain (PACKAGE
);
161 labels
= malloc (labels_size
);
162 unitv
= malloc (unitv_size
);
163 for (i
= 0; i
< MAX_OIDS
; i
++)
164 eval_method
[i
] = CHECK_UNDEF
;
168 label
= strdup ("SNMP");
170 port
= strdup (DEFAULT_PORT
);
171 outbuff
= strdup ("");
172 output
= strdup ("");
173 delimiter
= strdup (" = ");
174 output_delim
= strdup (DEFAULT_OUTPUT_DELIMITER
);
175 /* miblist = strdup (DEFAULT_MIBLIST); */
176 timeout_interval
= DEFAULT_TIMEOUT
;
177 retries
= DEFAULT_RETRIES
;
179 if (process_arguments (argc
, argv
) == ERROR
)
180 usage4 (_("Could not parse arguments"));
182 /* create the command line to execute */
183 if(usesnmpgetnext
== TRUE
) {
184 asprintf(&command_line
, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
185 PATH_TO_SNMPGETNEXT
, timeout_interval
, retries
, miblist
, proto
,
186 authpriv
, server_address
, port
, oid
);
189 asprintf (&command_line
, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
190 PATH_TO_SNMPGET
, timeout_interval
, retries
, miblist
, proto
,
191 authpriv
, server_address
, port
, oid
);
195 printf ("%s\n", command_line
);
198 /* run the command */
199 child_process
= spopen (command_line
);
200 if (child_process
== NULL
) {
201 printf (_("Could not open pipe: %s\n"), command_line
);
202 exit (STATE_UNKNOWN
);
205 child_stderr
= fdopen (child_stderr_array
[fileno (child_process
)], "r");
206 if (child_stderr
== NULL
) {
207 printf (_("Could not open stderr for %s\n"), command_line
);
210 while (fgets (input_buffer
, MAX_INPUT_BUFFER
- 1, child_process
))
211 asprintf (&output
, "%s%s", output
, input_buffer
);
214 printf ("%s\n", output
);
218 strcat(perfstr
, "| ");
222 foo
= strstr (ptr
, delimiter
);
223 strncat(perfstr
, ptr
, foo
-ptr
);
229 ptr
+= strlen (delimiter
);
230 ptr
+= strspn (ptr
, " ");
236 response
= strpcpy (response
, ptr
, "\"");
237 ptr
= strpbrk (ptr
, "\"");
238 ptr
+= strspn (ptr
, "\"\n");
241 response
= strpcpy (response
, ptr
, "\n");
242 ptr
= strpbrk (ptr
, "\n");
243 ptr
+= strspn (ptr
, "\n");
245 (strstr (ptr
, delimiter
) &&
246 strstr (ptr
, "\n") && strstr (ptr
, "\n") < strstr (ptr
, delimiter
)) {
247 response
= strpcat (response
, ptr
, "\n");
248 ptr
= strpbrk (ptr
, "\n");
250 if (ptr
&& strstr (ptr
, delimiter
) == NULL
) {
251 asprintf (&response
, "%s%s", response
, ptr
);
256 /* We strip out the datatype indicator for PHBs */
257 if (strstr (response
, "Gauge: "))
258 show
= strstr (response
, "Gauge: ") + 7;
259 else if (strstr (response
, "Gauge32: "))
260 show
= strstr (response
, "Gauge32: ") + 9;
261 else if (strstr (response
, "Counter32: ")) {
262 show
= strstr (response
, "Counter32: ") + 11;
265 else if (strstr (response
, "INTEGER: "))
266 show
= strstr (response
, "INTEGER: ") + 9;
267 else if (strstr (response
, "STRING: "))
268 show
= strstr (response
, "STRING: ") + 8;
273 iresult
= STATE_DEPENDENT
;
275 /* Process this block for integer comparisons */
276 if (eval_method
[i
] & CRIT_GT
||
277 eval_method
[i
] & CRIT_LT
||
278 eval_method
[i
] & CRIT_GE
||
279 eval_method
[i
] & CRIT_LE
||
280 eval_method
[i
] & CRIT_EQ
||
281 eval_method
[i
] & CRIT_NE
||
282 eval_method
[i
] & WARN_GT
||
283 eval_method
[i
] & WARN_LT
||
284 eval_method
[i
] & WARN_GE
||
285 eval_method
[i
] & WARN_LE
||
286 eval_method
[i
] & WARN_EQ
||
287 eval_method
[i
] & WARN_NE
) {
288 p2
= strpbrk (p2
, "0123456789");
290 die (STATE_UNKNOWN
,_("No valid data returned"));
291 response_value
[i
] = strtoul (p2
, NULL
, 10);
292 iresult
= check_num (i
);
293 asprintf (&show
, "%lu", response_value
[i
]);
296 /* Process this block for string matching */
297 else if (eval_method
[i
] & CRIT_STRING
) {
298 if (strcmp (show
, string_value
))
299 iresult
= STATE_CRITICAL
;
304 /* Process this block for regex matching */
305 else if (eval_method
[i
] & CRIT_REGEX
) {
306 excode
= regexec (&preg
, response
, 10, pmatch
, eflags
);
310 else if (excode
!= REG_NOMATCH
) {
311 regerror (excode
, &preg
, errbuf
, MAX_INPUT_BUFFER
);
312 printf (_("Execute Error: %s\n"), errbuf
);
313 exit (STATE_CRITICAL
);
316 iresult
= STATE_CRITICAL
;
320 /* Process this block for existence-nonexistence checks */
322 if (eval_method
[i
] & CRIT_PRESENT
)
323 iresult
= STATE_CRITICAL
;
324 else if (eval_method
[i
] & WARN_PRESENT
)
325 iresult
= STATE_WARNING
;
326 else if (response
&& iresult
== STATE_DEPENDENT
)
330 /* Result is the worst outcome of all the OIDs tested */
331 result
= max_state (result
, iresult
);
333 /* Prepend a label for this OID if there is one */
334 if (nlabels
> (size_t)1 && (size_t)i
< nlabels
&& labels
[i
] != NULL
)
335 asprintf (&outbuff
, "%s%s%s %s%s%s", outbuff
,
336 (i
== 0) ? " " : output_delim
,
337 labels
[i
], mark (iresult
), show
, mark (iresult
));
339 asprintf (&outbuff
, "%s%s%s%s%s", outbuff
, (i
== 0) ? " " : output_delim
,
340 mark (iresult
), show
, mark (iresult
));
342 /* Append a unit string for this OID if there is one */
343 if (nunits
> (size_t)0 && (size_t)i
< nunits
&& unitv
[i
] != NULL
)
344 asprintf (&outbuff
, "%s %s", outbuff
, unitv
[i
]);
348 asprintf(str
, "=%s%s;;;; ", show
, type
? type
: "");
349 strcat(perfstr
, *str
);
351 } /* end while (ptr) */
355 _("%s problem - No data received from host\nCMD: %s\n"),
359 /* WARNING if output found on stderr */
360 if (fgets (input_buffer
, MAX_INPUT_BUFFER
- 1, child_stderr
))
361 result
= max_state (result
, STATE_WARNING
);
364 (void) fclose (child_stderr
);
367 if (spclose (child_process
))
368 result
= max_state (result
, STATE_WARNING
);
370 /* if (nunits == 1 || i == 1) */
371 /* printf ("%s %s -%s %s\n", label, state_text (result), outbuff, units); */
373 printf ("%s %s -%s %s \n", label
, state_text (result
), outbuff
, perfstr
);
380 /* process command-line arguments */
382 process_arguments (int argc
, char **argv
)
386 int j
= 0, jj
= 0, ii
= 0;
389 static struct option longopts
[] = {
391 {"community", required_argument
, 0, 'C'},
392 {"oid", required_argument
, 0, 'o'},
393 {"object", required_argument
, 0, 'o'},
394 {"delimiter", required_argument
, 0, 'd'},
395 {"output-delimiter", required_argument
, 0, 'D'},
396 {"string", required_argument
, 0, 's'},
397 {"timeout", required_argument
, 0, 't'},
398 {"regex", required_argument
, 0, 'r'},
399 {"ereg", required_argument
, 0, 'r'},
400 {"eregi", required_argument
, 0, 'R'},
401 {"label", required_argument
, 0, 'l'},
402 {"units", required_argument
, 0, 'u'},
403 {"port", required_argument
, 0, 'p'},
404 {"retries", required_argument
, 0, 'e'},
405 {"miblist", required_argument
, 0, 'm'},
406 {"protocol", required_argument
, 0, 'P'},
407 {"seclevel", required_argument
, 0, 'L'},
408 {"secname", required_argument
, 0, 'U'},
409 {"authproto", required_argument
, 0, 'a'},
410 {"authpasswd", required_argument
, 0, 'A'},
411 {"privpasswd", required_argument
, 0, 'X'},
412 {"next", no_argument
, 0, 'n'},
419 /* reverse compatibility for very old non-POSIX usage forms */
420 for (c
= 1; c
< argc
; c
++) {
421 if (strcmp ("-to", argv
[c
]) == 0)
422 strcpy (argv
[c
], "-t");
423 if (strcmp ("-wv", argv
[c
]) == 0)
424 strcpy (argv
[c
], "-w");
425 if (strcmp ("-cv", argv
[c
]) == 0)
426 strcpy (argv
[c
], "-c");
430 c
= getopt_long (argc
, argv
, "nhvVt:c:w:H:C:o:e:E:d:D:s:t:R:r:l:u:p:m:P:L:U:a:A:X:",
433 if (c
== -1 || c
== EOF
)
437 case '?': /* usage */
438 usage2 (_("Unknown argument"), optarg
);
442 case 'V': /* version */
443 print_revision (progname
, revision
);
445 case 'v': /* verbose */
449 /* Connection info */
450 case 'C': /* group or community */
453 case 'H': /* Host or server */
454 server_address
= optarg
;
456 case 'p': /* TCP port number */
459 case 'm': /* List of MIBS */
462 case 'n': /* usesnmpgetnext */
463 usesnmpgetnext
= TRUE
;
465 case 'P': /* SNMP protocol version */
468 case 'L': /* security level */
471 case 'U': /* security username */
474 case 'a': /* auth protocol */
477 case 'A': /* auth passwd */
480 case 'X': /* priv passwd */
483 case 't': /* timeout period */
484 if (!is_integer (optarg
))
485 usage2 (_("Timeout interval must be a positive integer"), optarg
);
487 timeout_interval
= atoi (optarg
);
490 /* Test parameters */
491 case 'c': /* critical time threshold */
492 if (strspn (optarg
, "0123456789:,") < strlen (optarg
))
493 usage2 (_("Invalid critical threshold: %s\n"), optarg
);
494 for (ptr
= optarg
; ptr
&& jj
< MAX_OIDS
; jj
++) {
495 if (lu_getll (&lower_crit_lim
[jj
], ptr
) == 1)
496 eval_method
[jj
] |= CRIT_LT
;
497 if (lu_getul (&upper_crit_lim
[jj
], ptr
) == 1)
498 eval_method
[jj
] |= CRIT_GT
;
499 (ptr
= index (ptr
, ',')) ? ptr
++ : ptr
;
502 case 'w': /* warning time threshold */
503 if (strspn (optarg
, "0123456789:,") < strlen (optarg
))
504 usage2 (_("Invalid warning threshold: %s\n"), optarg
);
505 for (ptr
= optarg
; ptr
&& ii
< MAX_OIDS
; ii
++) {
506 if (lu_getll (&lower_warn_lim
[ii
], ptr
) == 1)
507 eval_method
[ii
] |= WARN_LT
;
508 if (lu_getul (&upper_warn_lim
[ii
], ptr
) == 1)
509 eval_method
[ii
] |= WARN_GT
;
510 (ptr
= index (ptr
, ',')) ? ptr
++ : ptr
;
513 case 'e': /* PRELIMINARY - may change */
514 case 'E': /* PRELIMINARY - may change */
515 if (!is_integer (optarg
))
516 usage2 (_("Retries interval must be a positive integer"), optarg
);
518 retries
= atoi(optarg
);
520 case 'o': /* object identifier */
521 if ( strspn( optarg
, "0123456789." ) != strlen( optarg
) ) {
523 * we have something other than digits and periods, so we
524 * have a mib variable, rather than just an SNMP OID, so
525 * we have to actually read the mib files
530 for (ptr
= optarg
; (ptr
= index (ptr
, ',')); ptr
++)
531 ptr
[0] = ' '; /* relpace comma with space */
532 for (ptr
= optarg
; (ptr
= index (ptr
, ' ')); ptr
++)
533 j
++; /* count OIDs */
534 asprintf (&oid
, "%s %s", (oid
?oid
:""), optarg
);
535 if (c
== 'E' || c
== 'e') {
540 eval_method
[j
+1] |= WARN_PRESENT
;
542 eval_method
[j
+1] |= CRIT_PRESENT
;
544 case 's': /* string or substring */
545 strncpy (string_value
, optarg
, sizeof (string_value
) - 1);
546 string_value
[sizeof (string_value
) - 1] = 0;
547 eval_method
[jj
++] = CRIT_STRING
;
550 case 'R': /* regex */
552 case 'r': /* regex */
553 cflags
|= REG_EXTENDED
| REG_NOSUB
| REG_NEWLINE
;
554 strncpy (regex_expect
, optarg
, sizeof (regex_expect
) - 1);
555 regex_expect
[sizeof (regex_expect
) - 1] = 0;
556 errcode
= regcomp (&preg
, regex_expect
, cflags
);
558 regerror (errcode
, &preg
, errbuf
, MAX_INPUT_BUFFER
);
559 printf (_("Could Not Compile Regular Expression"));
562 eval_method
[jj
++] = CRIT_REGEX
;
567 case 'd': /* delimiter */
568 delimiter
= strscpy (delimiter
, optarg
);
570 case 'D': /* output-delimiter */
571 output_delim
= strscpy (output_delim
, optarg
);
573 case 'l': /* label */
576 if (nlabels
>= labels_size
) {
578 labels
= realloc (labels
, labels_size
);
580 die (STATE_UNKNOWN
, _("Could not reallocate labels[%d]"), (int)nlabels
);
582 labels
[nlabels
- 1] = optarg
;
583 ptr
= thisarg (optarg
);
584 labels
[nlabels
- 1] = ptr
;
585 if (strstr (ptr
, "'") == ptr
)
586 labels
[nlabels
- 1] = ptr
+ 1;
587 while (ptr
&& (ptr
= nextarg (ptr
))) {
588 if (nlabels
>= labels_size
) {
590 labels
= realloc (labels
, labels_size
);
592 die (STATE_UNKNOWN
, _("Could not reallocate labels\n"));
596 if (strstr (ptr
, "'") == ptr
)
597 labels
[nlabels
- 1] = ptr
+ 1;
599 labels
[nlabels
- 1] = ptr
;
602 case 'u': /* units */
605 if (nunits
>= unitv_size
) {
607 unitv
= realloc (unitv
, unitv_size
);
609 die (STATE_UNKNOWN
, _("Could not reallocate units [%d]\n"), (int)nunits
);
611 unitv
[nunits
- 1] = optarg
;
612 ptr
= thisarg (optarg
);
613 unitv
[nunits
- 1] = ptr
;
614 if (strstr (ptr
, "'") == ptr
)
615 unitv
[nunits
- 1] = ptr
+ 1;
616 while (ptr
&& (ptr
= nextarg (ptr
))) {
617 if (nunits
>= unitv_size
) {
619 unitv
= realloc (unitv
, unitv_size
);
621 die (STATE_UNKNOWN
, _("Could not realloc() units\n"));
625 if (strstr (ptr
, "'") == ptr
)
626 unitv
[nunits
- 1] = ptr
+ 1;
628 unitv
[nunits
- 1] = ptr
;
635 if (server_address
== NULL
)
636 server_address
= argv
[optind
];
638 if (community
== NULL
)
639 community
= strdup (DEFAULT_COMMUNITY
);
643 return validate_arguments ();
647 /******************************************************************************
651 <title>validate_arguments</title>
653 <para>&PROTO_validate_arguments;</para>
655 <para>Checks to see if the default miblist needs to be loaded. Also verifies
656 the authentication and authorization combinations based on protocol version
663 ******************************************************************************/
668 validate_arguments ()
670 /* check whether to load locally installed MIBS (CPU/disk intensive) */
671 if (miblist
== NULL
) {
672 if ( needmibs
== TRUE
) {
673 miblist
= strdup (DEFAULT_MIBLIST
);
675 miblist
= "''"; /* don't read any mib files for numeric oids */
680 /* Need better checks to verify seclevel and authproto choices */
682 if (seclevel
== NULL
)
683 asprintf (&seclevel
, "noAuthNoPriv");
686 if (authproto
== NULL
)
687 asprintf(&authproto
, DEFAULT_AUTH_PROTOCOL
);
691 if (proto
== NULL
|| (strcmp(proto
,DEFAULT_PROTOCOL
) == 0) ) { /* default protocol version */
692 asprintf(&proto
, DEFAULT_PROTOCOL
);
693 asprintf(&authpriv
, "%s%s", "-c ", community
);
695 else if ( strcmp (proto
, "2c") == 0 ) { /* snmpv2c args */
696 asprintf(&authpriv
, "%s%s", "-c ", community
);
698 else if ( strcmp (proto
, "3") == 0 ) { /* snmpv3 args */
699 asprintf(&proto
, "%s", "3");
701 if ( (strcmp(seclevel
, "noAuthNoPriv") == 0) || seclevel
== NULL
) {
702 asprintf(&authpriv
, "%s", "-l noAuthNoPriv" );
704 else if ( strcmp(seclevel
, "authNoPriv") == 0 ) {
705 if ( secname
== NULL
|| authpasswd
== NULL
) {
706 printf (_("Missing secname (%s) or authpassword (%s) ! \n"),secname
, authpasswd
);
708 exit (STATE_UNKNOWN
);
710 asprintf(&authpriv
, "-l authNoPriv -a %s -u %s -A %s ", authproto
, secname
, authpasswd
);
712 else if ( strcmp(seclevel
, "authPriv") == 0 ) {
713 if ( secname
== NULL
|| authpasswd
== NULL
|| privpasswd
== NULL
) {
714 printf (_("Missing secname (%s), authpassword (%s), or privpasswd (%s)! \n"),secname
, authpasswd
,privpasswd
);
716 exit (STATE_UNKNOWN
);
718 asprintf(&authpriv
, "-l authPriv -a %s -u %s -A %s -x DES -X %s ", authproto
, secname
, authpasswd
, privpasswd
);
723 usage2 (_("Invalid SNMP version"), proto
);
732 clarify_message (char *msg
)
736 char tmpmsg_c
[MAX_INPUT_BUFFER
];
737 char *tmpmsg
= (char *) &tmpmsg_c
;
738 tmpmsg
= strcpy (tmpmsg
, msg
);
739 if (!strncmp (tmpmsg
, " Hex:", 5)) {
740 tmpmsg
= strtok (tmpmsg
, ":");
741 while ((tmpmsg
= strtok (NULL
, " "))) {
742 foo
= strtol (tmpmsg
, NULL
, 16);
743 /* Translate chars that are not the same value in the printers
773 if (eval_method
[i
] & WARN_GT
&& eval_method
[i
] & WARN_LT
&&
774 lower_warn_lim
[i
] > upper_warn_lim
[i
]) {
775 if (response_value
[i
] <= lower_warn_lim
[i
] &&
776 response_value
[i
] >= upper_warn_lim
[i
]) {
777 result
= STATE_WARNING
;
781 ((eval_method
[i
] & WARN_GT
&& response_value
[i
] > upper_warn_lim
[i
]) ||
782 (eval_method
[i
] & WARN_GE
&& response_value
[i
] >= upper_warn_lim
[i
]) ||
783 (eval_method
[i
] & WARN_LT
&& response_value
[i
] < lower_warn_lim
[i
]) ||
784 (eval_method
[i
] & WARN_LE
&& response_value
[i
] <= lower_warn_lim
[i
]) ||
785 (eval_method
[i
] & WARN_EQ
&& response_value
[i
] == upper_warn_lim
[i
]) ||
786 (eval_method
[i
] & WARN_NE
&& response_value
[i
] != upper_warn_lim
[i
])) {
787 result
= STATE_WARNING
;
790 if (eval_method
[i
] & CRIT_GT
&& eval_method
[i
] & CRIT_LT
&&
791 lower_crit_lim
[i
] > upper_crit_lim
[i
]) {
792 if (response_value
[i
] <= lower_crit_lim
[i
] &&
793 response_value
[i
] >= upper_crit_lim
[i
]) {
794 result
= STATE_CRITICAL
;
798 ((eval_method
[i
] & CRIT_GT
&& response_value
[i
] > upper_crit_lim
[i
]) ||
799 (eval_method
[i
] & CRIT_GE
&& response_value
[i
] >= upper_crit_lim
[i
]) ||
800 (eval_method
[i
] & CRIT_LT
&& response_value
[i
] < lower_crit_lim
[i
]) ||
801 (eval_method
[i
] & CRIT_LE
&& response_value
[i
] <= lower_crit_lim
[i
]) ||
802 (eval_method
[i
] & CRIT_EQ
&& response_value
[i
] == upper_crit_lim
[i
]) ||
803 (eval_method
[i
] & CRIT_NE
&& response_value
[i
] != upper_crit_lim
[i
])) {
804 result
= STATE_CRITICAL
;
813 lu_getll (unsigned long *ll
, char *str
)
816 if (strchr (str
, ':') == NULL
)
818 if (strchr (str
, ',') != NULL
&& (strchr (str
, ',') < strchr (str
, ':')))
820 if (sscanf (str
, "%lu%[:]", ll
, tmp
) == 2)
828 lu_getul (unsigned long *ul
, char *str
)
831 if (sscanf (str
, "%lu%[^,]", ul
, tmp
) == 1)
833 if (sscanf (str
, ":%lu%[^,]", ul
, tmp
) == 1)
835 if (sscanf (str
, "%*u:%lu%[^,]", ul
, tmp
) == 1)
842 /* trim leading whitespace
843 if there is a leading quote, make sure it balances */
848 str
+= strspn (str
, " \t\r\n"); /* trim any leading whitespace */
849 if (strstr (str
, "'") == str
) { /* handle SIMPLE quoted strings */
850 if (strlen (str
) == 1 || !strstr (str
+ 1, "'"))
851 die (STATE_UNKNOWN
, _("Unbalanced quotes\n"));
858 /* if there's a leading quote, advance to the trailing quote
859 set the trailing quote to '\x0'
860 if the string continues, advance beyond the comma */
865 if (strstr (str
, "'") == str
) {
867 if (strlen (str
) > 1) {
868 str
= strstr (str
+ 1, "'");
875 if (strstr (str
, ",") == str
) {
877 if (strlen (str
) > 1) {
884 if ((str
= strstr (str
, ",")) && strlen (str
) > 1) {
896 print_revision (progname
, revision
);
898 printf (COPYRIGHT
, copyright
, email
);
900 printf ("%s\n", _("Check status of remote machines and obtain sustem information via SNMP"));
906 printf (_(UT_HELP_VRSN
));
908 printf (_(UT_HOST_PORT
), 'p', DEFAULT_PORT
);
910 /* SNMP and Authentication Protocol */
911 printf (" %s\n", "-n, --next");
912 printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET"));
913 printf (" %s\n", "-P, --protocol=[1|2c|3]");
914 printf (" %s\n", _("SNMP protocol version"));
915 printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]");
916 printf (" %s\n", _("SNMPv3 securityLevel"));
917 printf (" %s\n", "-a, --authproto=[MD5|SHA]");
918 printf (" %s\n", _("SNMPv3 auth proto"));
920 /* Authentication Tokens*/
921 printf (" %s\n", "-C, --community=STRING");
922 printf (" %s\n", _("Optional community string for SNMP communication"));
923 printf (_("(default is \"%s\")"),DEFAULT_COMMUNITY
);
924 printf (" %s\n", "-U, --secname=USERNAME");
925 printf (" %s\n", _("SNMPv3 username"));
926 printf (" %s\n", "-A, --authpassword=PASSWORD");
927 printf (" %s\n", _("SNMPv3 authentication password"));
928 printf (" %s\n", "-X, --privpasswd=PASSWORD");
929 printf (" %s\n", _("SNMPv3 crypt passwd (DES)"));
932 printf (" %s\n", "-o, --oid=OID(s)");
933 printf (" %s\n", _("Object identifier(s) or SNMP variables whose value you wish to query"));
934 printf (" %s\n", "-m, --miblist=STRING");
935 printf (" %s\n", _("List of MIBS to be loaded (default = none if using numeric oids or 'ALL'"));
936 printf (" %s\n", _("for symbolic oids.)"));
937 printf (" %s\n", "-d, --delimiter=STRING");
938 printf (_(" Delimiter to use when parsing returned data. Default is \"%s\""), DEFAULT_DELIMITER
);
939 printf (" %s\n", _("Any data on the right hand side of the delimiter is considered"));
940 printf (" %s\n", _("to be the data that should be used in the evaluation."));
942 /* Tests Against Integers */
943 printf (" %s\n", "-w, --warning=INTEGER_RANGE(s)");
944 printf (" %s\n", _("Range(s) which will not result in a WARNING status"));
945 printf (" %s\n", "-c, --critical=INTEGER_RANGE(s)");
946 printf (" %s\n", _("Range(s) which will not result in a CRITICAL status"));
948 /* Tests Against Strings */
949 printf (" %s\n", "-s, --string=STRING");
950 printf (" %s\n", _("Return OK state (for that OID) if STRING is an exact match"));
951 printf (" %s\n", "-r, --ereg=REGEX");
952 printf (" %s\n", _("Return OK state (for that OID) if extended regular expression REGEX matches"));
953 printf (" %s\n", "-R, --eregi=REGEX");
954 printf (" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches"));
955 printf (" %s\n", "-l, --label=STRING");
956 printf (" %s\n", _("Prefix label for output from plugin (default -s 'SNMP')"));
958 /* Output Formatting */
959 printf (" %s\n", "-u, --units=STRING");
960 printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.')."));
961 printf (" %s\n", "-D, --output-delimiter=STRING");
962 printf (" %s\n", _("Separates output on multiple OID requests"));
964 printf (_(UT_TIMEOUT
), DEFAULT_SOCKET_TIMEOUT
);
966 printf (_(UT_VERBOSE
));
968 printf ("%s\n", _("This plugin uses the 'snmpget' command included with the NET-SNMP package."));
969 printf ("%s\n", _("if you don't have the package installed, you will need to download it from"));
970 printf ("%s\n", _("http://net-snmp.sourceforge.net before you can use this plugin."));
972 printf ("%s\n", _("- Multiple OIDs may be indicated by a comma- or space-delimited list (lists with"));
973 printf ("%s\n", _(" internal spaces must be quoted) [max 8 OIDs]"));
975 printf ("%s\n", _("- Ranges are inclusive and are indicated with colons. When specified as"));
976 printf ("%s\n", _(" 'min:max' a STATE_OK will be returned if the result is within the indicated"));
977 printf ("%s\n", _(" range or is equal to the upper or lower bound. A non-OK state will be"));
978 printf ("%s\n", _(" returned if the result is outside the specified range."));
980 printf ("%s\n", _("- If specified in the order 'max:min' a non-OK state will be returned if the"));
981 printf ("%s\n", _(" result is within the (inclusive) range."));
983 printf ("%s\n", _("- Upper or lower bounds may be omitted to skip checking the respective limit."));
984 printf ("%s\n", _("- Bare integers are interpreted as upper limits."));
985 printf ("%s\n", _("- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'"));
986 printf ("%s\n", _("- Note that only one string and one regex may be checked at present"));
987 printf ("%s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value"));
988 printf ("%s\n", _(" returned from the SNMP query is an unsigned integer."));
990 printf (_(UT_SUPPORT
));
998 printf (_("Usage:"));
999 printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\
1000 [-C community] [-s string] [-r regex] [-R regexi]\n\
1001 [-t timeout] [-e retries]\n\
1002 [-l label] [-u units] [-p port-number] [-d delimiter]\n\
1003 [-D output-delimiter] [-m miblist] [-P snmp version]\n\
1004 [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\
1005 [-X privpasswd]\n", progname
);