SMS notifications for specific hosts & services

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.
Locked
sixarm
Posts: 12
Joined: Sat Apr 07, 2012 5:05 am

SMS notifications for specific hosts & services

Post by sixarm »

Hi,

I have Nagios up and running with various services and hosts being monitored successfully. I have configured email notifications using Postfix along with SMS alerting using our SMS provider Mediaburst. At present we are only receiving SMS notifications when a host alarms. I did this for testing so that we didn't get bombarded with SMS notifications for every single service alarm. I achieved this by defining a new command for the SMS notification and then adding this command to the 'generic-contact' contact template, as can be seen below:

Code: Select all

host_notification_commands             notify-host-by-email,notify-host-by-sms
My overall Nagios setup is fairly basic and still uses the default templates. I am a contact with a defined email and pager (my mobile number), I use the 'generic-contact' template and I'm also a member of the 'admins' contact group. My hosts then have the contact group 'admin' assigned to them for notification purposes.

What I'd like to achieve is to define specific hosts and services as 'critical-host' & 'critical-service' and then apply SMS notifications to these hosts and services only. This will allow me to get SMS notifications for key hosts & services and not when the cleaner unplugs the printer. :)

I'm after some advice as to how to achieve the above as I can't quite get my head around it.

If any further information is required then I will be more than happy to provide it.

I look forward to your replies.
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: SMS notifications for specific hosts & services

Post by agriffin »

The way I would approach this is by first defining a "critical" hostgroup and a "critical" servicegroup. Then I'd write a custom notification script which is passed the hostgroup/servicegroup and then calls the notify-by-email or notify-by-sms commands based on that. It's a bit more work than I think you were hoping for, but Nagios doesn't have any built-in options to enable this (that I'm aware of anyway).

Hope that helps!
sixarm
Posts: 12
Joined: Sat Apr 07, 2012 5:05 am

Re: SMS notifications for specific hosts & services

Post by sixarm »

Thank you so much for the reply.

I had in mind that I would end up creating either a host/service group which each critical host/server would then be a member of, or a critical host/service template which each critical host/service would then be based upon. So I understand the first part.

What I'm not sure about is the custom notification script. I have zero experience with script writing for Nagios. Are you suggesting something along the lines of...

IF host/service is a member of 'critical-host-group' OR 'critical-service-group' THEN

notify-by-sms & notify-by-email

ELSE

notify-by-email

???
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: SMS notifications for specific hosts & services

Post by agriffin »

Putting it into a script may not even be necessary, I suggested defining another command along these lines:

Code: Select all

define command{
	command_name	notify-service-by-email-or-sms
	command_line	echo $SERVICEGROUPNAMES$ | grep -q critical && notify-service-by-sms || notify-service-by-email
	}
You'll need to replace notify-service-by-email and notify-service-by-sms with some actual commands (like the full command line text of those commands currently defined). This will notify you by sms for critical services, or by email for other
sixarm
Posts: 12
Joined: Sat Apr 07, 2012 5:05 am

Re: SMS notifications for specific hosts & services

Post by sixarm »

Just to follow this up...

I ended up defining two new notification processes, notify-critical-service-by-sms & notify-critical-host-by-sms, with the following commands:

Code: Select all

define command{
   command_name   notify-critical-host-by-sms
   command_line   echo $HOSTGROUPNAMES$ | grep -q critical && notify-by-sms
   }

define command{
   command_name   notify-critical-service-by-sms
   command_line   echo $SERVICEGROUPNAMES$ | grep -q critical && notify-by-sms
   }
As you stated, the notify-by-sms part contains the actual command to perform that action, so it executes a script provided by our SMS provider.

In addition to the above I added the following to the Contact Template:

Code: Select all

service_notification_commands   notify-critical-service-by-sms,notify-service-by-email	
host_notification_commands      notify-critical-host-by-sms,notify-host-by-email
I then created a Host Group and a Service Group called critical-hosts and critical-services respectively. I then just make the host/service a member of this group.

This has achieved exactly what I was after, for standard hosts/services notifications are sent via email and for critical hosts/services notifications are sent via both SMS and email.

Thank you agriffin for your help, it was much appreciated.
agriffin
Posts: 876
Joined: Mon May 09, 2011 9:36 am

Re: SMS notifications for specific hosts & services

Post by agriffin »

No problem, thanks for sharing!
Locked