Customizing Nagios to send http notifications

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Customizing Nagios to send http notifications

Post by bunker »

I am new to Nagios and can't find any help on customizing Nagios to send HTTP notifications like on address: http://192.45.78.66:2434/things. Is it possible in Nagios and if yes then how?

Actually I am trying to monitor my service and want it to send me an http notification if Rps increases from a certain threshold.
I have just decided to use Nagios, and asked this question several times on other forums including this, but no success uptil now. Please help!!! :?: :(

Thanks
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Customizing Nagios to send http notifications

Post by rkennedy »

Do you have a custom built API that will handle the notifications? This should work fine as long as you do, you'll just need to create a command to handle the notifications though. Take a look at these notify commands for examples of how the macro's work for our standard notify commands.

Code: Select all

[root@suse11 etc]# cat commands.cfg |grep printf
       command_line                             /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
       command_line                             /usr/bin/printf "%b" "***** Nagios Monitor XI Alert *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
[root@suse11 etc]#
For a full list of macros, see this link - https://assets.nagios.com/downloads/nag ... olist.html

You'll need to create a curl/wget string to get/post the information on your web page.
Former Nagios Employee
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Customizing Nagios to send http notifications

Post by bwallace »

You can use the check_http plugin for this.

https://assets.nagios.com/downloads/nag ... vices.html - see 'Monitoring HTTP' section

Here is the man page for this plugin:
http://nagios-plugins.org/doc/man/check_http.html


Note that check_http requires separation between fqdn and full path by using flag -u

Good example (using http://www.pbs.org/shows/)

Code: Select all

./check_http -H www.pbs.org -u /shows/
Where this will NOT work:

Code: Select all

./check_http -H www.pbs.org/shows/
Suppose the above site is hosted on a non-standard port, like your example, then just append it with the flag -p

Code: Select all

./check_http -H www.pbs.org -u /shows/ -p 123456

*You can test these checks manually from your Nagios server, 1st go to this directory /usr/local/nagios/libexec
Once in that location run "./plugin-name" with the appropriate flags you want to check.
To get help/usage info about any plugin run "./plugin-name -h"

Hope this helps, certainly let us know if you have any other questions, thanks.
Be sure to check out the Knowledgebase for helpful articles and solutions!
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

@bwallace should i put 'check_http -H 182.34.3.24 -p 1234' in some file with libexec folder?
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

@bwallace Thanks for your reply, but I don't want to monitor www.prs.com I want to notify www.prs.com about the alerts.. Like somehow I need to replace notify-by-email with notify-by-http. How can I do this?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Customizing Nagios to send http notifications

Post by rkennedy »

bunker wrote:@bwallace Thanks for your reply, but I don't want to monitor http://www.prs.com I want to notify http://www.prs.com about the alerts.. Like somehow I need to replace notify-by-email with notify-by-http. How can I do this?
Please see my post above. You will need to create something similar to 'notify-host-by-http', as well as an API to handle it on your end.
Former Nagios Employee
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

Sorry @rkennedy! I didn't understand your solution. And I do have a service to handle these notifications.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Customizing Nagios to send http notifications

Post by rkennedy »

No worries. I haven't tested this as I don't have an API to use, but this should be the start of what you need to do -

Define a command called notify-host-by-http, and as the command_line have it use -

Code: Select all

/usr/bin/curl --data "param1=value1&param2=value2" https://yourdomain.com/things
Essentially, it would look like -

Code: Select all

define command {
command_name notify-host-by-http
command_line /usr/bin/curl --data "host=$HOSTNAME$&state=$HOSTSTATE$" https://yourdomain.com/things
}
This will send a curl POST to https://yourdomain.com/things and post the parameters under --data.

Once you've got that setup completely, you'll need to have your contact to use this as the host_notification_command.

Does that make sense?
Former Nagios Employee
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

Yeah! Thanks, but let me try.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Customizing Nagios to send http notifications

Post by rkennedy »

Sounds good - I'm curious to see how it works. Let us know!
Former Nagios Employee
Locked