I have one powershell script to check the URL status. I am able to monitor it from Nagios. The issue is,, I am getting OK status even if the site is not working.
Could you please help me with the same? Below is the code:
Code: Select all
[string] $_URL = 'http://www.chalhoubgroup.com'
function CheckSiteURLStatus($_URL) {
try {
$request= [System.Net.WebRequest]::Create($_URL)
$response = $request.getResponse()
if ($response.StatusCode -eq "200") {
write-host "`nSite - $_URL is up (Return code: $($response.StatusCode) - $([int] $response.StatusCode)) `n" -ForegroundColor green
}
else {
write-host "`n Site - $_URL is down `n" ` -ForegroundColor red
}
} catch {
write-host "`n Site - $_URL is not accessable.`n" ` -ForegroundColor red
}
}
CheckSiteURLStatus $_URL
===========
Below is the command I am executing:
[root@HO1-NAGIOSXI libexec]# /usr/local/nagios/libexec/check_ncpa.py -H 10.1.0.29 -t '[email protected]' -M 'plugins/check_RSO.ps1'
Site is not accessable.