Page 1 of 1

Power Shell to Monitor port 22

Posted: Fri Jan 24, 2020 3:01 pm
by Younes.khabchaouy
Power Shell to Monitor port 22

I have windows server that has connection to external Linux machine port 22 and I would like to monitor this connection.
I did find this Powershell script but Nagios Server we page status for this script is always warning (yellow).
Can you please help

returnStateOK = 1
$returnStateCritical = 0
$Ipaddress= 'x.x.x.x'
$Port= '22'

$t = New-Object Net.Sockets.TcpClient
$t.Connect($Ipaddress,$Port)
if($t.Connected)
{
Write-Host "OK"
exit $returnStateOK
}else
{
Write-Host "Port $'Not OK' "
exit $returnStateCritical
}

Re: Power Shell to Monitor port 22

Posted: Fri Jan 24, 2020 4:24 pm
by cdienger
You'll need to change these lines:
returnStateOK = 1
$returnStateCritical = 0
Nagios considers a return code of 1 as a WARNING. OK is 0, WARNING is 1, CRITICAL is 2, and UNKNOWN is 3.

https://assets.nagios.com/downloads/nag ... inapi.html

Re: Power Shell to Monitor port 22

Posted: Mon Jan 27, 2020 10:30 am
by Younes.khabchaouy
Hello
Thank You for you answer. The change works for me
returnStateOK = 0
$returnStateCritical = 2

Plugin Return Code Service State Host State
0 OK UP
1 WARNING UP or DOWN/UNREACHABLE*
2 CRITICAL DOWN/UNREACHABLE
3 UNKNOWN DOWN/UNREACHABLE


Thank You for your kind support

Re: Power Shell to Monitor port 22

Posted: Mon Jan 27, 2020 10:54 am
by cdienger
Glad to help!