Power Shell to Monitor port 22

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Younes.khabchaouy
Posts: 2
Joined: Fri Feb 09, 2018 11:42 am

Power Shell to Monitor port 22

Post 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
}
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Power Shell to Monitor port 22

Post 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
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Younes.khabchaouy
Posts: 2
Joined: Fri Feb 09, 2018 11:42 am

Re: Power Shell to Monitor port 22

Post 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
User avatar
cdienger
Support Tech
Posts: 5045
Joined: Tue Feb 07, 2017 11:26 am

Re: Power Shell to Monitor port 22

Post by cdienger »

Glad to help!
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.
Locked