Page 1 of 1

Phone notification only for specific hosts|services

Posted: Mon Nov 19, 2018 2:15 am
by AlexSavVl
We have hundreds of hosts and thousands of services, but only some of them should have SMS notifications. How can I do that?
Separate contact for SMS notifications is a bad option, since in this case, the user will not be able to manage notifications.

Is it possible to add a variable to a host/service and check it in xi_host_notification_handler (/usr/local/nagiosxi/scripts/handle_nagioscore_notification.php) before sending SMS notifications?

For example

Code: Select all

if ( sms_notification == 1)
     send_sms()
Could you point to the part of the code responsible for sending SMS, or suggest another solution?

Re: Phone notification only for specific hosts|services

Posted: Mon Nov 19, 2018 6:53 am
by AlexSavVl
Maybe someone is trying to solve a similar problem.
I made it by adding a variable

Code: Select all

_sendsms	on
to "Free Variable" in required service, changing xi_service_notification_handler in "Commands" from

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=service --contact="$CONTACTNAME$" ...
to

Code: Select all

/usr/bin/php /usr/local/nagiosxi/scripts/handle_nagioscore_notification.php --notification-type=service sendsms=$_SERVICESENDSMS$ ...
(change _SERVICESENDSMS$ to HOSTSENDSMS$ in host case)
Changing email-to-sms subject to

Code: Select all

sms %sendsms%
In than case if I will add variable "_sendsms on" in "free variavle" of a service, the subject of e-mail will be "sms on", if not -> "sms $"
And removing all messages with subject "sms $" by Postfix ba adding

Code: Select all

/^Subject: sms \$/ DISCARD
to /etc/postfix/header_checks (dont foget uncomment header_checks from main.cf)

So postfix deletes unnecessary messages.

Re: Phone notification only for specific hosts|services

Posted: Mon Nov 19, 2018 12:45 pm
by cdienger
Thanks for following up with your solution!