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