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

Re: Customizing Nagios to send http notifications

Post by bunker »

Hey! I tried as you suggested. I checked the curl on command line and then it worked perfectly fine. Then I added that command in /usr/local/nagios/etc/objects/command.cfg file like below,

Code: Select all

# 'notify-service-by-http' command definition
define command{
        command_name    notify-service-by-http
        command_line    /usr/bin/curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"notification":{"host":$HOSTADDRESS$, "service":$SERVICEDISPLAYNAME$, "state":$SERVICESTATE$, "host-state-type":$SERVICESTATETYPE$, "notification-type":$NOTIFICATIONTYPE$, "attempts":$SERVICEATTEMPT$, "max-attempts":$MAXSERVICEATTEMPTS$, "time":$TIME$}}' http://192.168.56.113:9090/things > /tmp/notification.log
        }
For testing, i increased the load and below message displays but no notification is received. The web interface displays the below message,

Code: Select all

 
http admin CRITICAL 03-19-2016 00:50:17 0d 0h 9m 0s 3/3 CHECK_NRPE: Socket timeout after 10 seconds.
My contact.cfg

Code: Select all

 define contact{
        contact_name                    saas-app        ; Short name of user
    use                generic-contact        ; Inherit default values from generic-contact template (defined above)
        alias                           scaling as a service    ; Full name of user
        service_notification_options    w,c,r
#        host_notification_options       w,c,r
#        host_notification_commands      notify-host-by-http
        service_notification_commands   notify-service-by-http
#        register                        0
        }
define contactgroup{
        contactgroup_name       saas
        alias                   scaling as a service notifying group
        members                 saas-app
        }
object.cfg

Code: Select all

define host{
        host_name                       ubuntu-VirtualBox
        address                         192.168.56.113
        notifications_enabled           1          ; Host notifications are enabled
        event_handler_enabled           0          ; Host event handler is enabled
        flap_detection_enabled          0          ; Flap detection is enabled
        failure_prediction_enabled      1          ; Failure prediction is enabled
        process_perf_data               1          ; Process performance data
        retain_status_information       1          ; Retain status information across program restarts
        retain_nonstatus_information    1          ; Retain non-status information across program restarts
                check_command                   check-host-alive
                max_check_attempts              3  ; recheck the service before notifying the contact
        retry_check_interval            60 ; recheck intervals
                notification_interval           0
               # notification_options           w,c,r
                contact_groups                  saas
        register                        1          ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

define service {
        host_name                       ubuntu-VirtualBox
        service_description             keystone http admin
        check_command                   check_nrpe!check_keystone_http_admin
        use                             generic-service
        notification_interval           0 ; set > 0 if you want to be renotified
}
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

Hi @rkennedy, I tried as you told but unable to receive any notification at my service side. I have ensured thay my service is up and listening for the request. I checked the curl in command line before puting below code in /use/local/nagios/etc/objects/command.cfg.

Code: Select all

# 'notify-service-by-http' command definition
define command{
        command_name    notify-service-by-http
        command_line    /usr/bin/curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X POST -d '{"notification":{"host":$HOSTADDRESS$, "service":$SERVICEDISPLAYNAME$, "state":$SERVICESTATE$, "host-state-type":$SERVICESTATETYPE$, "notification-type":$NOTIFICATIONTYPE$, "attempts":$SERVICEATTEMPT$, "max-attempts":$MAXSERVICEATTEMPTS$, "time":$TIME$}}' http://192.168.56.113:9090/things > /tmp/notification.log
        }

For testing, I increased load n my service and got below message on web interface. but no notification had been sent.

Code: Select all

http admin CRITICAL 03-19-2016 00:50:17 0d 0h 9m 0s 3/3 CHECK_NRPE: Socket timeout after 10 seconds.
For you convenience I am also adding code for my contact.cfg and object.cfg respectively.
/usr/local/nagios/etc/objects/contact.cfg

Code: Select all

define contact{
        contact_name                    saas-app        ; Short name of user
    use                generic-contact        ; Inherit default values from generic-contact template (defined above)
        alias                           scaling as a service    ; Full name of user
        service_notification_options    w,c,r
#        host_notification_options       w,c,r
#        host_notification_commands      notify-host-by-http
        service_notification_commands   notify-service-by-http
#        register                        0
        }
define contactgroup{
        contactgroup_name       saas
        alias                   scaling as a service notifying group
        members                 saas-app
        }
-> /usr/local/nagios/etc/objects/my_object.cfg

Code: Select all


define host{
        host_name                       ubuntu-VirtualBox
        address                         192.168.56.113
        notifications_enabled           1          ; Host notifications are enabled
        event_handler_enabled           0          ; Host event handler is enabled
        flap_detection_enabled          0          ; Flap detection is enabled
        failure_prediction_enabled      1          ; Failure prediction is enabled
        process_perf_data               1          ; Process performance data
        retain_status_information       1          ; Retain status information across program restarts
        retain_nonstatus_information    1          ; Retain non-status information across program restarts
                check_command                   check-host-alive
                max_check_attempts              3  ; recheck the service before notifying the contact
        retry_check_interval            60 ; recheck intervals
                notification_interval           0
               # notification_options           w,c,r
                contact_groups                  saas
        register                        1          ; DONT REGISTER THIS DEFINITION – ITS NOT A REAL HOST, JUST A TEMPLATE!
        }

define service {
        host_name                       ubuntu-VirtualBox
        service_description             keystone http admin
        check_command                   check_nrpe!check_keystone_http_admin
        use                             generic-service
        notification_interval           0 ; set > 0 if you want to be renotified
}
User avatar
nozlaf
Posts: 172
Joined: Sun Nov 09, 2014 9:50 pm
Location: Victoria, Australia

Re: Customizing Nagios to send http notifications

Post by nozlaf »

I do this to integrate servicedeskplus and nagios, on alrert my script posts data to the HTTP api of servicedeskplus

one gotcha I found was that nagios was creating tickets every time it ran the notify script so I added a simple mysql datbase to keep track of the incident number in Nagios and the incident number in service desk plus, that way if the same issue was being notified a 2nd or subsequent times it performed a different action, instead of creating a new ticket it adds a note to the existing ticket to let you know that the issue is still there

if that sort of thing would be helpful for you I can share you my script, its not well written
Looking forward to seeing you all at #NagiosCon2019?
-Dedicated Lover of Nconf,PNP4Nagios and Nagvis
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

Well! i don't know the reason of not receiving notifications. If you think your solution will work in my case then please share your script. Thanks
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

Heelpppp Pllleaaaseeee..... :cry: :roll:
User avatar
nozlaf
Posts: 172
Joined: Sun Nov 09, 2014 9:50 pm
Location: Victoria, Australia

Re: Customizing Nagios to send http notifications

Post by nozlaf »

its the weekend here ill get it for you tomorrow
Looking forward to seeing you all at #NagiosCon2019?
-Dedicated Lover of Nconf,PNP4Nagios and Nagvis
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: Customizing Nagios to send http notifications

Post by hsmith »

Thanks, @nozlaf!
Former Nagios Employee.
me.
bunker
Posts: 12
Joined: Thu Mar 10, 2016 8:00 am

Re: Customizing Nagios to send http notifications

Post by bunker »

HELP!! :(
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Customizing Nagios to send http notifications

Post by rkennedy »

Is there a reason you have notification_options commented out for your host? Also, you have no notification_options defined in your service definition.

Take a look at this page for more information on notification_options, https://assets.nagios.com/downloads/nag ... tions.html
Former Nagios Employee
Locked