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