Director email notification

Hi Techs

I have a challenge to send email notifications from Director to my email. What is did as below & didnt received any notifications…

zones.d/Master-Zone/hosts.conf

object Host “ds1.uw” { import “[switch_host_template]” import “[nw_uptime_host_templete]” display_name = “switch1” address = “10.254.6.3” groups = [ “switch” ] }

zones.d/director-global/host_templates.conf

template Host “switch_host_template” { check_command = “[nwc_health]” max_check_attempts = “3” check_period = “Always” check_interval = 1m retry_interval = 30s check_timeout = 30s enable_notifications = true enable_active_checks = true enable_passive_checks = true enable_event_handler = false enable_flapping = false enable_perfdata = true vars.nwc_health_community = “pivitpoller” vars.nwc_health_oids = “1.3.6.1.2.1.1” }

zones.d/Master-Zone/notification_apply.conf

apply Notification “icinga_notification” to Host { import “[icinga host state changes]” period = “Always” assign where host.check_timeout == “3” user_groups = [ “IT Admins” ] }

zones.d/Master-Zone/notification_templates.conf

template Notification “icinga host state changes” { command = “[mail-host-notification]” period = “Always” states = [ Down, Up ] types = [ Acknowledgement, Problem, Recovery ] user_groups = [ “IT Admins” ] vars.notification_useremail = “i used my emails”

Hi,

the shown examples are templates, you’ll need to define real objects (or apply rules) for notifications.
They can import the previously created templates.

Cheers,
Michael

Hi Michael

Thanks for the info…

I have a below and dont know where to integrate host & Notifications
Checks --> host templates —> host ( working good)
Notification , Users with email --> usergroup --> Notification Templates —> notification ( created )

Can you share a screenshot of the notification you’ve created now?

Likely you did not create a matching apply rule, or anything else. Also, please share the output of your current Director deployment.

Cheers,
Michael

Hi Michael
I found the below , and not sure where i am making the mistake. Look like its storing the temporary location “notification_apply.conf”

warning/ApplyRule: Apply rule ‘host_notification’ (in /var/lib/icinga2/api/packages/director/bcb21f71-d6dc-4e99-a687-e198ba91b1dd/zones.d/Master-Zone/notification_apply.conf: 1:0-1:45) for type ‘Notification’ does not match anywhere!

find . -name notification_apply.conf
./var/lib/icinga2/api/zones/Master-Zone/director/notification_apply.conf
./var/lib/icinga2/api/packages/director/317568a3-7831-4302-804e-3623fad4a743/zones.d/Master-Zone/notification_apply.conf
./var/lib/icinga2/api/packages/director/bcb21f71-d6dc-4e99-a687-e198ba91b1dd/zones.d/Master-Zone/notification_apply.conf

[2019-04-06 15:17:50 +1000] information/ApiListener: My API identity: localhost.localdomain
[2019-04-06 15:17:50 +1000] warning/ApplyRule: Apply rule ‘host_notification’ (in [[stage]/zones.d/Master-Zone/notification_apply.conf] for type ‘Notification’ does not match anywhere!
[2019-04-06 15:17:50 +1000] information/ConfigItem: Instantiated 1 ScheduledDowntime.

Notification

Notification Template

Hi,

the assign where expression with host.check_timeout = 3 looks odd. Pick a different pattern, like host.vars.os == "Linux" or any other match for the hosts/services.

Cheers,
Michael

Thanks Michael , I just noticed the mistake. No warning now …Its amazing your knowledge :slight_smile:

1 Like

Hi,

it is important to get things going, and learn a lot. Once you feel familiar with Icinga, stick here and help other users from your gained expertise :slight_smile:

Cheers,
Michael

1 Like

Yes i agreed and stuck again.I believe Director required more work to get the email

warning/PluginNotificationTask:

Notification command for object ‘as2.uw’ (PID: 2431, arguments: ‘/etc/icinga2/scripts/mail-host-notification.sh’ ‘-4’ ‘10.254.6.70’ ‘-6’ ‘’ ‘-b’ ‘’ ‘-c’ ‘’ ‘-d’ ‘2019-04-08 20:42:09 +1000’ ‘-l’ ‘switch1’ ‘-n’ ‘switch1’ ‘-o’ ‘CRITICAL - Plugin timed out while executing system call’ ‘-r’ ‘robert@mmail.com’ ‘-s’ ‘DOWN’ ‘-t’ 'PROBLEM’)

terminated with exit code 1, output: which: no mail in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin) mail not found in $PATH. Consider installing it.

Depending on your distribution, you need to install a local MTA (mail transfer agent). Typically Postfix, exim or sendmail. Best is to configure your local mail relay which can send emails to the Internet, if needed.

The mail binary points to this and the notification script passes the correct parameters.

Cheers,
Michael

1 Like

Hi Michael

I have find the below , can you refer any links to knowledge base pls

[root@localhost /]# find . -name smtp
./etc/pam.d/smtp
./var/spool/postfix/private/smtp
./usr/libexec/postfix/smtp
[root@localhost /]#

Use
yum install mailx
OR
apt-get install mailx
or your appropriate package manager.

/George

3 Likes

Thanks Michael and George
Just installed " apt-get install mailx".and Mail working good , did not modified anything

MAILBIN = mail
mail-host-notification.sh mail-service-notification.sh
[root@localhost scripts]# cat mail-host-notification.sh

Send the mail using the $MAILBIN command.

If an explicit sender was specified, try to set it.

if [ -n “$MAILFROM” ] ; then

Modify this for your own needs!

Debian/Ubuntu use mailutils which requires -a to append the header

if [ -f /etc/debian_version ]; then
/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE” | $MAILBIN -a “From: $MAILFROM” -s “$SUBJECT” $USEREMAIL

Other distributions (RHEL/SUSE/etc.) prefer mailx which sets a sender address with -r

else
/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE” | $MAILBIN -r “$MAILFROM” -s “$SUBJECT” $USEREMAIL
fi
else
/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE”
| $MAILBIN -s “$SUBJECT” $USEREMAIL
fi