Page 1 of 1

Status issue

Posted: Wed Mar 31, 2021 7:28 am
by kalyanpabolu
Hello,

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.

Re: Status issue

Posted: Wed Mar 31, 2021 11:01 am
by dchurch
Try adding exit 0 for OK, exit 1 for a warning, and exit 2 to indicate a critical.

e.g.

Code: Select all

...
write-host "`n Site - $_URL is not accessable.`n" ` -ForegroundColor red
exit 2

Re: Status issue

Posted: Thu Apr 01, 2021 8:50 am
by kalyanpabolu
Hello,

Thanks a lot!!
It worked.

Re: Status issue

Posted: Thu Apr 01, 2021 9:05 am
by scottwilkerson
kalyanpabolu wrote:Hello,

Thanks a lot!!
It worked.
Great!

Locking thread