Is it possible to have 2 notifications template

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.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

#!/bin/bash ---> this thing worked and i got the email. However when i setup my actual notify-service-by-email , i did get the email but it was blank -no information at all. I have setup like that;

Code: Select all

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/local/nagios/libexec/messageone_recovery /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n\nURL: $SERVICEACTIONURL$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Is it possible to have 2 notifications template

Post by abrist »

As your actual mail command is in the custom script, remove the printf statement and replace with the necessary macros:

Code: Select all

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email
        command_line    /usr/local/nagios/libexec/messageone_recovery "$NOTIFICATIONTYPE$" "$SERVICEDESC$" "$HOSTALIAS$" "$HOSTADDRESS$" "$SERVICESTATE$" "$LONGDATETIME$" "$SERVICEOUTPUT$" "$SERVICEACTIONURL$" "$CONTACTEMAIL$"
}
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

Okay guys, i have modified the templates and contact and after that its not working at all. I am pasting my command.cfg, contact.cfg, and template.cfg.
I have not changed anything in the script and its working from command line.

Code: Select all

# 'notify-service-by-email' command definition
define command{
        command_name    notify-service-by-email-test
        command_line    /usr/local/nagios/libexec/messageone_recovery "$NOTIFICATIONTYPE$" "$SERVICEDESC$" "$HOSTALIAS$" "$HOSTADDRESS$" "$SERVICESTATE$" "$LONGDATETIME$" "$SERVICEOUTPUT$" "$SERVICEACTIONURL$" "$CONTACTEMAIL$"
        }

Code: Select all

define contact{
        contact_name              Recovery-phone 
        use                             generic-contact      
        alias                           Phone test                     
        email                          [email protected]       
        }

#define contact{
        contact_name              Recovery-email                             
        use                             generic-contact-email-test             
        alias                           Recovery email test                         
        email                          [email protected]      
       }

define contactgroup{
        contactgroup_name       admins
        alias                   Nagios Administrators
        members                Recovery-email, Recovery-phone
        }

Code: Select all

define contact{
        name                            generic-contact        
        service_notification_period     24x7                 
        host_notification_period        24x7                 
        service_notification_options    w,u,c,f,s         
        host_notification_options       d,u                   
        service_notification_commands   notify-service-by-phone 
        host_notification_commands      notify-host-by-phone   
        register                        0                               }


define contact{
        name                            generic-contact-email-test   
        service_notification_period     24x7                
        host_notification_period        24x7                  
        service_notification_options    r                  
        host_notification_options       r                        
        service_notification_commands   notify-service-by-email-test  
        host_notification_commands      notify-host-by-email   
       register                         0                     
        }
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Is it possible to have 2 notifications template

Post by abrist »

Lets check the logs:

Code: Select all

cat /usr/local/nagios/var/nagios.log | grep notify | tail
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
cesar.garza
Posts: 80
Joined: Mon Aug 19, 2013 3:14 pm

Re: Is it possible to have 2 notifications template

Post by cesar.garza »

We did it guys...Working as expected, getting only alert calls and recovery emails. Awesome.....
quick question, can we run notify by host with same script ? I know we can do with separate script and change the macros but I was curious to run from the same script but how ???
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Is it possible to have 2 notifications template

Post by slansing »

Using it for host notifications as well? This should work the same.
Locked