diff options
author | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-09 11:37:14 +0000 |
---|---|---|
committer | Karl DeBisschop <kdebisschop@users.sourceforge.net> | 2002-11-09 11:37:14 +0000 |
commit | 938d0d68daecf2a4d45b9e39d191259b63304bd2 (patch) | |
tree | 516608b265259b56245ff4d6126f68a98fe4c11e /plugins | |
parent | 6fa04c4a4954c34bd212a0f383fd1337d29a6cde (diff) | |
download | monitoring-plugins-938d0d68daecf2a4d45b9e39d191259b63304bd2.tar.gz |
remove call_getopt
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@182 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/check_ups.c | 106 | ||||
-rw-r--r-- | plugins/check_users.c | 74 |
2 files changed, 65 insertions, 115 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 | |||
475 | int | ||
476 | call_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 | ||
diff --git a/plugins/check_users.c b/plugins/check_users.c index 2b8fa15b..e39e0d2b 100644 --- a/plugins/check_users.c +++ b/plugins/check_users.c | |||
@@ -49,11 +49,14 @@ | |||
49 | #include "utils.h" | 49 | #include "utils.h" |
50 | 50 | ||
51 | #define PROGNAME "check_users" | 51 | #define PROGNAME "check_users" |
52 | #define REVISION "$Revision$" | ||
53 | #define COPYRIGHT "1999-2002" | ||
54 | #define AUTHOR "Ethan Galstad" | ||
55 | #define EMAIL "nagios@nagios.org" | ||
52 | 56 | ||
53 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) | 57 | #define possibly_set(a,b) ((a) == 0 ? (b) : 0) |
54 | 58 | ||
55 | int process_arguments (int, char **); | 59 | int process_arguments (int, char **); |
56 | int call_getopt (int, char **); | ||
57 | void print_usage (void); | 60 | void print_usage (void); |
58 | void print_help (void); | 61 | void print_help (void); |
59 | 62 | ||
@@ -133,40 +136,6 @@ process_arguments (int argc, char **argv) | |||
133 | { | 136 | { |
134 | int c; | 137 | int c; |
135 | 138 | ||
136 | if (argc < 2) | ||
137 | usage ("\n"); | ||
138 | |||
139 | c = 0; | ||
140 | while ((c += call_getopt (argc - c, &argv[c])) < argc) { | ||
141 | |||
142 | if (is_option (argv[c])) | ||
143 | continue; | ||
144 | |||
145 | if (wusers == -1 && argc > c) { | ||
146 | if (is_intnonneg (argv[c]) == FALSE) | ||
147 | usage ("Warning threshold must be a nonnegative integer\n"); | ||
148 | wusers = atoi (argv[c]); | ||
149 | |||
150 | } | ||
151 | else if (cusers == -1 && argc > c) { | ||
152 | if (is_intnonneg (argv[c]) == FALSE) | ||
153 | usage ("Warning threshold must be a nonnegative integer\n"); | ||
154 | cusers = atoi (argv[c]); | ||
155 | } | ||
156 | } | ||
157 | |||
158 | return OK; | ||
159 | } | ||
160 | |||
161 | |||
162 | |||
163 | |||
164 | |||
165 | int | ||
166 | call_getopt (int argc, char **argv) | ||
167 | { | ||
168 | int c, i = 0; | ||
169 | |||
170 | #ifdef HAVE_GETOPT_H | 139 | #ifdef HAVE_GETOPT_H |
171 | int option_index = 0; | 140 | int option_index = 0; |
172 | static struct option long_options[] = { | 141 | static struct option long_options[] = { |
@@ -178,6 +147,9 @@ call_getopt (int argc, char **argv) | |||
178 | }; | 147 | }; |
179 | #endif | 148 | #endif |
180 | 149 | ||
150 | if (argc < 2) | ||
151 | usage ("\n"); | ||
152 | |||
181 | while (1) { | 153 | while (1) { |
182 | #ifdef HAVE_GETOPT_H | 154 | #ifdef HAVE_GETOPT_H |
183 | c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index); | 155 | c = getopt_long (argc, argv, "+hVvc:w:", long_options, &option_index); |
@@ -185,27 +157,19 @@ call_getopt (int argc, char **argv) | |||
185 | c = getopt (argc, argv, "+hVvc:w:"); | 157 | c = getopt (argc, argv, "+hVvc:w:"); |
186 | #endif | 158 | #endif |
187 | 159 | ||
188 | i++; | ||
189 | |||
190 | if (c == -1 || c == EOF || c == 1) | 160 | if (c == -1 || c == EOF || c == 1) |
191 | break; | 161 | break; |
192 | 162 | ||
193 | switch (c) { | 163 | switch (c) { |
194 | case 'c': | ||
195 | case 'w': | ||
196 | i++; | ||
197 | } | ||
198 | |||
199 | switch (c) { | ||
200 | case '?': /* print short usage statement if args not parsable */ | 164 | case '?': /* print short usage statement if args not parsable */ |
201 | printf ("%s: Unknown argument: %s\n\n", my_basename (argv[0]), optarg); | 165 | printf ("%s: Unknown argument: %s\n\n", PROGNAME, optarg); |
202 | print_usage (); | 166 | print_usage (); |
203 | exit (STATE_UNKNOWN); | 167 | exit (STATE_UNKNOWN); |
204 | case 'h': /* help */ | 168 | case 'h': /* help */ |
205 | print_help (); | 169 | print_help (); |
206 | exit (STATE_OK); | 170 | exit (STATE_OK); |
207 | case 'V': /* version */ | 171 | case 'V': /* version */ |
208 | print_revision (my_basename (argv[0]), "$Revision$"); | 172 | print_revision (PROGNAME, REVISION); |
209 | exit (STATE_OK); | 173 | exit (STATE_OK); |
210 | case 'c': /* critical */ | 174 | case 'c': /* critical */ |
211 | if (!is_intnonneg (optarg)) | 175 | if (!is_intnonneg (optarg)) |
@@ -219,7 +183,21 @@ call_getopt (int argc, char **argv) | |||
219 | break; | 183 | break; |
220 | } | 184 | } |
221 | } | 185 | } |
222 | return i; | 186 | |
187 | c = optind; | ||
188 | if (wusers == -1 && argc > c) { | ||
189 | if (is_intnonneg (argv[c]) == FALSE) | ||
190 | usage ("Warning threshold must be a nonnegative integer\n"); | ||
191 | wusers = atoi (argv[c++]); | ||
192 | } | ||
193 | |||
194 | if (cusers == -1 && argc > c) { | ||
195 | if (is_intnonneg (argv[c]) == FALSE) | ||
196 | usage ("Warning threshold must be a nonnegative integer\n"); | ||
197 | cusers = atoi (argv[c]); | ||
198 | } | ||
199 | |||
200 | return OK; | ||
223 | } | 201 | } |
224 | 202 | ||
225 | 203 | ||
@@ -239,9 +217,9 @@ print_usage (void) | |||
239 | void | 217 | void |
240 | print_help (void) | 218 | print_help (void) |
241 | { | 219 | { |
242 | print_revision (PROGNAME, "$Revision$"); | 220 | print_revision (PROGNAME, REVISION); |
243 | printf | 221 | printf |
244 | ("Copyright (c) 1999 Ethan Galstad (nagios@nagios.org)\n\n" | 222 | ("Copyright (c) " COPYRIGHT " " AUTHOR "(" EMAIL ")\n\n" |
245 | "This plugin checks the number of users currently logged in on the local\n" | 223 | "This plugin checks the number of users currently logged in on the local\n" |
246 | "system and generates an error if the number exceeds the thresholds specified.\n"); | 224 | "system and generates an error if the number exceeds the thresholds specified.\n"); |
247 | print_usage (); | 225 | print_usage (); |