Page 1 of 1

check_ssh specify server port using server:port

Posted: Fri Sep 26, 2014 8:27 am
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++];
                }

Re: check_ssh specify server port using server:port

Posted: Fri Sep 26, 2014 11:07 am
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.