summaryrefslogtreecommitdiffstats
path: root/plugins/check_hpjd.c
diff options
context:
space:
mode:
authorKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-11-13 11:50:54 (GMT)
committerKarl DeBisschop <kdebisschop@users.sourceforge.net>2002-11-13 11:50:54 (GMT)
commit9e009c4b1128352c6039d25b39213fd480e9b055 (patch)
treee1495ef4ada6f8e092e20bc474195719f1b2b4aa /plugins/check_hpjd.c
parent9728dcad931d1c442a6d8e3e6765e2d9870600d1 (diff)
downloadmonitoring-plugins-9e009c4b1128352c6039d25b39213fd480e9b055.tar.gz
remove call_getopt and asprintf
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@190 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/check_hpjd.c')
-rw-r--r--plugins/check_hpjd.c96
1 files changed, 34 insertions, 62 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 6d42cd3..42b4bb5 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
86int process_arguments (int, char **); 88int process_arguments (int, char **);
87int call_getopt (int, char **);
88int validate_arguments (void); 89int validate_arguments (void);
89void print_help (void); 90void print_help (void);
90void print_usage (void); 91void print_usage (void);
91 92
92char *community = NULL; 93char *community = NULL;
93char *address = NULL; 94char *address = "127.0.0.1";
95
94 96
95int 97int
96main (int argc, char **argv) 98main (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
433int
434call_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)
510void 482void
511print_help (void) 483print_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"