summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_snmp.c200
1 files changed, 108 insertions, 92 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c
index 2aded73b..097c30ea 100644
--- a/plugins/check_snmp.c
+++ b/plugins/check_snmp.c
@@ -24,57 +24,95 @@
24 *****************************************************************************/ 24 *****************************************************************************/
25 25
26const char *progname = "check_snmp"; 26const char *progname = "check_snmp";
27#define REVISION "$Revision$" 27const char *revision = "$Revision$";
28#define COPYRIGHT "1999-2002" 28const char *copyright = "1999-2003";
29#define AUTHOR "Ethan Galstad" 29const char *email = "nagiosplug-devel@lists.sourceforge.net";
30#define EMAIL "nagios@nagios.org" 30
31#define SUMMARY "Check status of remote machines using SNMP.\n" 31#define DEFAULT_COMMUNITY "public"
32 32#define DEFAULT_PORT "161"
33#define OPTIONS "\ 33#define DEFAULT_MIBLIST "ALL"
34-H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\ 34#define DEFAULT_PROTOCOL "1"
35 [-C community] [-s string] [-r regex] [-R regexi] [-t timeout]\n\ 35#define DEFAULT_AUTH_PROTOCOL "MD5"
36 [-l label] [-u units] [-p port-number] [-d delimiter]\n\ 36#define DEFAULT_DELIMITER "="
37 [-D output-delimiter] [-m miblist] [-P snmp version]\n\ 37#define DEFAULT_OUTPUT_DELIMITER " "
38 [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\ 38
39 [-X privpasswd]\n" 39#include "common.h"
40 40#include "utils.h"
41#define LONGOPTIONS "\ 41#include "popen.h"
42 -H, --hostname=HOST\n\ 42
43 Name or IP address of the device you wish to query\n\ 43void
44 -o, --oid=OID(s)\n\ 44print_usage (void)
45 Object identifier(s) whose value you wish to query\n\ 45{
46 -w, --warning=INTEGER_RANGE(s)\n\ 46 printf ("\
47 Range(s) which will not result in a WARNING status\n\ 47Usage: %s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\
48 -c, --critical=INTEGER_RANGE(s)\n\ 48 [-C community] [-s string] [-r regex] [-R regexi] [-t timeout]\n\
49 Range(s) which will not result in a CRITICAL status\n\ 49 [-l label] [-u units] [-p port-number] [-d delimiter]\n\
50 -C, --community=STRING\n\ 50 [-D output-delimiter] [-m miblist] [-P snmp version]\n\
51 Optional community string for SNMP communication\n\ 51 [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\
52 (default is \"%s\")\n\ 52 [-X privpasswd]\n",
53 -u, --units=STRING\n\ 53 progname);
54 Units label(s) for output data (e.g., 'sec.').\n\ 54 printf ("\
55 -p, --port=STRING\n\ 55 %s (-h | --help) for detailed help\n\
56 UDP port number target is listening on. Default is \"%s\"\n\ 56 %s (-V | --version) for version information\n",
57 progname, progname);
58}
59
60void
61print_help (void)
62{
63 print_revision (progname, revision);
64
65 printf (_(COPYRIGHT), copyright, email);
66
67 printf (_("\
68Check status of remote machines and obtain sustem information via SNMP"));
69
70 print_usage ();
71
72 printf (_(UT_HELP_VRSN));
73
74 printf (_(UT_HOST_PORT), 'p', DEFAULT_PORT);
75
76 /* SNMP and Authentication Protocol */
77 printf (_("\
57 -P, --protocol=[1|3]\n\ 78 -P, --protocol=[1|3]\n\
58 SNMP protocol version\n\ 79 SNMP protocol version\n\
59 -L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]\n\ 80 -L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]\n\
60 SNMPv3 securityLevel\n\ 81 SNMPv3 securityLevel\n\
82 -a, --authproto=[MD5|SHA]\n\
83 SNMPv3 auth proto\n"));
84
85 /* Authentication Tokens*/
86 printf (_("\
87 -C, --community=STRING\n\
88 Optional community string for SNMP communication\n\
89 (default is \"%s\")\n\
61 -U, --secname=USERNAME\n\ 90 -U, --secname=USERNAME\n\
62 SNMPv3 username\n\ 91 SNMPv3 username\n\
63 -a, --authproto=[MD5|SHA]\n\
64 SNMPv3 auth proto\n\
65 -A, --authpassword=PASSWORD\n\ 92 -A, --authpassword=PASSWORD\n\
66 SNMPv3 authentication password\n\ 93 SNMPv3 authentication password\n\
67 -X, --privpasswd=PASSWORD\n\ 94 -X, --privpasswd=PASSWORD\n\
68 SNMPv3 crypt passwd (DES)\n\ 95 SNMPv3 crypt passwd (DES)\n"), DEFAULT_COMMUNITY);
69 -d, --delimiter=STRING\n\ 96
97 /* OID Stuff */
98 printf (_("\
99 -o, --oid=OID(s)\n\
100 Object identifier(s) whose value you wish to query\n\
101 -m, --miblist=STRING\n\
102 List of MIBS to be loaded (default = ALL)\n -d, --delimiter=STRING\n\
70 Delimiter to use when parsing returned data. Default is \"%s\"\n\ 103 Delimiter to use when parsing returned data. Default is \"%s\"\n\
71 Any data on the right hand side of the delimiter is considered\n\ 104 Any data on the right hand side of the delimiter is considered\n\
72 to be the data that should be used in the evaluation.\n\ 105 to be the data that should be used in the evaluation.\n"), DEFAULT_DELIMITER);
73 -t, --timeout=INTEGER\n\ 106
74 Seconds to wait before plugin times out (see also nagios server timeout).\n\ 107 /* Tests Against Integers */
75 Default is %d seconds\n\ 108 printf (_("\
76 -D, --output-delimiter=STRING\n\ 109 -w, --warning=INTEGER_RANGE(s)\n\
77 Separates output on multiple OID requests\n\ 110 Range(s) which will not result in a WARNING status\n\
111 -c, --critical=INTEGER_RANGE(s)\n\
112 Range(s) which will not result in a CRITICAL status\n"));
113
114 /* Tests Against Strings */
115 printf (_("\
78 -s, --string=STRING\n\ 116 -s, --string=STRING\n\
79 Return OK state (for that OID) if STRING is an exact match\n\ 117 Return OK state (for that OID) if STRING is an exact match\n\
80 -r, --ereg=REGEX\n\ 118 -r, --ereg=REGEX\n\
@@ -82,44 +120,49 @@ const char *progname = "check_snmp";
82 -R, --eregi=REGEX\n\ 120 -R, --eregi=REGEX\n\
83 Return OK state (for that OID) if case-insensitive extended REGEX matches\n\ 121 Return OK state (for that OID) if case-insensitive extended REGEX matches\n\
84 -l, --label=STRING\n\ 122 -l, --label=STRING\n\
85 Prefix label for output from plugin (default -s 'SNMP')\n\ 123 Prefix label for output from plugin (default -s 'SNMP')\n"));
86 -v, --verbose\n\ 124
87 Debugging the output\n\ 125 /* Output Formatting */
88 -m, --miblist=STRING\n\ 126 printf (_("\
89 List of MIBS to be loaded (default = ALL)\n" 127 -u, --units=STRING\n\
128 Units label(s) for output data (e.g., 'sec.').\n\
129 -D, --output-delimiter=STRING\n\
130 Separates output on multiple OID requests\n"));
90 131
91#define NOTES "\ 132 printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT);
133
134 printf (_(UT_VERBOSE));
135
136 printf (_("\
92- This plugin uses the 'snmpget' command included with the NET-SNMP package.\n\ 137- This plugin uses the 'snmpget' command included with the NET-SNMP package.\n\
93 If you don't have the package installed, you will need to download it from\n\ 138 If you don't have the package installed, you will need to download it from\n\
94 http://net-snmp.sourceforge.net before you can use this plugin.\n\ 139 http://net-snmp.sourceforge.net before you can use this plugin.\n"));
140
141 printf (_("\
95- Multiple OIDs may be indicated by a comma- or space-delimited list (lists with\n\ 142- Multiple OIDs may be indicated by a comma- or space-delimited list (lists with\n\
96 internal spaces must be quoted) [max 8 OIDs]\n\ 143 internal spaces must be quoted) [max 8 OIDs]\n"));
144
145 printf (_("\
97- Ranges are inclusive and are indicated with colons. When specified as\n\ 146- Ranges are inclusive and are indicated with colons. When specified as\n\
98 'min:max' a STATE_OK will be returned if the result is within the indicated\n\ 147 'min:max' a STATE_OK will be returned if the result is within the indicated\n\
99 range or is equal to the upper or lower bound. A non-OK state will be\n\ 148 range or is equal to the upper or lower bound. A non-OK state will be\n\
100 returned if the result is outside the specified range.\n\ 149 returned if the result is outside the specified range.\n"));
150
151 printf (_("\
101- If specified in the order 'max:min' a non-OK state will be returned if the\n\ 152- If specified in the order 'max:min' a non-OK state will be returned if the\n\
102 result is within the (inclusive) range.\n\ 153 result is within the (inclusive) range.\n"));
154
155 printf (_("\
103- Upper or lower bounds may be omitted to skip checking the respective limit.\n\ 156- Upper or lower bounds may be omitted to skip checking the respective limit.\n\
104- Bare integers are interpreted as upper limits.\n\ 157- Bare integers are interpreted as upper limits.\n\
105- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'\n\ 158- When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'\n\
106- Note that only one string and one regex may be checked at present\n\ 159- Note that only one string and one regex may be checked at present\n\
107- All evaluation methods other than PR, STR, and SUBSTR expect that the value\n\ 160- All evaluation methods other than PR, STR, and SUBSTR expect that the value\n\
108 returned from the SNMP query is an unsigned integer.\n" 161 returned from the SNMP query is an unsigned integer.\n"));
109 162
110#define DESCRIPTION "\ 163 support ();
111This plugin gets system information on a remote server via snmp.\n" 164}
112 165
113#define DEFAULT_COMMUNITY "public"
114#define DEFAULT_PORT "161"
115#define DEFAULT_TIMEOUT 10
116#define DEFAULT_MIBLIST "ALL"
117#define DEFAULT_PROTOCOL "1"
118#define DEFAULT_AUTH_PROTOCOL "MD5"
119
120#include "common.h"
121#include "utils.h"
122#include "popen.h"
123 166
124#define mark(a) ((a)!=0?"*":"") 167#define mark(a) ((a)!=0?"*":"")
125 168
@@ -147,8 +190,6 @@ This plugin gets system information on a remote server via snmp.\n"
147 190
148#define MAX_OIDS 8 191#define MAX_OIDS 8
149#define MAX_DELIM_LENGTH 8 192#define MAX_DELIM_LENGTH 8
150#define DEFAULT_DELIMITER "="
151#define DEFAULT_OUTPUT_DELIMITER " "
152 193
153void print_usage (void); 194void print_usage (void);
154void print_help (void); 195void print_help (void);
@@ -474,7 +515,7 @@ process_arguments (int argc, char **argv)
474 print_help (); 515 print_help ();
475 exit (STATE_OK); 516 exit (STATE_OK);
476 case 'V': /* version */ 517 case 'V': /* version */
477 print_revision (progname, REVISION); 518 print_revision (progname, revision);
478 exit (STATE_OK); 519 exit (STATE_OK);
479 case 'v': /* verbose */ 520 case 'v': /* verbose */
480 verbose = TRUE; 521 verbose = TRUE;
@@ -746,31 +787,6 @@ validate_arguments ()
746 787
747 return OK; 788 return OK;
748} 789}
749
750
751
752void
753print_help (void)
754{
755 print_revision (progname, REVISION);
756 printf
757 ("Copyright (c) %s %s <%s>\n\n%s\n", COPYRIGHT, AUTHOR, EMAIL, SUMMARY);
758 print_usage ();
759 printf
760 ("\nOptions:\n" LONGOPTIONS "\n" DESCRIPTION "\n" NOTES "\n",
761 DEFAULT_COMMUNITY, DEFAULT_PORT, DEFAULT_DELIMITER, DEFAULT_TIMEOUT);
762 support ();
763}
764
765void
766print_usage (void)
767{
768 printf
769 ("Usage:\n" " %s %s\n"
770 " %s (-h | --help) for detailed help\n"
771 " %s (-V | --version) for version information\n",
772 progname, OPTIONS, progname, progname);
773}
774 790
775 791
776 792