Page 2 of 4
Re: Is it possible to have 2 notifications template
Posted: Tue Nov 19, 2013 2:07 pm
by cesar.garza
tmcdonald wrote:cbeattie wrote:If it bugs you enough, there are two things I can think of. First, enable your e-mail contact to receive unknown (u) notifications and r, but not w or c. I get far, far fewer unknown states than w or c, and maybe you'll still get all the r.
cesar.garza wrote:Thanks for your help and i tried with notification option ""u"" only but it didn't work.
Did you try with "u" AND "r" like he suggested?
Or have you tried cbeattie's previous suggestion of a custom notification command?
I havent tried
cbeattie's suggestion yet because i am not fully understand. I tried just ""u"" with r option and it didn't work. On some website,i read that if there is no option (w and c) then you wont get the r too.
Re: Is it possible to have 2 notifications template
Posted: Tue Nov 19, 2013 4:51 pm
by cbeattie
cesar.garza wrote:
I haven't completely understand this one. should i have only one templates without/with ""r"" ? and then add above command to command.cfg file.
The contact needs to have the w, c, and r. The idea is that Nagios is satisfied the contact will receive everything. Then the notification command (not Nagios) filters out the w and c, and only forwards the r. The way I wrote it won't work, though, since "if" is built-in to bash.
What sreinhardt suggested is to replace the printf call in the notification command, and have the command call a shell script instead (and pass it the necessary parameters). The script then checks if it's being called for a recovery notification, and if so, then it sends out the e-mail notification. The script just ignores warnings and criticals, and doesn't send e-mail for them.
Re: Is it possible to have 2 notifications template
Posted: Tue Nov 19, 2013 4:54 pm
by sreinhardt
I was actually stating that I would wrap the entire notification command in a script, or as much as possible as nothing is evaluated other than variables being expanded. If you just handle the "if" logic in a bash script, we're both right! What are you confused on cesar?
Re: Is it possible to have 2 notifications template
Posted: Wed Nov 20, 2013 2:14 pm
by cesar.garza
cbeattie wrote:I had another idea which (if it works) is certainly easier and better than changing the source code. It might be possible to use a custom notification command instead. Something along these lines:
Code: Select all
define command {
command_name recovery_only
command_line if [ "$NOTIFICATIONTYPE$" -eq "RECOVERY" ]; then /bin/printf your_command | /bin/mail your_command; fi
}
Then change your contact's service_notification_options to w,c,r and the service_notification_command to recovery_only (or whatever you called it).
I have tried this suggestion and it didn't work. Not sure who to work on cbeattie second suggetion to delete the code part form the printf.
Re: Is it possible to have 2 notifications template
Posted: Wed Nov 20, 2013 2:23 pm
by cesar.garza
cbeattie wrote:cesar.garza wrote:
I haven't completely understand this one. should i have only one templates without/with ""r"" ? and then add above command to command.cfg file.
The contact needs to have the w, c, and r. The idea is that Nagios is satisfied the contact will receive everything. Then the notification command (not Nagios) filters out the w and c, and only forwards the r. The way I wrote it won't work, though, since "if" is built-in to bash.
What sreinhardt suggested is to replace the printf call in the notification command, and have the command call a shell script instead (and pass it the necessary parameters). The script then checks if it's being called for a recovery notification, and if so, then it sends out the e-mail notification. The script just ignores warnings and criticals, and doesn't send e-mail for them.
It sounds good to me but so far what i understand is that make the shell script with this
Code: Select all
if [ "$NOTIFICATIONTYPE$" -eq "RECOVERY" ]; then /bin/printf your_command | /bin/mail your_command; fi
and pass the script name and path in the command.cfg
Re: Is it possible to have 2 notifications template
Posted: Wed Nov 20, 2013 2:36 pm
by cesar.garza
I have make the script with command.cfg configuratino. please have a look and let me know if i am going in the wrong direction.
Re: Is it possible to have 2 notifications template
Posted: Wed Nov 20, 2013 4:38 pm
by cbeattie
I think you're on the right track. You have to pass the Nagios macros as parameters to the script. So, I think you'll end up with something along the lines of:
Code: Select all
define command{
command_name notify-service-by-email-test
command_line /usr/local/nagios/libexec/recovery.sh $NOTIFICATIONTYPE$ $SERVICEDESC$ ...etc...
}
And then in the script, to use the parameters you passed, something along the lines of:
Code: Select all
#! /bin/sh
notificationtype=$1
servicedesc=$2
if
[ "${notificationtype}" == "RECOVERY" ]; then /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: ${notificationtype}\n\nService: ${servicedesc}\nHost ...etc...
Re: Is it possible to have 2 notifications template
Posted: Thu Nov 21, 2013 11:28 am
by slansing
Thank's cbeattie!
Re: Is it possible to have 2 notifications template
Posted: Tue Nov 26, 2013 12:56 pm
by cesar.garza
I tried the cbeattie suggest and it didn't work. what i did is make a script and put the command in the command.cfg like this and also edited the template file for notification option. I got the call but not recovery email.
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
#! /bin/sh
NOTIFICATIONTYPE=$1
SERVICEDESC=$2
HOSTALIAS=$3
HOSTADDRESS=$4
SERVICESTATE=$5
LONGDATETIME=$6
SERVICEOUTPUT=$7
SERVICEACTIONURL=$8
CONTACTEMAIL=$9
if
[ "${NOTIFICATIONTYPE}" == "RECOVERY" ]; then /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};
fi
Re: Is it possible to have 2 notifications template
Posted: Wed Nov 27, 2013 12:58 pm
by slansing
We're looking into this and will get back to you.