aboutsummaryrefslogtreecommitdiff
path: root/plugins
diff options
context:
space:
mode:
authorGravatar abrist <abrist@nagios.com> 2014-01-24 13:52:08 -0500
committerGravatar Jan Wagner <waja@cyconet.org> 2014-07-20 23:35:41 +0200
commit3c7d24478c7e79f288d4e79278168c3fe5b73a45 (patch)
tree3030ec1dd806f766282b5121e8d2f5c17ab3bd2a /plugins
parent78d00d338a07ab0dd5ff052af96aab13a5ee93ae (diff)
downloadmonitoring-plugins-3c7d24478c7e79f288d4e79278168c3fe5b73a45.tar.gz
check_hpjd - Added a switch for port specification. Defaults to 161.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/check_hpjd.c30
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";
#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);
}