check_ssh specify server port using server:port

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
beneford
Posts: 1
Joined: Fri Sep 26, 2014 6:01 am

check_ssh specify server port using server:port

Post by beneford »

I use quite a lot of non-standard ports with ssh to access various servers, and I find the server:port notation used by rsync/scp etc. more convenient than the -p port style used by ssh and (by default) nagios.
I've modified check_ssh and check_by_ssh to support this and wondered if you'd like to include it in the main build.

The change are:

Code: Select all

diff --git a/plugins/check_by_ssh.c b/plugins/check_by_ssh.c
index 1f8913c..e30f413 100644
--- a/plugins/check_by_ssh.c
+++ b/plugins/check_by_ssh.c
@@ -222,9 +222,14 @@ process_arguments (int argc, char **argv)
                                timeout_interval = atoi (optarg);
                        break;
                case 'H':                                                                       /* host */
+                       if (p1=strstr(optarg,":"))
+                               *p1=0; /* terminate the host-name */
                        host_or_die(optarg);
                        hostname = optarg;
-                       break;
+                       if (!p1)
+                               break;
+                       optarg=p1+1;    /* set port number as next param
+                       and fall thru... */
                case 'p': /* port number */
                        if (!is_integer (optarg))
                                usage_va(_("Port must be a positive integer"));

diff --git a/plugins/check_ssh.c b/plugins/check_ssh.c
index ac7a4d4..762f9fe 100644
--- a/plugins/check_ssh.c
+++ b/plugins/check_ssh.c
@@ -174,6 +174,12 @@ process_arguments (int argc, char **argv)

        c = optind;
        if (server_name == NULL && c < argc) {
+               char *p;
+               if (p=strstr(argv[c],":")) {
+                       *p=0;                   /* terminate the host-name */
+                       if (is_intpos(p+1))     /* set the port number */
+                               port=atoi(p+1);
+                       }
                if (is_host (argv[c])) {
                        server_name = argv[c++];
                }
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: check_ssh specify server port using server:port

Post by sreinhardt »

Do you have a github account, where you could submit a pull request for us? Just makes it that much easier to give you proper credit if we do include the patch. I will have to review the patch, we definitely do not want to remove -p options, but if your patch works with it without causing possible conflicts, I would be happy to include it.
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
Locked