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

Is it possible to have 2 notifications template

Post by cesar.garza »

Hey guys
I need your suggestion, few days ago i have posted a thread regarding having a recovery email but not phone call. you can read my this thread http://support.nagios.com/forum/viewtop ... =7&t=21980 now I have setup a notification service by phone and getting the calls whenever services or hosts go down. But there is a twist that we are getting calls for recovery services/hosts too that we don't want it. But we want the emails for recovery services/host only. However some one from this forum suggested me to have a two templates. Template one with ""R"" and template two without ""R"". This idea is not completely working for me. Template for service by phone without ""r"" works fine but Template for service by email with ""r"" is not working. it only works when i put options "w and c" with the option (r).
Any suggestion guys ??
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 »

Can you post the relevant configs?
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.
cbeattie
Posts: 19
Joined: Fri Oct 04, 2013 7:12 am

Re: Is it possible to have 2 notifications template

Post by cbeattie »

I think Nagios isn't set up to be able to do what you want to do. I don't speak the language, but I looked at the source in notifications.c anyway. This bit looked interesting.

Code: Select all

if(svc->current_state == STATE_OK) {

	if(cntct->notify_on_service_recovery == FALSE) {
		log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify this contact about RECOVERY service states.\n");
		return ERROR;
		}

	if(!((svc->notified_on_unknown == TRUE && cntct->notify_on_service_unknown == TRUE) || (svc->notified_on_warning == TRUE && cntct->notify_on_service_warning == TRUE) || (svc->notified_on_critical == TRUE && cntct->notify_on_service_critical == TRUE))) {
		log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify about this recovery.\n");
		return ERROR;
		}
	}
It looks like this says if the contact doesn't have r, then don't sent a recovery notification. Then it looks like it says if you don't also have u, w, or c, set, then again don't send a notification. I think that's the line that's messing you up for services. There's a similar one for hosts.

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.

Or, you could delete that line, recompile Nagios, and see what happens. I don't know how that line fits in to the whole notification algorithm. There's probably a perfectly sane, logical reason for it to be there, but hey, it's open source! Maybe Nagios will act the way you expect it to, or maybe your e-mail contact will get hammered with recovery messages. If it doesn't work, just put the original file back and recompile again.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Is it possible to have 2 notifications template

Post by tmcdonald »

Thanks for the input, cbeattie! cesar.garza, can you let us know if this will work for you?
Former Nagios employee
cbeattie
Posts: 19
Joined: Fri Oct 04, 2013 7:12 am

Re: Is it possible to have 2 notifications template

Post by cbeattie »

I should word my post better! This is the line I meant you should remove, if you try that route:

Code: Select all

if(!((svc->notified_on_unknown == TRUE && cntct->notify_on_service_unknown == TRUE) || (svc->notified_on_warning == TRUE && cntct->notify_on_service_warning == TRUE) || (svc->notified_on_critical == TRUE && cntct->notify_on_service_critical == TRUE))) {
      log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify about this recovery.\n");
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 »

cbeattie wrote:I should word my post better! This is the line I meant you should remove, if you try that route:

Code: Select all

if(!((svc->notified_on_unknown == TRUE && cntct->notify_on_service_unknown == TRUE) || (svc->notified_on_warning == TRUE && cntct->notify_on_service_warning == TRUE) || (svc->notified_on_critical == TRUE && cntct->notify_on_service_critical == TRUE))) {
      log_debug_info(DEBUGL_NOTIFICATIONS, 2, "We shouldn't notify about this recovery.\n");
Thanks for your help and i tried with notification option ""u"" only but it didn't work.
One interesting thing i found that when i made some changes in the templates with notification option U and tested with this command /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg...i got the weird message...

Code: Select all

Checking contacts...
Warning: Service recovery notification option for contact 'NGAF-email' doesn't make any sense - specify critical and/or warning options as well
Warning: Service recovery notification option for contact 'sham-email' doesn't make any sense - specify critical and/or warning options as well
        Checked 6 contacts.
Can you please let me know where i have to change the above code ? I am not that much in nagios and haven't seen coding in the nagios so far.
Thanks
cbeattie
Posts: 19
Joined: Fri Oct 04, 2013 7:12 am

Re: Is it possible to have 2 notifications template

Post by cbeattie »

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).
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Is it possible to have 2 notifications template

Post by tmcdonald »

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?
Former Nagios employee
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Is it possible to have 2 notifications template

Post by sreinhardt »

I would go the route of adding those checks to a script that handles the printf portion. The notification options and such, are not being sent to a bash or other shell interpreter so the if statement would likely not be evaluated. However calling a script that does use bash or the scripting language of your choice to handle this would be a great and preferred solution. Unfortunately, as may have been mentioned, you can not presently have separate templates for a single contacts notifications, you could always do separate contacts for mail and phone, but that is less than ideal and again why using a script to handle that would be a great suggestion!
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
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 »

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 haven't completely understand this one. should i have only one templates without/with ""r"" ? and then add above command to command.cfg file.
Locked