Page 2 of 2

Re: Monitor localhost URL

Posted: Mon May 17, 2021 7:58 am
by apteancloud
From NagiosXI Server:

Code: Select all

CHS_Admin@NagiosXIAzPrd:~$ curl -k -L -vvv "http://10.179.3.25:51011/api/status"
*   Trying 10.179.3.25...
* TCP_NODELAY set
* connect to 10.179.3.25 port 51011 failed: Connection refused
* Failed to connect to 10.179.3.25 port 51011: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 10.179.3.25 port 51011: Connection refused

Re: Monitor localhost URL

Posted: Mon May 17, 2021 11:58 am
by vtrac
Hi,
Hope you are having a good day!!
Since you do have NSClient++ installed on that "local" url machine, looks like your only choice is to write your own PS1 script, let call it "check_localurl.ps1".

put that under:

Code: Select all

C:\Program Files\NSClient++\scripts\
Now, edit the "nsclient.ini" by follow the step in the URL below:
https://docs.nsclient.org/howto/external_scripts/

You can use "chek_nrpe" to calls "check_localurl.ps1":

Code: Select all

/usr/local/nagios/libexec/check_nrpe -2 -H x.x.x.x  -c check_localurl
Best Regards,
Vinh

Re: Monitor localhost URL

Posted: Tue May 18, 2021 6:57 am
by apteancloud
I have set the PS script as:

Code: Select all

((Invoke-WebRequest http://server.local:51011/api/status -UseBasicParsing).Content |ConvertFrom-Json).status
Output: Started
At nsclient.ini, under [/settings/external scripts/scripts]:

Code: Select all

ssm_output_ps1 = cmd /c echo scripts\SSMoutput.ps1; exit($lastexitcode) | powershell.exe -command -
On NagiosXI, I get this output:
Capture.JPG
Now, this is good. However, what happens when the status changes to 'Stopped'. How do I ensure Nagios changes to CRITICAL when the status is anything other than 'Started'?

This is what I see at NagiosXI
Capture1.JPG
Capture2.JPG

Re: Monitor localhost URL

Posted: Tue May 18, 2021 9:44 am
by vtrac
Hi,
How are you doing?

Instead of a command line (like what you did), please put that into a PowerShell script.

I am NOT a PowerShell programmer, but here's my thought:

Code: Select all

$a1 = ((Invoke-WebRequest http://server.local:51011/api/status -UseBasicParsing).Content |ConvertFrom-Json).status

if ($a1 -eq "Started") { exit 0 }
else  { exit 2 }
Exit Status:
0 = OK
1 = Warning
2 = Critical

Best Regards,
Vinh

Re: Monitor localhost URL

Posted: Tue May 18, 2021 10:41 am
by apteancloud
Made it!

You are correct to input the exit code and that did the trick. For exit 2, Nagios turns CRITICAL. For exit 0, Nagios turns OK.
Thank you very much. :ugeek:

Re: Monitor localhost URL

Posted: Tue May 18, 2021 10:54 am
by vtrac
Great!! .... may I close this thread? .... :-)


Regards,
Vinh

Re: Monitor localhost URL

Posted: Tue May 18, 2021 11:20 am
by apteancloud
Just give me a day so that I can confirm on thread closure.

Re: Monitor localhost URL

Posted: Tue May 18, 2021 11:37 am
by vtrac
Will do ..... :-)

Re: Monitor localhost URL

Posted: Tue Jun 08, 2021 8:41 pm
by apteancloud
I realised I never responded back. Please archive this thread. Thanks again for pointing me to right direction.. :D

Re: Monitor localhost URL

Posted: Wed Jun 09, 2021 7:11 am
by scottwilkerson
apteancloud wrote:I realised I never responded back. Please archive this thread. Thanks again for pointing me to right direction.. :D
Locking thread