1 /*****************************************************************************
3 * Nagios check_snmp plugin
6 * Copyright (c) 1999-2007 Nagios Plugins Development Team
8 * Last Modified: $Date$
12 * This file contains the check_snmp plugin
14 * Check status of remote machines and obtain system information via SNMP
17 * This program is free software: you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation, either version 3 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <http://www.gnu.org/licenses/>.
32 *****************************************************************************/
34 const char *progname
= "check_snmp";
35 const char *revision
= "$Revision$";
36 const char *copyright
= "1999-2007";
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 llu_getll (unsigned long long *, char *);
85 int llu_getul (unsigned long 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 long lower_warn_lim
[MAX_OIDS
];
125 unsigned long long upper_warn_lim
[MAX_OIDS
];
126 unsigned long long lower_crit_lim
[MAX_OIDS
];
127 unsigned long long upper_crit_lim
[MAX_OIDS
];
128 unsigned long long response_value
[MAX_OIDS
];
129 int check_warning_value
= FALSE
;
130 int check_critical_value
= FALSE
;
132 unsigned long 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 *cl_hidden_auth
= NULL
;
149 char *response
= NULL
;
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
);
187 asprintf(&cl_hidden_auth
, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
188 PATH_TO_SNMPGETNEXT
, timeout_interval
, retries
, miblist
, proto
,
189 "[authpriv]", server_address
, port
, oid
);
192 asprintf (&command_line
, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
193 PATH_TO_SNMPGET
, timeout_interval
, retries
, miblist
, proto
,
194 authpriv
, server_address
, port
, oid
);
195 asprintf(&cl_hidden_auth
, "%s -t %d -r %d -m %s -v %s %s %s:%s %s",
196 PATH_TO_SNMPGET
, timeout_interval
, retries
, miblist
, proto
,
197 "[authpriv]", server_address
, port
, oid
);
201 printf ("%s\n", command_line
);
204 /* run the command */
205 child_process
= spopen (command_line
);
206 if (child_process
== NULL
) {
207 printf (_("Could not open pipe: %s\n"), cl_hidden_auth
);
208 exit (STATE_UNKNOWN
);
211 #if 0 /* Removed May 29, 2007 */
212 child_stderr
= fdopen (child_stderr_array
[fileno (child_process
)], "r");
213 if (child_stderr
== NULL
) {
214 printf (_("Could not open stderr for %s\n"), cl_hidden_auth
);
218 while (fgets (input_buffer
, MAX_INPUT_BUFFER
- 1, child_process
))
219 asprintf (&output
, "%s%s", output
, input_buffer
);
222 printf ("%s\n", output
);
226 strncat(perfstr
, "| ", sizeof(perfstr
)-strlen(perfstr
)-1);
229 unsigned int copylen
;
231 foo
= strstr (ptr
, delimiter
);
233 if (copylen
> sizeof(perfstr
)-strlen(perfstr
)-1)
234 copylen
= sizeof(perfstr
)-strlen(perfstr
)-1;
235 strncat(perfstr
, ptr
, copylen
);
241 ptr
+= strlen (delimiter
);
242 ptr
+= strspn (ptr
, " ");
248 response
= strpcpy (response
, ptr
, "\"");
249 ptr
= strpbrk (ptr
, "\"");
250 ptr
+= strspn (ptr
, "\"\n");
253 response
= strpcpy (response
, ptr
, "\n");
254 ptr
= strpbrk (ptr
, "\n");
255 ptr
+= strspn (ptr
, "\n");
257 (strstr (ptr
, delimiter
) &&
258 strstr (ptr
, "\n") && strstr (ptr
, "\n") < strstr (ptr
, delimiter
)) {
259 response
= strpcat (response
, ptr
, "\n");
260 ptr
= strpbrk (ptr
, "\n");
262 if (ptr
&& strstr (ptr
, delimiter
) == NULL
) {
263 asprintf (&response
, "%s%s", response
, ptr
);
268 /* We strip out the datatype indicator for PHBs */
270 /* Clean up type array - Sol10 does not necessarily zero it out */
271 bzero(type
, sizeof(type
));
273 if (strstr (response
, "Gauge: "))
274 show
= strstr (response
, "Gauge: ") + 7;
275 else if (strstr (response
, "Gauge32: "))
276 show
= strstr (response
, "Gauge32: ") + 9;
277 else if (strstr (response
, "Counter32: ")) {
278 show
= strstr (response
, "Counter32: ") + 11;
281 else if (strstr (response
, "Counter64: ")) {
282 show
= strstr (response
, "Counter64: ") + 11;
285 else if (strstr (response
, "INTEGER: "))
286 show
= strstr (response
, "INTEGER: ") + 9;
287 else if (strstr (response
, "STRING: "))
288 show
= strstr (response
, "STRING: ") + 8;
293 iresult
= STATE_DEPENDENT
;
295 /* Process this block for integer comparisons */
296 if (eval_method
[i
] & CRIT_GT
||
297 eval_method
[i
] & CRIT_LT
||
298 eval_method
[i
] & CRIT_GE
||
299 eval_method
[i
] & CRIT_LE
||
300 eval_method
[i
] & CRIT_EQ
||
301 eval_method
[i
] & CRIT_NE
||
302 eval_method
[i
] & WARN_GT
||
303 eval_method
[i
] & WARN_LT
||
304 eval_method
[i
] & WARN_GE
||
305 eval_method
[i
] & WARN_LE
||
306 eval_method
[i
] & WARN_EQ
||
307 eval_method
[i
] & WARN_NE
) {
308 p2
= strpbrk (p2
, "0123456789");
310 die (STATE_UNKNOWN
,_("No valid data returned"));
311 response_value
[i
] = strtoul (p2
, NULL
, 10);
312 iresult
= check_num (i
);
313 asprintf (&show
, "%llu", response_value
[i
]);
316 /* Process this block for string matching */
317 else if (eval_method
[i
] & CRIT_STRING
) {
318 if (strcmp (show
, string_value
))
319 iresult
= STATE_CRITICAL
;
324 /* Process this block for regex matching */
325 else if (eval_method
[i
] & CRIT_REGEX
) {
326 excode
= regexec (&preg
, response
, 10, pmatch
, eflags
);
330 else if (excode
!= REG_NOMATCH
) {
331 regerror (excode
, &preg
, errbuf
, MAX_INPUT_BUFFER
);
332 printf (_("Execute Error: %s\n"), errbuf
);
333 exit (STATE_CRITICAL
);
336 iresult
= STATE_CRITICAL
;
340 /* Process this block for existence-nonexistence checks */
342 if (eval_method
[i
] & CRIT_PRESENT
)
343 iresult
= STATE_CRITICAL
;
344 else if (eval_method
[i
] & WARN_PRESENT
)
345 iresult
= STATE_WARNING
;
346 else if (response
&& iresult
== STATE_DEPENDENT
)
350 /* Result is the worst outcome of all the OIDs tested */
351 result
= max_state (result
, iresult
);
353 /* Prepend a label for this OID if there is one */
354 if (nlabels
> (size_t)1 && (size_t)i
< nlabels
&& labels
[i
] != NULL
)
355 asprintf (&outbuff
, "%s%s%s %s%s%s", outbuff
,
356 (i
== 0) ? " " : output_delim
,
357 labels
[i
], mark (iresult
), show
, mark (iresult
));
359 asprintf (&outbuff
, "%s%s%s%s%s", outbuff
, (i
== 0) ? " " : output_delim
,
360 mark (iresult
), show
, mark (iresult
));
362 /* Append a unit string for this OID if there is one */
363 if (nunits
> (size_t)0 && (size_t)i
< nunits
&& unitv
[i
] != NULL
)
364 asprintf (&outbuff
, "%s %s", outbuff
, unitv
[i
]);
368 strncat(perfstr
, "=", sizeof(perfstr
)-strlen(perfstr
)-1);
369 strncat(perfstr
, show
, sizeof(perfstr
)-strlen(perfstr
)-1);
371 strncat(perfstr
, type
, sizeof(perfstr
)-strlen(perfstr
)-1);
372 strncat(perfstr
, " ", sizeof(perfstr
)-strlen(perfstr
)-1);
374 } /* end while (ptr) */
378 _("%s problem - No data received from host\nCMD: %s\n"),
382 #if 0 /* Removed May 29, 2007 */
383 /* WARNING if output found on stderr */
384 if (fgets (input_buffer
, MAX_INPUT_BUFFER
- 1, child_stderr
))
385 result
= max_state (result
, STATE_WARNING
);
388 (void) fclose (child_stderr
);
392 if (spclose (child_process
)) {
393 if (result
== STATE_OK
)
394 result
= STATE_UNKNOWN
;
395 asprintf (&outbuff
, "%s (%s)", outbuff
, _("snmpget returned an error status"));
398 /* if (nunits == 1 || i == 1) */
399 /* printf ("%s %s -%s %s\n", label, state_text (result), outbuff, units); */
401 printf ("%s %s -%s %s \n", label
, state_text (result
), outbuff
, perfstr
);
408 /* process command-line arguments */
410 process_arguments (int argc
, char **argv
)
414 int j
= 0, jj
= 0, ii
= 0;
417 static struct option longopts
[] = {
419 {"community", required_argument
, 0, 'C'},
420 {"oid", required_argument
, 0, 'o'},
421 {"object", required_argument
, 0, 'o'},
422 {"delimiter", required_argument
, 0, 'd'},
423 {"output-delimiter", required_argument
, 0, 'D'},
424 {"string", required_argument
, 0, 's'},
425 {"timeout", required_argument
, 0, 't'},
426 {"regex", required_argument
, 0, 'r'},
427 {"ereg", required_argument
, 0, 'r'},
428 {"eregi", required_argument
, 0, 'R'},
429 {"label", required_argument
, 0, 'l'},
430 {"units", required_argument
, 0, 'u'},
431 {"port", required_argument
, 0, 'p'},
432 {"retries", required_argument
, 0, 'e'},
433 {"miblist", required_argument
, 0, 'm'},
434 {"protocol", required_argument
, 0, 'P'},
435 {"seclevel", required_argument
, 0, 'L'},
436 {"secname", required_argument
, 0, 'U'},
437 {"authproto", required_argument
, 0, 'a'},
438 {"authpasswd", required_argument
, 0, 'A'},
439 {"privpasswd", required_argument
, 0, 'X'},
440 {"next", no_argument
, 0, 'n'},
447 /* reverse compatibility for very old non-POSIX usage forms */
448 for (c
= 1; c
< argc
; c
++) {
449 if (strcmp ("-to", argv
[c
]) == 0)
450 strcpy (argv
[c
], "-t");
451 if (strcmp ("-wv", argv
[c
]) == 0)
452 strcpy (argv
[c
], "-w");
453 if (strcmp ("-cv", argv
[c
]) == 0)
454 strcpy (argv
[c
], "-c");
458 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:",
461 if (c
== -1 || c
== EOF
)
465 case '?': /* usage */
470 case 'V': /* version */
471 print_revision (progname
, revision
);
473 case 'v': /* verbose */
477 /* Connection info */
478 case 'C': /* group or community */
481 case 'H': /* Host or server */
482 server_address
= optarg
;
484 case 'p': /* TCP port number */
487 case 'm': /* List of MIBS */
490 case 'n': /* usesnmpgetnext */
491 usesnmpgetnext
= TRUE
;
493 case 'P': /* SNMP protocol version */
496 case 'L': /* security level */
499 case 'U': /* security username */
502 case 'a': /* auth protocol */
505 case 'A': /* auth passwd */
508 case 'X': /* priv passwd */
511 case 't': /* timeout period */
512 if (!is_integer (optarg
))
513 usage2 (_("Timeout interval must be a positive integer"), optarg
);
515 timeout_interval
= atoi (optarg
);
518 /* Test parameters */
519 case 'c': /* critical time threshold */
520 if (strspn (optarg
, "0123456789:,") < strlen (optarg
))
521 usage2 (_("Invalid critical threshold"), optarg
);
522 for (ptr
= optarg
; ptr
&& jj
< MAX_OIDS
; jj
++) {
523 if (llu_getll (&lower_crit_lim
[jj
], ptr
) == 1)
524 eval_method
[jj
] |= CRIT_LT
;
525 if (llu_getul (&upper_crit_lim
[jj
], ptr
) == 1)
526 eval_method
[jj
] |= CRIT_GT
;
527 (ptr
= index (ptr
, ',')) ? ptr
++ : ptr
;
530 case 'w': /* warning time threshold */
531 if (strspn (optarg
, "0123456789:,") < strlen (optarg
))
532 usage2 (_("Invalid warning threshold"), optarg
);
533 for (ptr
= optarg
; ptr
&& ii
< MAX_OIDS
; ii
++) {
534 if (llu_getll (&lower_warn_lim
[ii
], ptr
) == 1)
535 eval_method
[ii
] |= WARN_LT
;
536 if (llu_getul (&upper_warn_lim
[ii
], ptr
) == 1)
537 eval_method
[ii
] |= WARN_GT
;
538 (ptr
= index (ptr
, ',')) ? ptr
++ : ptr
;
541 case 'e': /* PRELIMINARY - may change */
542 case 'E': /* PRELIMINARY - may change */
543 if (!is_integer (optarg
))
544 usage2 (_("Retries interval must be a positive integer"), optarg
);
546 retries
= atoi(optarg
);
548 case 'o': /* object identifier */
549 if ( strspn( optarg
, "0123456789.," ) != strlen( optarg
) ) {
551 * we have something other than digits, periods and comas,
552 * so we have a mib variable, rather than just an SNMP OID,
553 * so we have to actually read the mib files
558 for (ptr
= optarg
; (ptr
= index (ptr
, ',')); ptr
++)
559 ptr
[0] = ' '; /* relpace comma with space */
560 for (ptr
= optarg
; (ptr
= index (ptr
, ' ')); ptr
++)
561 j
++; /* count OIDs */
562 asprintf (&oid
, "%s %s", (oid
?oid
:""), optarg
);
563 if (c
== 'E' || c
== 'e') {
568 eval_method
[j
+1] |= WARN_PRESENT
;
570 eval_method
[j
+1] |= CRIT_PRESENT
;
572 case 's': /* string or substring */
573 strncpy (string_value
, optarg
, sizeof (string_value
) - 1);
574 string_value
[sizeof (string_value
) - 1] = 0;
575 eval_method
[jj
++] = CRIT_STRING
;
578 case 'R': /* regex */
580 case 'r': /* regex */
581 cflags
|= REG_EXTENDED
| REG_NOSUB
| REG_NEWLINE
;
582 strncpy (regex_expect
, optarg
, sizeof (regex_expect
) - 1);
583 regex_expect
[sizeof (regex_expect
) - 1] = 0;
584 errcode
= regcomp (&preg
, regex_expect
, cflags
);
586 regerror (errcode
, &preg
, errbuf
, MAX_INPUT_BUFFER
);
587 printf (_("Could Not Compile Regular Expression"));
590 eval_method
[jj
++] = CRIT_REGEX
;
595 case 'd': /* delimiter */
596 delimiter
= strscpy (delimiter
, optarg
);
598 case 'D': /* output-delimiter */
599 output_delim
= strscpy (output_delim
, optarg
);
601 case 'l': /* label */
604 if (nlabels
>= labels_size
) {
606 labels
= realloc (labels
, labels_size
);
608 die (STATE_UNKNOWN
, _("Could not reallocate labels[%d]"), (int)nlabels
);
610 labels
[nlabels
- 1] = optarg
;
611 ptr
= thisarg (optarg
);
612 labels
[nlabels
- 1] = ptr
;
613 if (strstr (ptr
, "'") == ptr
)
614 labels
[nlabels
- 1] = ptr
+ 1;
615 while (ptr
&& (ptr
= nextarg (ptr
))) {
616 if (nlabels
>= labels_size
) {
618 labels
= realloc (labels
, labels_size
);
620 die (STATE_UNKNOWN
, _("Could not reallocate labels\n"));
624 if (strstr (ptr
, "'") == ptr
)
625 labels
[nlabels
- 1] = ptr
+ 1;
627 labels
[nlabels
- 1] = ptr
;
630 case 'u': /* units */
633 if (nunits
>= unitv_size
) {
635 unitv
= realloc (unitv
, unitv_size
);
637 die (STATE_UNKNOWN
, _("Could not reallocate units [%d]\n"), (int)nunits
);
639 unitv
[nunits
- 1] = optarg
;
640 ptr
= thisarg (optarg
);
641 unitv
[nunits
- 1] = ptr
;
642 if (strstr (ptr
, "'") == ptr
)
643 unitv
[nunits
- 1] = ptr
+ 1;
644 while (ptr
&& (ptr
= nextarg (ptr
))) {
645 if (nunits
>= unitv_size
) {
647 unitv
= realloc (unitv
, unitv_size
);
649 die (STATE_UNKNOWN
, _("Could not realloc() units\n"));
653 if (strstr (ptr
, "'") == ptr
)
654 unitv
[nunits
- 1] = ptr
+ 1;
656 unitv
[nunits
- 1] = ptr
;
663 if (server_address
== NULL
)
664 server_address
= argv
[optind
];
666 if (community
== NULL
)
667 community
= strdup (DEFAULT_COMMUNITY
);
671 return validate_arguments ();
675 /******************************************************************************
679 <title>validate_arguments</title>
681 <para>&PROTO_validate_arguments;</para>
683 <para>Checks to see if the default miblist needs to be loaded. Also verifies
684 the authentication and authorization combinations based on protocol version
691 ******************************************************************************/
696 validate_arguments ()
698 /* check whether to load locally installed MIBS (CPU/disk intensive) */
699 if (miblist
== NULL
) {
700 if ( needmibs
== TRUE
) {
701 miblist
= strdup (DEFAULT_MIBLIST
);
703 miblist
= "''"; /* don't read any mib files for numeric oids */
708 /* Need better checks to verify seclevel and authproto choices */
710 if (seclevel
== NULL
)
711 asprintf (&seclevel
, "noAuthNoPriv");
714 if (authproto
== NULL
)
715 asprintf(&authproto
, DEFAULT_AUTH_PROTOCOL
);
719 if (proto
== NULL
|| (strcmp(proto
,DEFAULT_PROTOCOL
) == 0) ) { /* default protocol version */
720 asprintf(&proto
, DEFAULT_PROTOCOL
);
721 asprintf(&authpriv
, "%s%s", "-c ", community
);
723 else if ( strcmp (proto
, "2c") == 0 ) { /* snmpv2c args */
724 asprintf(&authpriv
, "%s%s", "-c ", community
);
726 else if ( strcmp (proto
, "3") == 0 ) { /* snmpv3 args */
727 asprintf(&proto
, "%s", "3");
729 if ( (strcmp(seclevel
, "noAuthNoPriv") == 0) || seclevel
== NULL
) {
730 asprintf(&authpriv
, "%s", "-l noAuthNoPriv" );
732 else if ( strcmp(seclevel
, "authNoPriv") == 0 ) {
733 if ( secname
== NULL
|| authpasswd
== NULL
) {
734 printf (_("Missing secname (%s) or authpassword (%s) ! \n"),secname
, authpasswd
);
736 exit (STATE_UNKNOWN
);
738 asprintf(&authpriv
, "-l authNoPriv -a %s -u %s -A %s ", authproto
, secname
, authpasswd
);
740 else if ( strcmp(seclevel
, "authPriv") == 0 ) {
741 if ( secname
== NULL
|| authpasswd
== NULL
|| privpasswd
== NULL
) {
742 printf (_("Missing secname (%s), authpassword (%s), or privpasswd (%s)! \n"),secname
, authpasswd
,privpasswd
);
744 exit (STATE_UNKNOWN
);
746 asprintf(&authpriv
, "-l authPriv -a %s -u %s -A %s -x DES -X %s ", authproto
, secname
, authpasswd
, privpasswd
);
751 usage2 (_("Invalid SNMP version"), proto
);
760 clarify_message (char *msg
)
764 char tmpmsg_c
[MAX_INPUT_BUFFER
];
765 char *tmpmsg
= (char *) &tmpmsg_c
;
766 tmpmsg
= strcpy (tmpmsg
, msg
);
767 if (!strncmp (tmpmsg
, " Hex:", 5)) {
768 tmpmsg
= strtok (tmpmsg
, ":");
769 while ((tmpmsg
= strtok (NULL
, " "))) {
770 foo
= strtol (tmpmsg
, NULL
, 16);
771 /* Translate chars that are not the same value in the printers
801 if (eval_method
[i
] & WARN_GT
&& eval_method
[i
] & WARN_LT
&&
802 lower_warn_lim
[i
] > upper_warn_lim
[i
]) {
803 if (response_value
[i
] <= lower_warn_lim
[i
] &&
804 response_value
[i
] >= upper_warn_lim
[i
]) {
805 result
= STATE_WARNING
;
809 ((eval_method
[i
] & WARN_GT
&& response_value
[i
] > upper_warn_lim
[i
]) ||
810 (eval_method
[i
] & WARN_GE
&& response_value
[i
] >= upper_warn_lim
[i
]) ||
811 (eval_method
[i
] & WARN_LT
&& response_value
[i
] < lower_warn_lim
[i
]) ||
812 (eval_method
[i
] & WARN_LE
&& response_value
[i
] <= lower_warn_lim
[i
]) ||
813 (eval_method
[i
] & WARN_EQ
&& response_value
[i
] == upper_warn_lim
[i
]) ||
814 (eval_method
[i
] & WARN_NE
&& response_value
[i
] != upper_warn_lim
[i
])) {
815 result
= STATE_WARNING
;
818 if (eval_method
[i
] & CRIT_GT
&& eval_method
[i
] & CRIT_LT
&&
819 lower_crit_lim
[i
] > upper_crit_lim
[i
]) {
820 if (response_value
[i
] <= lower_crit_lim
[i
] &&
821 response_value
[i
] >= upper_crit_lim
[i
]) {
822 result
= STATE_CRITICAL
;
826 ((eval_method
[i
] & CRIT_GT
&& response_value
[i
] > upper_crit_lim
[i
]) ||
827 (eval_method
[i
] & CRIT_GE
&& response_value
[i
] >= upper_crit_lim
[i
]) ||
828 (eval_method
[i
] & CRIT_LT
&& response_value
[i
] < lower_crit_lim
[i
]) ||
829 (eval_method
[i
] & CRIT_LE
&& response_value
[i
] <= lower_crit_lim
[i
]) ||
830 (eval_method
[i
] & CRIT_EQ
&& response_value
[i
] == upper_crit_lim
[i
]) ||
831 (eval_method
[i
] & CRIT_NE
&& response_value
[i
] != upper_crit_lim
[i
])) {
832 result
= STATE_CRITICAL
;
841 llu_getll (unsigned long long *ll
, char *str
)
844 if (strchr (str
, ':') == NULL
)
846 if (strchr (str
, ',') != NULL
&& (strchr (str
, ',') < strchr (str
, ':')))
848 if (sscanf (str
, "%llu%[:]", ll
, tmp
) == 2)
856 llu_getul (unsigned long long *ul
, char *str
)
859 if (sscanf (str
, "%llu%[^,]", ul
, tmp
) == 1)
861 if (sscanf (str
, ":%llu%[^,]", ul
, tmp
) == 1)
863 if (sscanf (str
, "%*u:%llu%[^,]", ul
, tmp
) == 1)
870 /* trim leading whitespace
871 if there is a leading quote, make sure it balances */
876 str
+= strspn (str
, " \t\r\n"); /* trim any leading whitespace */
877 if (strstr (str
, "'") == str
) { /* handle SIMPLE quoted strings */
878 if (strlen (str
) == 1 || !strstr (str
+ 1, "'"))
879 die (STATE_UNKNOWN
, _("Unbalanced quotes\n"));
886 /* if there's a leading quote, advance to the trailing quote
887 set the trailing quote to '\x0'
888 if the string continues, advance beyond the comma */
893 if (strstr (str
, "'") == str
) {
895 if (strlen (str
) > 1) {
896 str
= strstr (str
+ 1, "'");
903 if (strstr (str
, ",") == str
) {
905 if (strlen (str
) > 1) {
912 if ((str
= strstr (str
, ",")) && strlen (str
) > 1) {
924 print_revision (progname
, revision
);
926 printf (COPYRIGHT
, copyright
, email
);
928 printf ("%s\n", _("Check status of remote machines and obtain sustem information via SNMP"));
934 printf (_(UT_HELP_VRSN
));
936 printf (_(UT_HOST_PORT
), 'p', DEFAULT_PORT
);
938 /* SNMP and Authentication Protocol */
939 printf (" %s\n", "-n, --next");
940 printf (" %s\n", _("Use SNMP GETNEXT instead of SNMP GET"));
941 printf (" %s\n", "-P, --protocol=[1|2c|3]");
942 printf (" %s\n", _("SNMP protocol version"));
943 printf (" %s\n", "-L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]");
944 printf (" %s\n", _("SNMPv3 securityLevel"));
945 printf (" %s\n", "-a, --authproto=[MD5|SHA]");
946 printf (" %s\n", _("SNMPv3 auth proto"));
948 /* Authentication Tokens*/
949 printf (" %s\n", "-C, --community=STRING");
950 printf (" %s ", _("Optional community string for SNMP communication"));
951 printf ("(%s \"%s\")\n", _("default is") ,DEFAULT_COMMUNITY
);
952 printf (" %s\n", "-U, --secname=USERNAME");
953 printf (" %s\n", _("SNMPv3 username"));
954 printf (" %s\n", "-A, --authpassword=PASSWORD");
955 printf (" %s\n", _("SNMPv3 authentication password"));
956 printf (" %s\n", "-X, --privpasswd=PASSWORD");
957 printf (" %s\n", _("SNMPv3 privacy password"));
960 printf (" %s\n", "-o, --oid=OID(s)");
961 printf (" %s\n", _("Object identifier(s) or SNMP variables whose value you wish to query"));
962 printf (" %s\n", "-m, --miblist=STRING");
963 printf (" %s\n", _("List of MIBS to be loaded (default = none if using numeric oids or 'ALL'"));
964 printf (" %s\n", _("for symbolic oids.)"));
965 printf (" %s\n", "-d, --delimiter=STRING");
966 printf (_(" Delimiter to use when parsing returned data. Default is \"%s\""), DEFAULT_DELIMITER
);
967 printf (" %s\n", _("Any data on the right hand side of the delimiter is considered"));
968 printf (" %s\n", _("to be the data that should be used in the evaluation."));
970 /* Tests Against Integers */
971 printf (" %s\n", "-w, --warning=INTEGER_RANGE(s)");
972 printf (" %s\n", _("Range(s) which will not result in a WARNING status"));
973 printf (" %s\n", "-c, --critical=INTEGER_RANGE(s)");
974 printf (" %s\n", _("Range(s) which will not result in a CRITICAL status"));
976 /* Tests Against Strings */
977 printf (" %s\n", "-s, --string=STRING");
978 printf (" %s\n", _("Return OK state (for that OID) if STRING is an exact match"));
979 printf (" %s\n", "-r, --ereg=REGEX");
980 printf (" %s\n", _("Return OK state (for that OID) if extended regular expression REGEX matches"));
981 printf (" %s\n", "-R, --eregi=REGEX");
982 printf (" %s\n", _("Return OK state (for that OID) if case-insensitive extended REGEX matches"));
983 printf (" %s\n", "-l, --label=STRING");
984 printf (" %s\n", _("Prefix label for output from plugin (default -s 'SNMP')"));
986 /* Output Formatting */
987 printf (" %s\n", "-u, --units=STRING");
988 printf (" %s\n", _("Units label(s) for output data (e.g., 'sec.')."));
989 printf (" %s\n", "-D, --output-delimiter=STRING");
990 printf (" %s\n", _("Separates output on multiple OID requests"));
992 printf (_(UT_TIMEOUT
), DEFAULT_SOCKET_TIMEOUT
);
994 printf (_(UT_VERBOSE
));
997 printf ("%s\n", _("This plugin uses the 'snmpget' command included with the NET-SNMP package."));
998 printf ("%s\n", _("if you don't have the package installed, you will need to download it from"));
999 printf ("%s\n", _("http://net-snmp.sourceforge.net before you can use this plugin."));
1002 printf ("%s\n", _("Notes:"));
1003 printf (" %s\n", _("- Multiple OIDs may be indicated by a comma- or space-delimited list (lists with"));
1004 printf (" %s\n", _("internal spaces must be quoted) [max 8 OIDs]"));
1006 printf (" %s\n", _("- Ranges are inclusive and are indicated with colons. When specified as"));
1007 printf (" %s\n", _("'min:max' a STATE_OK will be returned if the result is within the indicated"));
1008 printf (" %s\n", _("range or is equal to the upper or lower bound. A non-OK state will be"));
1009 printf (" %s\n", _("returned if the result is outside the specified range."));
1011 printf (" %s\n", _("- If specified in the order 'max:min' a non-OK state will be returned if the"));
1012 printf (" %s\n", _("result is within the (inclusive) range."));
1014 printf (" %s\n", _("- Upper or lower bounds may be omitted to skip checking the respective limit."));
1015 printf (" %s\n", _("- Bare integers are interpreted as upper limits."));
1016 printf (" %s\n", _("- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'"));
1017 printf (" %s\n", _("- Note that only one string and one regex may be checked at present"));
1018 printf (" %s\n", _("- All evaluation methods other than PR, STR, and SUBSTR expect that the value"));
1019 printf (" %s\n", _("returned from the SNMP query is an unsigned integer."));
1021 printf (_(UT_SUPPORT
));
1029 printf (_("Usage:"));
1030 printf ("%s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range]\n",progname
);
1031 printf ("[-C community] [-s string] [-r regex] [-R regexi] [-t timeout] [-e retries]\n");
1032 printf ("[-l label] [-u units] [-p port-number] [-d delimiter] [-D output-delimiter]\n");
1033 printf ("[-m miblist] [-P snmp version] [-L seclevel] [-U secname] [-a authproto]\n");
1034 printf ("[-A authpasswd] [-X privpasswd]\n");