Monitor localhost URL

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
apteancloud
Posts: 47
Joined: Wed Sep 09, 2020 4:05 am

Re: Monitor localhost URL

Post 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
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: Monitor localhost URL

Post 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
apteancloud
Posts: 47
Joined: Wed Sep 09, 2020 4:05 am

Re: Monitor localhost URL

Post 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
You do not have the required permissions to view the files attached to this post.
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: Monitor localhost URL

Post 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
apteancloud
Posts: 47
Joined: Wed Sep 09, 2020 4:05 am

Re: Monitor localhost URL

Post 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:
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: Monitor localhost URL

Post by vtrac »

Great!! .... may I close this thread? .... :-)


Regards,
Vinh
apteancloud
Posts: 47
Joined: Wed Sep 09, 2020 4:05 am

Re: Monitor localhost URL

Post by apteancloud »

Just give me a day so that I can confirm on thread closure.
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: Monitor localhost URL

Post by vtrac »

Will do ..... :-)
apteancloud
Posts: 47
Joined: Wed Sep 09, 2020 4:05 am

Re: Monitor localhost URL

Post by apteancloud »

I realised I never responded back. Please archive this thread. Thanks again for pointing me to right direction.. :D
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Monitor localhost URL

Post 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
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked