Check if network port is closed

Hi all,

I would like to monitor port 22 (ssh ) to be closed and get a warning or critial if the is a response. The standard check_tcp does have the option to classify a state when the connection is refused but still returns ok when the port is open.

Any thoughts on how to accomplish this?

For active checks such as check_tcp or check_ssh you can use negate as a wrapper to reverse the status.

negate is also located in $OMD_ROOT/lib/nagios/plugins. You can create service checks with the ruleset “Classical active and passive monitoring checks”.

2 Likes

almost there:

OMD[checkmksite]:~/lib/nagios/plugins$ ./check_ssh -4H hostname.domain.example
SSH OK - OpenSSH_7.4 (protocol 2.0) | time=0.010968s;;;0.000000;10.000000
OMD[checkmksite]:~/lib/nagios/plugins$ ./negate -s "/omd/sites/checkmksite/lib/nagios/plugins/check_ssh -4H hostname.domain.example"
SSH CRITICAL - OpenSSH_7.4 (protocol 2.0) | time=0.009139s;;;0.000000;10.000000

however if I create a classical check with command line:

/omd/sites/checkmksite/lib/nagios/plugins/negate -s "/omd/sites/checkmksite/lib/nagios/plugins/check_ssh -4H hostname.domain.example"

the check returns (Return code of 127 is out of bounds - plugin may be missing)

solved:

negate -s /omd/sites/keepmultisiteinmind/lib/nagios/plugins/check_ssh -4H host.domain.example

1 Like