diff options
Diffstat (limited to 'plugins/check_hpjd.c')
| -rw-r--r-- | plugins/check_hpjd.c | 96 |
1 files changed, 34 insertions, 62 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 6d42cd38..42b4bb54 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
| @@ -66,6 +66,8 @@ | |||
| 66 | #include "utils.h" | 66 | #include "utils.h" |
| 67 | 67 | ||
| 68 | #define PROGNAME "check_hpjd" | 68 | #define PROGNAME "check_hpjd" |
| 69 | #define REVISION "$Revision$" | ||
| 70 | #define COPYRIGHT "2000-2002" | ||
| 69 | 71 | ||
| 70 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" | 72 | #define HPJD_LINE_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.1" |
| 71 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" | 73 | #define HPJD_PAPER_STATUS ".1.3.6.1.4.1.11.2.3.9.1.1.2.2" |
| @@ -84,13 +86,13 @@ | |||
| 84 | #define OFFLINE 1 | 86 | #define OFFLINE 1 |
| 85 | 87 | ||
| 86 | int process_arguments (int, char **); | 88 | int process_arguments (int, char **); |
| 87 | int call_getopt (int, char **); | ||
| 88 | int validate_arguments (void); | 89 | int validate_arguments (void); |
| 89 | void print_help (void); | 90 | void print_help (void); |
| 90 | void print_usage (void); | 91 | void print_usage (void); |
| 91 | 92 | ||
| 92 | char *community = NULL; | 93 | char *community = NULL; |
| 93 | char *address = NULL; | 94 | char *address = "127.0.0.1"; |
| 95 | |||
| 94 | 96 | ||
| 95 | int | 97 | int |
| 96 | main (int argc, char **argv) | 98 | main (int argc, char **argv) |
| @@ -386,55 +388,6 @@ process_arguments (int argc, char **argv) | |||
| 386 | { | 388 | { |
| 387 | int c; | 389 | int c; |
| 388 | 390 | ||
| 389 | if (argc < 2) | ||
| 390 | return ERROR; | ||
| 391 | |||
| 392 | for (c = 1; c < argc; c++) { | ||
| 393 | if (strcmp ("-to", argv[c]) == 0) | ||
| 394 | strcpy (argv[c], "-t"); | ||
| 395 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 396 | strcpy (argv[c], "-w"); | ||
| 397 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 398 | strcpy (argv[c], "-c"); | ||
| 399 | } | ||
| 400 | |||
| 401 | |||
| 402 | |||
| 403 | c = 0; | ||
| 404 | while ((c += (call_getopt (argc - c, &argv[c]))) < argc) { | ||
| 405 | |||
| 406 | if (is_option (argv[c])) | ||
| 407 | continue; | ||
| 408 | |||
| 409 | if (address == NULL) { | ||
| 410 | if (is_host (argv[c])) { | ||
| 411 | address = argv[c]; | ||
| 412 | } | ||
| 413 | else { | ||
| 414 | usage ("Invalid host name"); | ||
| 415 | } | ||
| 416 | } | ||
| 417 | else if (community == NULL) { | ||
| 418 | community = argv[c]; | ||
| 419 | } | ||
| 420 | } | ||
| 421 | |||
| 422 | if (address == NULL) | ||
| 423 | address = strscpy (NULL, "127.0.0.1"); | ||
| 424 | |||
| 425 | return validate_arguments (); | ||
| 426 | } | ||
| 427 | |||
| 428 | |||
| 429 | |||
| 430 | |||
| 431 | |||
| 432 | |||
| 433 | int | ||
| 434 | call_getopt (int argc, char **argv) | ||
| 435 | { | ||
| 436 | int c, i = 0; | ||
| 437 | |||
| 438 | #ifdef HAVE_GETOPT_H | 391 | #ifdef HAVE_GETOPT_H |
| 439 | int option_index = 0; | 392 | int option_index = 0; |
| 440 | static struct option long_options[] = { | 393 | static struct option long_options[] = { |
| @@ -450,6 +403,18 @@ call_getopt (int argc, char **argv) | |||
| 450 | }; | 403 | }; |
| 451 | #endif | 404 | #endif |
| 452 | 405 | ||
| 406 | if (argc < 2) | ||
| 407 | return ERROR; | ||
| 408 | |||
| 409 | for (c = 1; c < argc; c++) { | ||
| 410 | if (strcmp ("-to", argv[c]) == 0) | ||
| 411 | strcpy (argv[c], "-t"); | ||
| 412 | else if (strcmp ("-wt", argv[c]) == 0) | ||
| 413 | strcpy (argv[c], "-w"); | ||
| 414 | else if (strcmp ("-ct", argv[c]) == 0) | ||
| 415 | strcpy (argv[c], "-c"); | ||
| 416 | } | ||
| 417 | |||
| 453 | while (1) { | 418 | while (1) { |
| 454 | #ifdef HAVE_GETOPT_H | 419 | #ifdef HAVE_GETOPT_H |
| 455 | c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index); | 420 | c = getopt_long (argc, argv, "+hVH:C:", long_options, &option_index); |
| @@ -457,18 +422,10 @@ call_getopt (int argc, char **argv) | |||
| 457 | c = getopt (argc, argv, "+?hVH:C:"); | 422 | c = getopt (argc, argv, "+?hVH:C:"); |
| 458 | #endif | 423 | #endif |
| 459 | 424 | ||
| 460 | i++; | ||
| 461 | |||
| 462 | if (c == -1 || c == EOF || c == 1) | 425 | if (c == -1 || c == EOF || c == 1) |
| 463 | break; | 426 | break; |
| 464 | 427 | ||
| 465 | switch (c) { | 428 | switch (c) { |
| 466 | case 'H': | ||
| 467 | case 'C': | ||
| 468 | i++; | ||
| 469 | } | ||
| 470 | |||
| 471 | switch (c) { | ||
| 472 | case 'H': /* hostname */ | 429 | case 'H': /* hostname */ |
| 473 | if (is_host (optarg)) { | 430 | if (is_host (optarg)) { |
| 474 | address = optarg; | 431 | address = optarg; |
| @@ -481,7 +438,7 @@ call_getopt (int argc, char **argv) | |||
| 481 | community = optarg; | 438 | community = optarg; |
| 482 | break; | 439 | break; |
| 483 | case 'V': /* version */ | 440 | case 'V': /* version */ |
| 484 | print_revision (PROGNAME, "$Revision$"); | 441 | print_revision (PROGNAME, REVISION); |
| 485 | exit (STATE_OK); | 442 | exit (STATE_OK); |
| 486 | case 'h': /* help */ | 443 | case 'h': /* help */ |
| 487 | print_help (); | 444 | print_help (); |
| @@ -490,7 +447,22 @@ call_getopt (int argc, char **argv) | |||
| 490 | usage ("Invalid argument\n"); | 447 | usage ("Invalid argument\n"); |
| 491 | } | 448 | } |
| 492 | } | 449 | } |
| 493 | return i; | 450 | |
| 451 | c = optind; | ||
| 452 | if (address == NULL) { | ||
| 453 | if (is_host (argv[c])) { | ||
| 454 | address = argv[c++]; | ||
| 455 | } | ||
| 456 | else { | ||
| 457 | usage ("Invalid host name"); | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | if (community == NULL) { | ||
| 462 | community = argv[c++]; | ||
| 463 | } | ||
| 464 | |||
| 465 | return validate_arguments (); | ||
| 494 | } | 466 | } |
| 495 | 467 | ||
| 496 | 468 | ||
| @@ -510,7 +482,7 @@ validate_arguments (void) | |||
| 510 | void | 482 | void |
| 511 | print_help (void) | 483 | print_help (void) |
| 512 | { | 484 | { |
| 513 | print_revision (PROGNAME, "$Revision$"); | 485 | print_revision (PROGNAME, REVISION); |
| 514 | printf | 486 | printf |
| 515 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" | 487 | ("Copyright (c) 2000 Ethan Galstad/Karl DeBisschop\n\n" |
| 516 | "This plugin tests the STATUS of an HP printer with a JetDirect card.\n" | 488 | "This plugin tests the STATUS of an HP printer with a JetDirect card.\n" |
