diff options
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_snmp.c | 333 |
1 files changed, 176 insertions, 157 deletions
diff --git a/plugins/check_snmp.c b/plugins/check_snmp.c index 2e2430d..dcb6e68 100644 --- a/plugins/check_snmp.c +++ b/plugins/check_snmp.c | |||
@@ -1,33 +1,30 @@ | |||
1 | /****************************************************************************** | 1 | /****************************************************************************** |
2 | * | 2 | |
3 | * Program: SNMP plugin for Nagios | 3 | This program is free software; you can redistribute it and/or modify |
4 | * License: GPL | 4 | it under the terms of the GNU General Public License as published by |
5 | * | 5 | the Free Software Foundation; either version 2 of the License, or |
6 | * License Information: | 6 | (at your option) any later version. |
7 | * | 7 | |
8 | * This program is free software; you can redistribute it and/or modify | 8 | This program is distributed in the hope that it will be useful, |
9 | * it under the terms of the GNU General Public License as published by | 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * the Free Software Foundation; either version 2 of the License, or | 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * (at your option) any later version. | 11 | GNU General Public License for more details. |
12 | * | 12 | |
13 | * This program is distributed in the hope that it will be useful, | 13 | You should have received a copy of the GNU General Public License |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 | along with this program; if not, write to the Free Software |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 15 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
16 | * GNU General Public License for more details. | 16 | |
17 | * | 17 | ******************************************************************************/ |
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
21 | * | ||
22 | *./plugins/check_snmp 127.0.0.1 -c public -o .1.3.6.1.4.1.2021.9.1.2.1 | ||
23 | * | ||
24 | *****************************************************************************/ | ||
25 | 18 | ||
26 | const char *progname = "check_snmp"; | 19 | const char *progname = "check_snmp"; |
27 | const char *revision = "$Revision$"; | 20 | const char *revision = "$Revision$"; |
28 | const char *copyright = "1999-2003"; | 21 | const char *copyright = "1999-2003"; |
29 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; | 22 | const char *email = "nagiosplug-devel@lists.sourceforge.net"; |
30 | 23 | ||
24 | #include "common.h" | ||
25 | #include "utils.h" | ||
26 | #include "popen.h" | ||
27 | |||
31 | #define DEFAULT_COMMUNITY "public" | 28 | #define DEFAULT_COMMUNITY "public" |
32 | #define DEFAULT_PORT "161" | 29 | #define DEFAULT_PORT "161" |
33 | #define DEFAULT_MIBLIST "ALL" | 30 | #define DEFAULT_MIBLIST "ALL" |
@@ -36,130 +33,6 @@ const char *email = "nagiosplug-devel@lists.sourceforge.net"; | |||
36 | #define DEFAULT_DELIMITER "=" | 33 | #define DEFAULT_DELIMITER "=" |
37 | #define DEFAULT_OUTPUT_DELIMITER " " | 34 | #define DEFAULT_OUTPUT_DELIMITER " " |
38 | 35 | ||
39 | #include "common.h" | ||
40 | #include "utils.h" | ||
41 | #include "popen.h" | ||
42 | |||
43 | void | ||
44 | print_usage (void) | ||
45 | { | ||
46 | printf (_("\ | ||
47 | Usage: %s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\ | ||
48 | [-C community] [-s string] [-r regex] [-R regexi] [-t timeout]\n\ | ||
49 | [-l label] [-u units] [-p port-number] [-d delimiter]\n\ | ||
50 | [-D output-delimiter] [-m miblist] [-P snmp version]\n\ | ||
51 | [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\ | ||
52 | [-X privpasswd]\n"), progname); | ||
53 | printf (_(UT_HLP_VRS), progname, progname); | ||
54 | } | ||
55 | |||
56 | void | ||
57 | print_help (void) | ||
58 | { | ||
59 | print_revision (progname, revision); | ||
60 | |||
61 | printf (_(COPYRIGHT), copyright, email); | ||
62 | |||
63 | printf (_("\ | ||
64 | Check status of remote machines and obtain sustem information via SNMP\n\n")); | ||
65 | |||
66 | print_usage (); | ||
67 | |||
68 | printf (_(UT_HELP_VRSN)); | ||
69 | |||
70 | printf (_(UT_HOST_PORT), 'p', DEFAULT_PORT); | ||
71 | |||
72 | /* SNMP and Authentication Protocol */ | ||
73 | printf (_("\ | ||
74 | -P, --protocol=[1|3]\n\ | ||
75 | SNMP protocol version\n\ | ||
76 | -L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]\n\ | ||
77 | SNMPv3 securityLevel\n\ | ||
78 | -a, --authproto=[MD5|SHA]\n\ | ||
79 | SNMPv3 auth proto\n")); | ||
80 | |||
81 | /* Authentication Tokens*/ | ||
82 | printf (_("\ | ||
83 | -C, --community=STRING\n\ | ||
84 | Optional community string for SNMP communication\n\ | ||
85 | (default is \"%s\")\n\ | ||
86 | -U, --secname=USERNAME\n\ | ||
87 | SNMPv3 username\n\ | ||
88 | -A, --authpassword=PASSWORD\n\ | ||
89 | SNMPv3 authentication password\n\ | ||
90 | -X, --privpasswd=PASSWORD\n\ | ||
91 | SNMPv3 crypt passwd (DES)\n"), DEFAULT_COMMUNITY); | ||
92 | |||
93 | /* OID Stuff */ | ||
94 | printf (_("\ | ||
95 | -o, --oid=OID(s)\n\ | ||
96 | Object identifier(s) whose value you wish to query\n\ | ||
97 | -m, --miblist=STRING\n\ | ||
98 | List of MIBS to be loaded (default = ALL)\n -d, --delimiter=STRING\n\ | ||
99 | Delimiter to use when parsing returned data. Default is \"%s\"\n\ | ||
100 | Any data on the right hand side of the delimiter is considered\n\ | ||
101 | to be the data that should be used in the evaluation.\n"), DEFAULT_DELIMITER); | ||
102 | |||
103 | /* Tests Against Integers */ | ||
104 | printf (_("\ | ||
105 | -w, --warning=INTEGER_RANGE(s)\n\ | ||
106 | Range(s) which will not result in a WARNING status\n\ | ||
107 | -c, --critical=INTEGER_RANGE(s)\n\ | ||
108 | Range(s) which will not result in a CRITICAL status\n")); | ||
109 | |||
110 | /* Tests Against Strings */ | ||
111 | printf (_("\ | ||
112 | -s, --string=STRING\n\ | ||
113 | Return OK state (for that OID) if STRING is an exact match\n\ | ||
114 | -r, --ereg=REGEX\n\ | ||
115 | Return OK state (for that OID) if extended regular expression REGEX matches\n\ | ||
116 | -R, --eregi=REGEX\n\ | ||
117 | Return OK state (for that OID) if case-insensitive extended REGEX matches\n\ | ||
118 | -l, --label=STRING\n\ | ||
119 | Prefix label for output from plugin (default -s 'SNMP')\n")); | ||
120 | |||
121 | /* Output Formatting */ | ||
122 | printf (_("\ | ||
123 | -u, --units=STRING\n\ | ||
124 | Units label(s) for output data (e.g., 'sec.').\n\ | ||
125 | -D, --output-delimiter=STRING\n\ | ||
126 | Separates output on multiple OID requests\n")); | ||
127 | |||
128 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
129 | |||
130 | printf (_(UT_VERBOSE)); | ||
131 | |||
132 | printf (_("\n\ | ||
133 | - This plugin uses the 'snmpget' command included with the NET-SNMP package.\n\ | ||
134 | If you don't have the package installed, you will need to download it from\n\ | ||
135 | http://net-snmp.sourceforge.net before you can use this plugin.\n")); | ||
136 | |||
137 | printf (_("\ | ||
138 | - Multiple OIDs may be indicated by a comma- or space-delimited list (lists with\n\ | ||
139 | internal spaces must be quoted) [max 8 OIDs]\n")); | ||
140 | |||
141 | printf (_("\ | ||
142 | - Ranges are inclusive and are indicated with colons. When specified as\n\ | ||
143 | 'min:max' a STATE_OK will be returned if the result is within the indicated\n\ | ||
144 | range or is equal to the upper or lower bound. A non-OK state will be\n\ | ||
145 | returned if the result is outside the specified range.\n")); | ||
146 | |||
147 | printf (_("\ | ||
148 | - If specified in the order 'max:min' a non-OK state will be returned if the\n\ | ||
149 | result is within the (inclusive) range.\n")); | ||
150 | |||
151 | printf (_("\ | ||
152 | - Upper or lower bounds may be omitted to skip checking the respective limit.\n\ | ||
153 | - Bare integers are interpreted as upper limits.\n\ | ||
154 | - When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'\n\ | ||
155 | - Note that only one string and one regex may be checked at present\n\ | ||
156 | - All evaluation methods other than PR, STR, and SUBSTR expect that the value\n\ | ||
157 | returned from the SNMP query is an unsigned integer.\n")); | ||
158 | |||
159 | printf (_(UT_SUPPORT)); | ||
160 | } | ||
161 | |||
162 | |||
163 | #define mark(a) ((a)!=0?"*":"") | 36 | #define mark(a) ((a)!=0?"*":"") |
164 | 37 | ||
165 | #define CHECK_UNDEF 0 | 38 | #define CHECK_UNDEF 0 |
@@ -187,16 +60,16 @@ Check status of remote machines and obtain sustem information via SNMP\n\n")); | |||
187 | #define MAX_OIDS 8 | 60 | #define MAX_OIDS 8 |
188 | #define MAX_DELIM_LENGTH 8 | 61 | #define MAX_DELIM_LENGTH 8 |
189 | 62 | ||
190 | void print_usage (void); | ||
191 | void print_help (void); | ||
192 | int process_arguments (int, char **); | 63 | int process_arguments (int, char **); |
193 | int validate_arguments (void); | 64 | int validate_arguments (void); |
194 | int check_num (int); | ||
195 | char *clarify_message (char *); | 65 | char *clarify_message (char *); |
66 | int check_num (int); | ||
196 | int lu_getll (unsigned long *, char *); | 67 | int lu_getll (unsigned long *, char *); |
197 | int lu_getul (unsigned long *, char *); | 68 | int lu_getul (unsigned long *, char *); |
198 | char *thisarg (char *str); | 69 | char *thisarg (char *str); |
199 | char *nextarg (char *str); | 70 | char *nextarg (char *str); |
71 | void print_usage (void); | ||
72 | void print_help (void); | ||
200 | 73 | ||
201 | #ifdef HAVE_REGEX_H | 74 | #ifdef HAVE_REGEX_H |
202 | #include <regex.h> | 75 | #include <regex.h> |
@@ -244,6 +117,10 @@ char *output_delim = DEFAULT_OUTPUT_DELIMITER; | |||
244 | char *miblist = DEFAULT_MIBLIST; | 117 | char *miblist = DEFAULT_MIBLIST; |
245 | 118 | ||
246 | 119 | ||
120 | |||
121 | |||
122 | |||
123 | |||
247 | int | 124 | int |
248 | main (int argc, char **argv) | 125 | main (int argc, char **argv) |
249 | { | 126 | { |
@@ -427,10 +304,10 @@ main (int argc, char **argv) | |||
427 | } /* end while (ptr) */ | 304 | } /* end while (ptr) */ |
428 | 305 | ||
429 | if (found == 0) | 306 | if (found == 0) |
430 | die | 307 | die (STATE_UNKNOWN, |
431 | (STATE_UNKNOWN, | 308 | _("%s problem - No data recieved from host\nCMD: %s\n"), |
432 | _("%s problem - No data recieved from host\nCMD: %s\n"), | 309 | label, |
433 | label, command_line); | 310 | command_line); |
434 | 311 | ||
435 | /* WARNING if output found on stderr */ | 312 | /* WARNING if output found on stderr */ |
436 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) | 313 | if (fgets (input_buffer, MAX_INPUT_BUFFER - 1, child_stderr)) |
@@ -451,6 +328,11 @@ main (int argc, char **argv) | |||
451 | return result; | 328 | return result; |
452 | } | 329 | } |
453 | 330 | ||
331 | |||
332 | |||
333 | |||
334 | |||
335 | |||
454 | /* process command-line arguments */ | 336 | /* process command-line arguments */ |
455 | int | 337 | int |
456 | process_arguments (int argc, char **argv) | 338 | process_arguments (int argc, char **argv) |
@@ -708,6 +590,9 @@ process_arguments (int argc, char **argv) | |||
708 | return validate_arguments (); | 590 | return validate_arguments (); |
709 | } | 591 | } |
710 | 592 | ||
593 | |||
594 | |||
595 | |||
711 | /****************************************************************************** | 596 | /****************************************************************************** |
712 | 597 | ||
713 | @@- | 598 | @@- |
@@ -783,9 +668,12 @@ validate_arguments () | |||
783 | 668 | ||
784 | return OK; | 669 | return OK; |
785 | } | 670 | } |
786 | |||
787 | 671 | ||
788 | 672 | ||
673 | |||
674 | |||
675 | |||
676 | |||
789 | char * | 677 | char * |
790 | clarify_message (char *msg) | 678 | clarify_message (char *msg) |
791 | { | 679 | { |
@@ -822,6 +710,8 @@ clarify_message (char *msg) | |||
822 | } | 710 | } |
823 | 711 | ||
824 | 712 | ||
713 | |||
714 | |||
825 | int | 715 | int |
826 | check_num (int i) | 716 | check_num (int i) |
827 | { | 717 | { |
@@ -865,6 +755,8 @@ check_num (int i) | |||
865 | } | 755 | } |
866 | 756 | ||
867 | 757 | ||
758 | |||
759 | |||
868 | int | 760 | int |
869 | lu_getll (unsigned long *ll, char *str) | 761 | lu_getll (unsigned long *ll, char *str) |
870 | { | 762 | { |
@@ -878,6 +770,9 @@ lu_getll (unsigned long *ll, char *str) | |||
878 | return 0; | 770 | return 0; |
879 | } | 771 | } |
880 | 772 | ||
773 | |||
774 | |||
775 | |||
881 | int | 776 | int |
882 | lu_getul (unsigned long *ul, char *str) | 777 | lu_getul (unsigned long *ul, char *str) |
883 | { | 778 | { |
@@ -894,8 +789,6 @@ lu_getul (unsigned long *ul, char *str) | |||
894 | 789 | ||
895 | 790 | ||
896 | 791 | ||
897 | |||
898 | |||
899 | /* trim leading whitespace | 792 | /* trim leading whitespace |
900 | if there is a leading quote, make sure it balances */ | 793 | if there is a leading quote, make sure it balances */ |
901 | 794 | ||
@@ -911,6 +804,8 @@ thisarg (char *str) | |||
911 | } | 804 | } |
912 | 805 | ||
913 | 806 | ||
807 | |||
808 | |||
914 | /* if there's a leading quote, advance to the trailing quote | 809 | /* if there's a leading quote, advance to the trailing quote |
915 | set the trailing quote to '\x0' | 810 | set the trailing quote to '\x0' |
916 | if the string continues, advance beyond the comma */ | 811 | if the string continues, advance beyond the comma */ |
@@ -945,3 +840,127 @@ nextarg (char *str) | |||
945 | } | 840 | } |
946 | return NULL; | 841 | return NULL; |
947 | } | 842 | } |
843 | |||
844 | |||
845 | |||
846 | |||
847 | |||
848 | |||
849 | void | ||
850 | print_help (void) | ||
851 | { | ||
852 | print_revision (progname, revision); | ||
853 | |||
854 | printf (_(COPYRIGHT), copyright, email); | ||
855 | |||
856 | printf (_("\ | ||
857 | Check status of remote machines and obtain sustem information via SNMP\n\n")); | ||
858 | |||
859 | print_usage (); | ||
860 | |||
861 | printf (_(UT_HELP_VRSN)); | ||
862 | |||
863 | printf (_(UT_HOST_PORT), 'p', DEFAULT_PORT); | ||
864 | |||
865 | /* SNMP and Authentication Protocol */ | ||
866 | printf (_("\ | ||
867 | -P, --protocol=[1|3]\n\ | ||
868 | SNMP protocol version\n\ | ||
869 | -L, --seclevel=[noAuthNoPriv|authNoPriv|authPriv]\n\ | ||
870 | SNMPv3 securityLevel\n\ | ||
871 | -a, --authproto=[MD5|SHA]\n\ | ||
872 | SNMPv3 auth proto\n")); | ||
873 | |||
874 | /* Authentication Tokens*/ | ||
875 | printf (_("\ | ||
876 | -C, --community=STRING\n\ | ||
877 | Optional community string for SNMP communication\n\ | ||
878 | (default is \"%s\")\n\ | ||
879 | -U, --secname=USERNAME\n\ | ||
880 | SNMPv3 username\n\ | ||
881 | -A, --authpassword=PASSWORD\n\ | ||
882 | SNMPv3 authentication password\n\ | ||
883 | -X, --privpasswd=PASSWORD\n\ | ||
884 | SNMPv3 crypt passwd (DES)\n"), DEFAULT_COMMUNITY); | ||
885 | |||
886 | /* OID Stuff */ | ||
887 | printf (_("\ | ||
888 | -o, --oid=OID(s)\n\ | ||
889 | Object identifier(s) whose value you wish to query\n\ | ||
890 | -m, --miblist=STRING\n\ | ||
891 | List of MIBS to be loaded (default = ALL)\n -d, --delimiter=STRING\n\ | ||
892 | Delimiter to use when parsing returned data. Default is \"%s\"\n\ | ||
893 | Any data on the right hand side of the delimiter is considered\n\ | ||
894 | to be the data that should be used in the evaluation.\n"), DEFAULT_DELIMITER); | ||
895 | |||
896 | /* Tests Against Integers */ | ||
897 | printf (_("\ | ||
898 | -w, --warning=INTEGER_RANGE(s)\n\ | ||
899 | Range(s) which will not result in a WARNING status\n\ | ||
900 | -c, --critical=INTEGER_RANGE(s)\n\ | ||
901 | Range(s) which will not result in a CRITICAL status\n")); | ||
902 | |||
903 | /* Tests Against Strings */ | ||
904 | printf (_("\ | ||
905 | -s, --string=STRING\n\ | ||
906 | Return OK state (for that OID) if STRING is an exact match\n\ | ||
907 | -r, --ereg=REGEX\n\ | ||
908 | Return OK state (for that OID) if extended regular expression REGEX matches\n\ | ||
909 | -R, --eregi=REGEX\n\ | ||
910 | Return OK state (for that OID) if case-insensitive extended REGEX matches\n\ | ||
911 | -l, --label=STRING\n\ | ||
912 | Prefix label for output from plugin (default -s 'SNMP')\n")); | ||
913 | |||
914 | /* Output Formatting */ | ||
915 | printf (_("\ | ||
916 | -u, --units=STRING\n\ | ||
917 | Units label(s) for output data (e.g., 'sec.').\n\ | ||
918 | -D, --output-delimiter=STRING\n\ | ||
919 | Separates output on multiple OID requests\n")); | ||
920 | |||
921 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
922 | |||
923 | printf (_(UT_VERBOSE)); | ||
924 | |||
925 | printf (_("\n\ | ||
926 | - This plugin uses the 'snmpget' command included with the NET-SNMP package.\n\ | ||
927 | If you don't have the package installed, you will need to download it from\n\ | ||
928 | http://net-snmp.sourceforge.net before you can use this plugin.\n")); | ||
929 | |||
930 | printf (_("\ | ||
931 | - Multiple OIDs may be indicated by a comma- or space-delimited list (lists with\n\ | ||
932 | internal spaces must be quoted) [max 8 OIDs]\n")); | ||
933 | |||
934 | printf (_("\ | ||
935 | - Ranges are inclusive and are indicated with colons. When specified as\n\ | ||
936 | 'min:max' a STATE_OK will be returned if the result is within the indicated\n\ | ||
937 | range or is equal to the upper or lower bound. A non-OK state will be\n\ | ||
938 | returned if the result is outside the specified range.\n")); | ||
939 | |||
940 | printf (_("\ | ||
941 | - If specified in the order 'max:min' a non-OK state will be returned if the\n\ | ||
942 | result is within the (inclusive) range.\n")); | ||
943 | |||
944 | printf (_("\ | ||
945 | - Upper or lower bounds may be omitted to skip checking the respective limit.\n\ | ||
946 | - Bare integers are interpreted as upper limits.\n\ | ||
947 | - When checking multiple OIDs, separate ranges by commas like '-w 1:10,1:,:20'\n\ | ||
948 | - Note that only one string and one regex may be checked at present\n\ | ||
949 | - All evaluation methods other than PR, STR, and SUBSTR expect that the value\n\ | ||
950 | returned from the SNMP query is an unsigned integer.\n")); | ||
951 | |||
952 | printf (_(UT_SUPPORT)); | ||
953 | } | ||
954 | |||
955 | void | ||
956 | print_usage (void) | ||
957 | { | ||
958 | printf (_("\ | ||
959 | Usage: %s -H <ip_address> -o <OID> [-w warn_range] [-c crit_range] \n\ | ||
960 | [-C community] [-s string] [-r regex] [-R regexi] [-t timeout]\n\ | ||
961 | [-l label] [-u units] [-p port-number] [-d delimiter]\n\ | ||
962 | [-D output-delimiter] [-m miblist] [-P snmp version]\n\ | ||
963 | [-L seclevel] [-U secname] [-a authproto] [-A authpasswd]\n\ | ||
964 | [-X privpasswd]\n"), progname); | ||
965 | printf (_(UT_HLP_VRS), progname, progname); | ||
966 | } | ||