0

My linux box uses a nonstandard port for ssh. Nagios' check_ssh (of course) keeps marking the process as critical since it can't connect on that port. The object file localhost.cfg allows for parameters to be passed to check_ssh.

The documentation uses the example of:

for ...

/usr/local/nagios/libexec/check_ping -H 192.168.1.2 -w 100.0,90% -c 200.0,60%

...use:

define service{
    host_name       linuxbox
    service_description PING
    check_command   check_ping!200.0,80%!400.0,40%
    ...
    }  

However, it doesn't describe in which order to pass parameters. In my localhost.cfg I have tried:

check_ssh!xxx22!localhost

and

check_ssh!4!10!OpenSSH_6.7p1!!xxx22!localhost

...where xxx22 is the actual port. But it doesn't identify that as the port.

Looking at the check_ssh man page doesn't seem to indicate in what order to place these switches...

The check_ssh Plugin


    check_ssh v2.2.1.git (nagios-plugins 2.2.1)
    Copyright (c) 1999 Remi Paulmier <remi@sinfomic.fr>
    Copyright (c) 2000-2014 Nagios Plugin Development Team
        <devel@nagios-plugins.org>

    Try to connect to an SSH server at specified server and port


    Usage:
    check_ssh  [-4|-6] [-t <timeout>] [-r <remote version>] [-p <port>] <host>

    Options:
     -h, --help
        Print detailed help screen
     -V, --version
        Print version information
     --extra-opts=[section][@file]
        Read options from an ini file. See
        https://www.nagios-plugins.org/doc/extra-opts.html
        for usage and examples.
     -H, --hostname=ADDRESS
        Host name, IP Address, or unix socket (must be an absolute path)
     -p, --port=INTEGER
        Port number (default: 22)
     -4, --use-ipv4
        Use IPv4 connection
     -6, --use-ipv6
        Use IPv6 connection
     -t, --timeout=INTEGER:<timeout state>
        Seconds before connection times out (default: 10)
        Optional ":<timeout state>" can be a state integer (0,1,2,3) or a state STRING
     -r, --remote-version=STRING
        Alert if string doesn't match expected server version (ex: OpenSSH_3.9p1)
     -P, --remote-protocol=STRING
        Alert if protocol doesn't match expected protocol version (ex: 2.0)
     -v, --verbose
        Show details for command-line debugging (Nagios may truncate output)

    Send email to help@nagios-plugins.org if you have questions regarding use
    of this software. To submit patches or suggest improvements, send email to
    devel@nagios-plugins.org
1

You can define a command and use that command for your service.

define command{
  command_name check_ssh_2222
  command_line /usr/lib/nagios/plugins/check_ssh -p 2222 $ARG1
}

And then for your service:

check_command   check_ssh_2222
  • Thanks for the post. I tried that as well, but ran into a different issue. Maybe you could look there and get credit for the answer if you have ideas. Thx. https://unix.stackexchange.com/questions/457409/nagios-failing-restart-with-new-service-directove-in-localhost-cfg – BurningKrome Jul 20 '18 at 10:15
0

My /etc/nagios/objects/commands.cfg states

define command{
    command_name    check_ping
    command_line    $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
    }

which defines the arguments in between the exclamation marks as in the documentation example you gave. It also tells us that

define command{
        command_name    check_ssh
        command_line    $USER1$/check_ssh $ARG1$ $HOSTADDRESS$
        }

I think that your entry should be

check_ssh!--port=xxx22

since there is no predefined argument to specify the port, like --port=$ARG1$ in the definition, but only a generic place holder.

Edit: I think the localhost should not be part of the check_ssh!... line, since nagios will substitute $HOSTADDRESS$ for the appropriate hosts ip/name.

  • Thanks for that. I put in ` check_ssh!--host=localhost!--port=xxx22` and nagios will start with service nagios restart. But it still reports the starts (via web interface) as "unknown". – BurningKrome Jul 20 '18 at 9:59
  • P.s. at the command line ./check_ssh --host localhost --port xxx22 responds with ./check_ssh --host localhost --port 32122 SSH OK - OpenSSH_6.7p1 Debian-5+deb8u4 (protocol 2.0) | time=0.007549s;;;0.000000;10.000000 ... so it appears the check_ssh parameters themselves are OK...? – BurningKrome Jul 20 '18 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.