Page 1 of 1
Posting an alert via HTTP to 3rd party app
Posted: Sat Dec 05, 2020 3:58 pm
by ric.flair.wcw
Good evening experts,
First of all I don't have experience with Nagios so any info you'll share will be new to me.
I have an app where I want to consume Nagios notifications. I presumed there is a webhook option in Nagios so it can send alert via HTTP to my app. I found a forum thread (
https://support.nagios.com/forum/viewto ... =7&t=37493) but it is 4 years old now and I hope there is a another more shiny way for doing that.
I found the 'Notifications' section in the Nagios doc (
https://assets.nagios.com/downloads/nag ... tions.html) but it didn't help unfortunately.
If there isn't then I am not sure how the commands can be used and how to bind them to Nagios alerts / notifications.
Thanks a lot!
Best regards,
V.
Re: Posting an alert via HTTP to 3rd party app
Posted: Mon Dec 07, 2020 5:47 pm
by benjaminsmith
Hi V,
So that solution is a good starting point. Essentially, if you can post data to your web app using a curl command, like:
Code: Select all
/usr/bin/curl --data "param1=value1¶m2=value2" https://yourdomain.com/things
You can then build up a custom notification command in Naigis using that as a starting point. All the notification data such as the hostname, time, state type can be passed into your notification command via system macros.
See:
https://assets.nagios.com/downloads/nag ... olist.html
Here's an example of the notification handler in Nagios XI for the phpmailer ( passes the macros as arguments to the PHP script to send to the contact).
Code: Select all
/usr/bin/php /usr/local/nagiosxi/scripts/contact_notification_handler.php
--contactemail="$CONTACTEMAIL$" --subject="** $NOTIFICATIONTYPE$ Host Alert:
$HOSTNAME$ is $HOSTSTATE$ **" --message="***** Nagios Monitor XI Alert
*****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState:
$HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time:
$LONGDATETIME$\n"
Hope that helps clear things up.
Benjamin
Re: Posting an alert via HTTP to 3rd party app
Posted: Tue Dec 22, 2020 5:52 am
by ric.flair.wcw
Hi,
Sorry for the late reply and thank you for the hint!
Eventually I used the following definitions:
Code: Select all
define service {
host_name computer-2.broadband
service_description is_splunk_running
check_command check_http!-p 8000!!!!!!!
max_check_attempts 1
notification_period 24x7
notification_options w,c,r,u,f,s,
notifications_enabled 1
contacts reaction
stalking_options o,w,c,u,N,
register 1
}
define contact {
contact_name reaction
service_notifications_enabled 1
service_notification_period 24x7
service_notification_options w,u,c,f,s
host_notification_commands notify_reaction
service_notification_commands notify_reaction
can_submit_commands 1
}
define command {
command_name notify_reaction
command_line /usr/bin/curl --header "Content-Type: application/json" --request POST --data '{"error": "host is down", "host": "$HOSTADDRESS$:q"}' --inecure https://computer-2.broadband:8443/reaction-engine/notification/event/nagios
}
define host {
host_name computer-2.broadband
address computer-2.broadband
max_check_attempts 1
active_check_enabled 1
notification_period 24x7
notifications_enabled 1
register 1
}
Regards,
V.