diff options
Diffstat (limited to 'plugins/check_mrtgtraf.c')
| -rw-r--r-- | plugins/check_mrtgtraf.c | 135 |
1 files changed, 55 insertions, 80 deletions
diff --git a/plugins/check_mrtgtraf.c b/plugins/check_mrtgtraf.c index 11f5146b..d33ebd9c 100644 --- a/plugins/check_mrtgtraf.c +++ b/plugins/check_mrtgtraf.c | |||
| @@ -55,7 +55,6 @@ | |||
| 55 | #define PROGNAME "check_mrtgtraf" | 55 | #define PROGNAME "check_mrtgtraf" |
| 56 | 56 | ||
| 57 | int process_arguments (int, char **); | 57 | int process_arguments (int, char **); |
| 58 | int call_getopt (int, char **); | ||
| 59 | int validate_arguments (void); | 58 | int validate_arguments (void); |
| 60 | void print_help (void); | 59 | void print_help (void); |
| 61 | void print_usage (void); | 60 | void print_usage (void); |
| @@ -77,7 +76,7 @@ main (int argc, char **argv) | |||
| 77 | char input_buffer[MAX_INPUT_BUFFER]; | 76 | char input_buffer[MAX_INPUT_BUFFER]; |
| 78 | char *temp_buffer; | 77 | char *temp_buffer; |
| 79 | time_t current_time; | 78 | time_t current_time; |
| 80 | char error_message[MAX_INPUT_BUFFER]; | 79 | char *error_message; |
| 81 | time_t timestamp = 0L; | 80 | time_t timestamp = 0L; |
| 82 | unsigned long average_incoming_rate = 0L; | 81 | unsigned long average_incoming_rate = 0L; |
| 83 | unsigned long average_outgoing_rate = 0L; | 82 | unsigned long average_outgoing_rate = 0L; |
| @@ -198,7 +197,7 @@ main (int argc, char **argv) | |||
| 198 | if (incoming_rate > incoming_critical_threshold | 197 | if (incoming_rate > incoming_critical_threshold |
| 199 | || outgoing_rate > outgoing_critical_threshold) { | 198 | || outgoing_rate > outgoing_critical_threshold) { |
| 200 | result = STATE_CRITICAL; | 199 | result = STATE_CRITICAL; |
| 201 | sprintf (error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", | 200 | asprintf (&error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", |
| 202 | (use_average == TRUE) ? "Ave" : "Max", adjusted_incoming_rate, | 201 | (use_average == TRUE) ? "Ave" : "Max", adjusted_incoming_rate, |
| 203 | incoming_speed_rating, (use_average == TRUE) ? "Ave" : "Max", | 202 | incoming_speed_rating, (use_average == TRUE) ? "Ave" : "Max", |
| 204 | adjusted_outgoing_rate, outgoing_speed_rating); | 203 | adjusted_outgoing_rate, outgoing_speed_rating); |
| @@ -206,7 +205,7 @@ main (int argc, char **argv) | |||
| 206 | else if (incoming_rate > incoming_warning_threshold | 205 | else if (incoming_rate > incoming_warning_threshold |
| 207 | || outgoing_rate > outgoing_warning_threshold) { | 206 | || outgoing_rate > outgoing_warning_threshold) { |
| 208 | result = STATE_WARNING; | 207 | result = STATE_WARNING; |
| 209 | sprintf (error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", | 208 | asprintf (&error_message, "%s. In = %0.1f %s, %s. Out = %0.1f %s", |
| 210 | (use_average == TRUE) ? "Ave" : "Max", adjusted_incoming_rate, | 209 | (use_average == TRUE) ? "Ave" : "Max", adjusted_incoming_rate, |
| 211 | incoming_speed_rating, (use_average == TRUE) ? "Ave" : "Max", | 210 | incoming_speed_rating, (use_average == TRUE) ? "Ave" : "Max", |
| 212 | adjusted_outgoing_rate, outgoing_speed_rating); | 211 | adjusted_outgoing_rate, outgoing_speed_rating); |
| @@ -233,68 +232,9 @@ process_arguments (int argc, char **argv) | |||
| 233 | { | 232 | { |
| 234 | int c; | 233 | int c; |
| 235 | 234 | ||
| 236 | if (argc < 2) | ||
| 237 | return ERROR; | ||
| 238 | |||
| 239 | for (c = 1; c < argc; c++) { | ||
| 240 | if (strcmp ("-to", argv[c]) == 0) | ||
| 241 | strcpy (argv[c], "-t"); | ||
| 242 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 243 | strcpy (argv[c], "-w"); | ||
| 244 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 245 | strcpy (argv[c], "-c"); | ||
| 246 | } | ||
| 247 | |||
| 248 | |||
| 249 | |||
| 250 | c = 0; | ||
| 251 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 252 | |||
| 253 | if (is_option (argv[c])) | ||
| 254 | continue; | ||
| 255 | |||
| 256 | if (log_file == NULL) { | ||
| 257 | log_file = argv[c]; | ||
| 258 | } | ||
| 259 | else if (expire_minutes == -1) { | ||
| 260 | expire_minutes = atoi (optarg); | ||
| 261 | } | ||
| 262 | else if (strcmp (argv[c], "MAX") == 0) { | ||
| 263 | use_average = FALSE; | ||
| 264 | } | ||
| 265 | else if (strcmp (argv[c], "AVG") == 0) { | ||
| 266 | use_average = TRUE; | ||
| 267 | } | ||
| 268 | else if (incoming_warning_threshold == 0) { | ||
| 269 | incoming_warning_threshold = strtoul (argv[c], NULL, 10); | ||
| 270 | } | ||
| 271 | else if (incoming_critical_threshold == 0) { | ||
| 272 | incoming_critical_threshold = strtoul (argv[c], NULL, 10); | ||
| 273 | } | ||
| 274 | else if (outgoing_warning_threshold == 0) { | ||
| 275 | outgoing_warning_threshold = strtoul (argv[c], NULL, 10); | ||
| 276 | } | ||
| 277 | else if (outgoing_critical_threshold == 0) { | ||
| 278 | outgoing_critical_threshold = strtoul (argv[c], NULL, 10); | ||
| 279 | } | ||
| 280 | } | ||
| 281 | |||
| 282 | return validate_arguments (); | ||
| 283 | } | ||
| 284 | |||
| 285 | |||
| 286 | |||
| 287 | |||
| 288 | |||
| 289 | |||
| 290 | int | ||
| 291 | call_getopt (int argc, char **argv) | ||
| 292 | { | ||
| 293 | int c, i = 0; | ||
| 294 | |||
| 295 | #ifdef HAVE_GETOPT_H | 235 | #ifdef HAVE_GETOPT_H |
| 296 | int option_index = 0; | 236 | int option_index = 0; |
| 297 | static struct option long_options[] = { | 237 | static struct option longopts[] = { |
| 298 | {"logfile", required_argument, 0, 'F'}, | 238 | {"logfile", required_argument, 0, 'F'}, |
| 299 | {"expires", required_argument, 0, 'e'}, | 239 | {"expires", required_argument, 0, 'e'}, |
| 300 | {"aggregation", required_argument, 0, 'a'}, | 240 | {"aggregation", required_argument, 0, 'a'}, |
| @@ -308,29 +248,29 @@ call_getopt (int argc, char **argv) | |||
| 308 | }; | 248 | }; |
| 309 | #endif | 249 | #endif |
| 310 | 250 | ||
| 251 | if (argc < 2) | ||
| 252 | return ERROR; | ||
| 253 | |||
| 254 | for (c = 1; c < argc; c++) { | ||
| 255 | if (strcmp ("-to", argv[c]) == 0) | ||
| 256 | strcpy (argv[c], "-t"); | ||
| 257 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 258 | strcpy (argv[c], "-w"); | ||
| 259 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 260 | strcpy (argv[c], "-c"); | ||
| 261 | } | ||
| 262 | |||
| 311 | while (1) { | 263 | while (1) { |
| 312 | #ifdef HAVE_GETOPT_H | 264 | #ifdef HAVE_GETOPT_H |
| 313 | c = | 265 | c = getopt_long (argc, argv, "hVF:e:a:c:w:", longopts, &option_index); |
| 314 | getopt_long (argc, argv, "+hVF:e:a:c:w:", long_options, &option_index); | ||
| 315 | #else | 266 | #else |
| 316 | c = getopt (argc, argv, "+hVF:e:a:c:w:"); | 267 | c = getopt (argc, argv, "hVF:e:a:c:w:"); |
| 317 | #endif | 268 | #endif |
| 318 | 269 | ||
| 319 | i++; | 270 | if (c == -1 || c == EOF) |
| 320 | |||
| 321 | if (c == -1 || c == EOF || c == 1) | ||
| 322 | break; | 271 | break; |
| 323 | 272 | ||
| 324 | switch (c) { | 273 | switch (c) { |
| 325 | case 'F': | ||
| 326 | case 'e': | ||
| 327 | case 'a': | ||
| 328 | case 'c': | ||
| 329 | case 'w': | ||
| 330 | i++; | ||
| 331 | } | ||
| 332 | |||
| 333 | switch (c) { | ||
| 334 | case 'F': /* input file */ | 274 | case 'F': /* input file */ |
| 335 | log_file = optarg; | 275 | log_file = optarg; |
| 336 | break; | 276 | break; |
| @@ -361,7 +301,42 @@ call_getopt (int argc, char **argv) | |||
| 361 | usage ("Invalid argument\n"); | 301 | usage ("Invalid argument\n"); |
| 362 | } | 302 | } |
| 363 | } | 303 | } |
| 364 | return i; | 304 | |
| 305 | c = optind; | ||
| 306 | if (argc > c && log_file == NULL) { | ||
| 307 | log_file = argv[c++]; | ||
| 308 | } | ||
| 309 | |||
| 310 | if (argc > c && expire_minutes == -1) { | ||
| 311 | expire_minutes = atoi (argv[c++]); | ||
| 312 | } | ||
| 313 | |||
| 314 | if (argc > c && strcmp (argv[c], "MAX") == 0) { | ||
| 315 | use_average = FALSE; | ||
| 316 | c++; | ||
| 317 | } | ||
| 318 | else if (argc > c && strcmp (argv[c], "AVG") == 0) { | ||
| 319 | use_average = TRUE; | ||
| 320 | c++; | ||
| 321 | } | ||
| 322 | |||
| 323 | if (argc > c && incoming_warning_threshold == 0) { | ||
| 324 | incoming_warning_threshold = strtoul (argv[c++], NULL, 10); | ||
| 325 | } | ||
| 326 | |||
| 327 | if (argc > c && incoming_critical_threshold == 0) { | ||
| 328 | incoming_critical_threshold = strtoul (argv[c++], NULL, 10); | ||
| 329 | } | ||
| 330 | |||
| 331 | if (argc > c && outgoing_warning_threshold == 0) { | ||
| 332 | outgoing_warning_threshold = strtoul (argv[c++], NULL, 10); | ||
| 333 | } | ||
| 334 | |||
| 335 | if (argc > c && outgoing_critical_threshold == 0) { | ||
| 336 | outgoing_critical_threshold = strtoul (argv[c++], NULL, 10); | ||
| 337 | } | ||
| 338 | |||
| 339 | return validate_arguments (); | ||
| 365 | } | 340 | } |
| 366 | 341 | ||
| 367 | 342 | ||
