Module: monitoring-plugins
    Branch: master
    Commit: 3c7d24478c7e79f288d4e79278168c3fe5b73a45
    Author: abrist <[email protected]>
 Committer: Jan Wagner <[email protected]>
      Date: Fri Jan 24 13:52:08 2014 -0500
       URL: 
https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=3c7d244

check_hpjd - Added a switch for port specification. Defaults to 161.

---

 plugins/check_hpjd.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/plugins/check_hpjd.c b/plugins/check_hpjd.c
index 1e7605b..1ee4d13 100644
--- a/plugins/check_hpjd.c
+++ b/plugins/check_hpjd.c
@@ -39,7 +39,7 @@ const char *email = "[email protected]";
 #include "netutils.h"
 
 #define DEFAULT_COMMUNITY "public"
-
+#define DEFAULT_PORT "161"
 
 const char *option_summary = "-H host [-C community]\n";
 
@@ -66,6 +66,7 @@ void print_usage (void);
 
 char *community = NULL;
 char *address = NULL;
+char *port = NULL;
 
 int
 main (int argc, char **argv)
@@ -119,8 +120,8 @@ main (int argc, char **argv)
                 HPJD_GD_DOOR_OPEN, HPJD_GD_PAPER_OUTPUT, 
HPJD_GD_STATUS_DISPLAY);
 
        /* get the command to run */
-       sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s %s", 
PATH_TO_SNMPGET, community,
-                                                                       
address, query_string);
+       sprintf (command_line, "%s -OQa -m : -v 1 -c %s %s:%hd %s", 
PATH_TO_SNMPGET, community,
+                                                                       
address, port, query_string);
 
        /* run the command */
        child_process = spopen (command_line);
@@ -313,7 +314,7 @@ process_arguments (int argc, char **argv)
                {"community", required_argument, 0, 'C'},
 /*             {"critical",       required_argument,0,'c'}, */
 /*             {"warning",        required_argument,0,'w'}, */
-/*             {"port",           required_argument,0,'P'}, */
+               {"port", required_argument,0,'p'}, 
                {"version", no_argument, 0, 'V'},
                {"help", no_argument, 0, 'h'},
                {0, 0, 0, 0}
@@ -324,7 +325,7 @@ process_arguments (int argc, char **argv)
 
 
        while (1) {
-               c = getopt_long (argc, argv, "+hVH:C:", longopts, &option);
+               c = getopt_long (argc, argv, "+hVH:C:p:", longopts, &option);
 
                if (c == -1 || c == EOF || c == 1)
                        break;
@@ -341,6 +342,12 @@ process_arguments (int argc, char **argv)
                case 'C':                                                       
                /* community */
                        community = strscpy (community, optarg);
                        break;
+               case 'p':
+                       if (!is_intpos(optarg))
+                               usage2 (_("Port must be a positive integer"), 
optarg);
+                       else
+                               port = atoi(optarg);
+                       break;
                case 'V':                                                       
                /* version */
                        print_revision (progname, NP_VERSION);
                        exit (STATE_OK);
@@ -369,6 +376,13 @@ process_arguments (int argc, char **argv)
                        community = strdup (DEFAULT_COMMUNITY);
        }
 
+       if (port == NULL) {
+               if (argv[c] != NULL )
+                       port = argv[c];
+               else
+                       port = atoi (DEFAULT_PORT);
+       }
+
        return validate_arguments ();
 }
 
@@ -402,6 +416,10 @@ print_help (void)
        printf ("    %s", _("The SNMP community name "));
        printf (_("(default=%s)"), DEFAULT_COMMUNITY);
        printf ("\n");
+       printf (" %s\n", "-p, --port=STRING");
+       printf ("    %s", _("Specify the port to check "));
+       printf (_("(default=%s)"), DEFAULT_PORT);
+       printf ("\n");
 
        printf (UT_SUPPORT);
 }
@@ -412,5 +430,5 @@ void
 print_usage (void)
 {
   printf ("%s\n", _("Usage:"));
-       printf ("%s -H host [-C community]\n", progname);
+       printf ("%s -H host [-C community] [-p port]\n", progname);
 }

Reply via email to