diff options
Diffstat (limited to 'plugins/check_hpjd.c')
-rw-r--r-- | plugins/check_hpjd.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c index 1e7605ba..1ee4d134 100644 --- a/plugins/check_hpjd.c +++ b/plugins/check_hpjd.c | |||
@@ -39,7 +39,7 @@ const char *email = "devel@monitoring-plugins.org"; | |||
39 | #include "netutils.h" | 39 | #include "netutils.h" |
40 | 40 | ||
41 | #define DEFAULT_COMMUNITY "public" | 41 | #define DEFAULT_COMMUNITY "public" |
42 | 42 | #define DEFAULT_PORT "161" | |
43 | 43 | ||
44 | const char *option_summary = "-H host [-C community]\n"; | 44 | const char *option_summary = "-H host [-C community]\n"; |
45 | 45 | ||
@@ -66,6 +66,7 @@ void print_usage (void); | |||
66 | 66 | ||
67 | char *community = NULL; | 67 | char *community = NULL; |
68 | char *address = NULL; | 68 | char *address = NULL; |
69 | char *port = NULL; | ||
69 | 70 | ||
70 | int | 71 | int |
71 | main (int argc, char **argv) | 72 | main (int argc, char **argv) |
@@ -119,8 +120,8 @@ main (int argc, char **argv) | |||
119 | HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); | 120 | HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, HPJD_GD_STATUS_DISPLAY); |
120 | 121 | ||
121 | /* get the command to run */ | 122 | /* get the command to run */ |
122 | sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s %s", PATH_TO_SNMPGET, community, | 123 | sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%hd %s", PATH_TO_SNMPGET, community, |
123 | address, query_string); | 124 | address, port, query_string); |
124 | 125 | ||
125 | /* run the command */ | 126 | /* run the command */ |
126 | child_process = spopen (command_line); | 127 | child_process = spopen (command_line); |
@@ -313,7 +314,7 @@ process_arguments (int argc, char **argv) | |||
313 | {"community", required_argument, 0, 'C'}, | 314 | {"community", required_argument, 0, 'C'}, |
314 | /* {"critical", required_argument,0,'c'}, */ | 315 | /* {"critical", required_argument,0,'c'}, */ |
315 | /* {"warning", required_argument,0,'w'}, */ | 316 | /* {"warning", required_argument,0,'w'}, */ |
316 | /* {"port", required_argument,0,'P'}, */ | 317 | {"port", required_argument,0,'p'}, |
317 | {"version", no_argument, 0, 'V'}, | 318 | {"version", no_argument, 0, 'V'}, |
318 | {"help", no_argument, 0, 'h'}, | 319 | {"help", no_argument, 0, 'h'}, |
319 | {0, 0, 0, 0} | 320 | {0, 0, 0, 0} |
@@ -324,7 +325,7 @@ process_arguments (int argc, char **argv) | |||
324 | 325 | ||
325 | 326 | ||
326 | while (1) { | 327 | while (1) { |
327 | c = getopt_long (argc, argv, "+hVH:C:", longopts, &option); | 328 | c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option); |
328 | 329 | ||
329 | if (c == -1 || c == EOF || c == 1) | 330 | if (c == -1 || c == EOF || c == 1) |
330 | break; | 331 | break; |
@@ -341,6 +342,12 @@ process_arguments (int argc, char **argv) | |||
341 | case 'C': /* community */ | 342 | case 'C': /* community */ |
342 | community = strscpy (community, optarg); | 343 | community = strscpy (community, optarg); |
343 | break; | 344 | break; |
345 | case 'p': | ||
346 | if (!is_intpos(optarg)) | ||
347 | usage2 (_("Port must be a positive integer"), optarg); | ||
348 | else | ||
349 | port = atoi(optarg); | ||
350 | break; | ||
344 | case 'V': /* version */ | 351 | case 'V': /* version */ |
345 | print_revision (progname, NP_VERSION); | 352 | print_revision (progname, NP_VERSION); |
346 | exit (STATE_OK); | 353 | exit (STATE_OK); |
@@ -369,6 +376,13 @@ process_arguments (int argc, char **argv) | |||
369 | community = strdup (DEFAULT_COMMUNITY); | 376 | community = strdup (DEFAULT_COMMUNITY); |
370 | } | 377 | } |
371 | 378 | ||
379 | if (port == NULL) { | ||
380 | if (argv[c] != NULL ) | ||
381 | port = argv[c]; | ||
382 | else | ||
383 | port = atoi (DEFAULT_PORT); | ||
384 | } | ||
385 | |||
372 | return validate_arguments (); | 386 | return validate_arguments (); |
373 | } | 387 | } |
374 | 388 | ||
@@ -402,6 +416,10 @@ print_help (void) | |||
402 | printf (" %s", _("The SNMP community name ")); | 416 | printf (" %s", _("The SNMP community name ")); |
403 | printf (_("(default=%s)"), DEFAULT_COMMUNITY); | 417 | printf (_("(default=%s)"), DEFAULT_COMMUNITY); |
404 | printf ("\n"); | 418 | printf ("\n"); |
419 | printf (" %s\n", "-p, --port=STRING"); | ||
420 | printf (" %s", _("Specify the port to check ")); | ||
421 | printf (_("(default=%s)"), DEFAULT_PORT); | ||
422 | printf ("\n"); | ||
405 | 423 | ||
406 | printf (UT_SUPPORT); | 424 | printf (UT_SUPPORT); |
407 | } | 425 | } |
@@ -412,5 +430,5 @@ void | |||
412 | print_usage (void) | 430 | print_usage (void) |
413 | { | 431 | { |
414 | printf ("%s\n", _("Usage:")); | 432 | printf ("%s\n", _("Usage:")); |
415 | printf ("%s -H host [-C community]\n", progname); | 433 | printf ("%s -H host [-C community] [-p port]\n", progname); |
416 | } | 434 | } |