Page 2 of 2

Re: Customizing Nagios to send http notifications

Posted: Sat Mar 19, 2016 12:07 am
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
}

Re: Customizing Nagios to send http notifications

Posted: Sat Mar 19, 2016 1:28 am
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
}

Re: Customizing Nagios to send http notifications

Posted: Sat Mar 19, 2016 1:51 am
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

Re: Customizing Nagios to send http notifications

Posted: Sat Mar 19, 2016 2:33 am
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

Re: Customizing Nagios to send http notifications

Posted: Sat Mar 19, 2016 10:28 am
by bunker
Heelpppp Pllleaaaseeee..... :cry: :roll:

Re: Customizing Nagios to send http notifications

Posted: Sun Mar 20, 2016 12:14 am
by nozlaf
its the weekend here ill get it for you tomorrow

Re: Customizing Nagios to send http notifications

Posted: Mon Mar 21, 2016 10:12 am
by hsmith
Thanks, @nozlaf!

Re: Customizing Nagios to send http notifications

Posted: Sat Mar 26, 2016 5:52 am
by bunker
HELP!! :(

Re: Customizing Nagios to send http notifications

Posted: Mon Mar 28, 2016 9:25 am
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