summaryrefslogtreecommitdiffstats
path: root/plugins/check_ups.c
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/check_ups.c')
-rw-r--r--plugins/check_ups.c106
1 files changed, 39 insertions, 67 deletions
diff --git a/plugins/check_ups.c b/plugins/check_ups.c
index 1e1aa39c..c711de20 100644
--- a/plugins/check_ups.c
+++ b/plugins/check_ups.c
@@ -57,6 +57,10 @@
57#include "utils.h" 57#include "utils.h"
58 58
59#define PROGNAME "check_ups" 59#define PROGNAME "check_ups"
60#define REVISION "$Revision$"
61#define COPYRIGHT "1999-2002"
62#define AUTHOR "Ethan Galstad"
63#define EMAIL "nagios@nagios.org"
60 64
61#define CHECK_NONE 0 65#define CHECK_NONE 0
62 66
@@ -433,50 +437,6 @@ process_arguments (int argc, char **argv)
433{ 437{
434 int c; 438 int c;
435 439
436 if (argc < 2)
437 return ERROR;
438
439 for (c = 1; c < argc; c++) {
440 if (strcmp ("-to", argv[c]) == 0)
441 strcpy (argv[c], "-t");
442 else if (strcmp ("-wt", argv[c]) == 0)
443 strcpy (argv[c], "-w");
444 else if (strcmp ("-ct", argv[c]) == 0)
445 strcpy (argv[c], "-c");
446 }
447
448 c = 0;
449 while ((c += (call_getopt (argc - c, &argv[c]))) < argc) {
450
451 if (is_option (argv[c]))
452 continue;
453
454 if (server_address == NULL) {
455 if (is_host (argv[c])) {
456 server_address = argv[c];
457 }
458 else {
459 usage ("Invalid host name");
460 }
461 }
462 }
463
464 if (server_address == NULL)
465 server_address = strscpy (NULL, "127.0.0.1");
466
467 return validate_arguments ();
468}
469
470
471
472
473
474
475int
476call_getopt (int argc, char **argv)
477{
478 int c, i = 0;
479
480#ifdef HAVE_GETOPT_H 440#ifdef HAVE_GETOPT_H
481 int option_index = 0; 441 int option_index = 0;
482 static struct option long_options[] = { 442 static struct option long_options[] = {
@@ -493,40 +453,39 @@ call_getopt (int argc, char **argv)
493 }; 453 };
494#endif 454#endif
495 455
456 if (argc < 2)
457 return ERROR;
458
459 for (c = 1; c < argc; c++) {
460 if (strcmp ("-to", argv[c]) == 0)
461 strcpy (argv[c], "-t");
462 else if (strcmp ("-wt", argv[c]) == 0)
463 strcpy (argv[c], "-w");
464 else if (strcmp ("-ct", argv[c]) == 0)
465 strcpy (argv[c], "-c");
466 }
467
496 while (1) { 468 while (1) {
497#ifdef HAVE_GETOPT_H 469#ifdef HAVE_GETOPT_H
498 c = 470 c =
499 getopt_long (argc, argv, "+hVH:u:p:v:c:w:t:", long_options, 471 getopt_long (argc, argv, "hVH:u:p:v:c:w:t:", long_options,
500 &option_index); 472 &option_index);
501#else 473#else
502 c = getopt (argc, argv, "+?hVH:u:p:v:c:w:t:"); 474 c = getopt (argc, argv, "hVH:u:p:v:c:w:t:");
503#endif 475#endif
504 476
505 i++; 477 if (c == -1 || c == EOF)
506
507 if (c == -1 || c == EOF || c == 1)
508 break; 478 break;
509 479
510 switch (c) { 480 switch (c) {
511 case 'H':
512 case 'u':
513 case 'p':
514 case 'v':
515 case 'c':
516 case 'w':
517 case 't':
518 i++;
519 }
520
521 switch (c) {
522 case '?': /* help */ 481 case '?': /* help */
523 usage ("Invalid argument\n"); 482 usage3 ("Unknown option", optopt);
524 case 'H': /* hostname */ 483 case 'H': /* hostname */
525 if (is_host (optarg)) { 484 if (is_host (optarg)) {
526 server_address = optarg; 485 server_address = optarg;
527 } 486 }
528 else { 487 else {
529 usage ("Invalid host name\n"); 488 usage2 ("Invalid host name", optarg);
530 } 489 }
531 break; 490 break;
532 case 'u': /* ups name */ 491 case 'u': /* ups name */
@@ -537,7 +496,7 @@ call_getopt (int argc, char **argv)
537 server_port = atoi (optarg); 496 server_port = atoi (optarg);
538 } 497 }
539 else { 498 else {
540 usage ("Server port must be a positive integer\n"); 499 usage2 ("Server port must be a positive integer", optarg);
541 } 500 }
542 break; 501 break;
543 case 'c': /* critical time threshold */ 502 case 'c': /* critical time threshold */
@@ -546,7 +505,7 @@ call_getopt (int argc, char **argv)
546 check_critical_value = TRUE; 505 check_critical_value = TRUE;
547 } 506 }
548 else { 507 else {
549 usage ("Critical time must be a nonnegative integer\n"); 508 usage2 ("Critical time must be a nonnegative integer", optarg);
550 } 509 }
551 break; 510 break;
552 case 'w': /* warning time threshold */ 511 case 'w': /* warning time threshold */
@@ -555,7 +514,7 @@ call_getopt (int argc, char **argv)
555 check_warning_value = TRUE; 514 check_warning_value = TRUE;
556 } 515 }
557 else { 516 else {
558 usage ("Warning time must be a nonnegative integer\n"); 517 usage2 ("Warning time must be a nonnegative integer", optarg);
559 } 518 }
560 break; 519 break;
561 case 'v': /* variable */ 520 case 'v': /* variable */
@@ -568,7 +527,7 @@ call_getopt (int argc, char **argv)
568 else if (!strcmp (optarg, "LOADPCT")) 527 else if (!strcmp (optarg, "LOADPCT"))
569 check_variable = UPS_LOADPCT; 528 check_variable = UPS_LOADPCT;
570 else 529 else
571 usage ("Unrecognized UPS variable\n"); 530 usage2 ("Unrecognized UPS variable", optarg);
572 break; 531 break;
573 case 't': /* timeout */ 532 case 't': /* timeout */
574 if (is_intnonneg (optarg)) { 533 if (is_intnonneg (optarg)) {
@@ -586,7 +545,20 @@ call_getopt (int argc, char **argv)
586 exit (STATE_OK); 545 exit (STATE_OK);
587 } 546 }
588 } 547 }
589 return i; 548
549
550 if (server_address == NULL) {
551 if (optind >= argc) {
552 server_address = strscpy (NULL, "127.0.0.1");
553 }
554 else if (is_host (argv[optind])) {
555 server_address = argv[optind++];
556 }
557 else {
558 usage ("Invalid host name");
559 }
560 }
561 return validate_arguments();
590} 562}
591 563
592 564