# Problem setting up email notification (mail-host-notification)

**URL:** <https://community.icinga.com/t/problem-setting-up-email-notification-mail-host-notification/9857>\
**Category:** Icinga Director\
**Created:** [May 18, 2022, 1:59pm UTC](https://community.icinga.com/t/problem-setting-up-email-notification-mail-host-notification/9857 "2022-05-18T13:59:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glober](https://community.icinga.com/letter_avatar_proxy/v4/letter/g/67e7ee/32.png) [@glober](https://community.icinga.com/u/glober)\
**Post date:** [May 18, 2022, 1:59pm UTC](https://community.icinga.com/t/problem-setting-up-email-notification-mail-host-notification/9857/1 "2022-05-18T13:59:59Z")

</div>

Hello,

I am currently configuring email notification on an Icinga 2 server, but run into a problem on the final step.  
After spending lots of hours troubleshooting, I hope that I can get some external input as I have no clue what exactly is the problem.

To begin with:  
I have made sure that the server itself is able to sent outbound email from the CLI.  
Therefore I have configured mutt as root and run the following command to check if its working:

```auto
/usr/bin/printf "This is the body text" | mutt \
	-e "set content_type=text/html" \
	-s "This is the subject" \
	my@mailaddress.com

```

A few seconds later I can see this email in my inbox - so no problem.

Then I have edited the mailscript /etc/icinga2/scripts/mail-host-notification.sh and changed it, so that the above command can send the email:

```auto
[...]
#Do not remove -e 'my_hdr From:', This is used for setting 'from' address in mutt
/usr/bin/printf "%b" "$template" | mutt -e "set content_type=text/html" -e 'my_hdr From:Icinga Monitoring<icinga@maildomain.com>' -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME is $HOSTSTATE" $USEREMAIL
[...]

```

Then I followed this guide ( [https://andreas.scherbaum.la/blog/archives/1101-How-to-configure-notifications-in-Icinga2-Director.html](https://andreas.scherbaum.la/blog/archives/1101-How-to-configure-notifications-in-Icinga2-Director.html) ) to create:

1. a time period “always” in: Icinga Director → Timeperiods → Timeperiods
2. a user template “generic-director-user-template” in: Icinga Director → Users/Contacts → User Templates and addes all states and transition types
3. a new user with the same email, which I tested as recipient in CLI before in: Icinga Director → Users/Contacts → Users/Contacts
4. Checked external commands for mail-host-notification in: Icinga Director → Commands → External Commands and made sure that it points to the correct file located at: /etc/icinga2/scripts/mail-host-notification.sh
5. Created a notification template “host-notification-default-template” in: Icinga Director → Notifications → Notification Templates and pointed it to the external notification command (mail-host-notification) and addes states and transition types
6. Created a “host notification” in: Icinga Director → Notifications → Notifications and importing the notification template and added the created user and set “Apply to” to Hosts and configuring the time period which I created. Additionally I set Assign where to “host enable\_notifications = is true (or set)”

If I now click on deployment I get an error in the deployment log.  
If I disable the created host notification which I created in step 6 by setting Disabled to True the deployment run will work.

```auto
[2022-05-18 14:51:38 +0200] information/cli: Icinga application loader (version: 2.13.0-1)
[2022-05-18 14:51:38 +0200] information/cli: Loading configuration file(s).
[2022-05-18 14:51:38 +0200] information/ConfigItem: Committing config item(s).
[2022-05-18 14:51:38 +0200] information/ApiListener: My API identity: vsrv-icinga-4.intern.DOMAIN.COM
[2022-05-18 14:51:39 +0200] critical/config: Error: Validation failed for object 'ITSWI02!E-Mails (Hosts)' of type 'Notification'; Attribute 'command': Object 'mail-host-notification' of type 'NotificationCommand' does not exist.
Location: in [stage]/zones.d/master/notification_templates.conf: 2:5-2:38
[stage]/zones.d/master/notification_templates.conf(1): template Notification "Notification Template E-Mail Host" {
[stage]/zones.d/master/notification_templates.conf(2): command = "mail-host-notification"
                                                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[stage]/zones.d/master/notification_templates.conf(3): states = [Down, Up]

```

I have looked into /var/lib/icinga2/api/zones/master/director/notification\_templates.conf

```auto
template Notification "host-notification-default-template" {
    command = "mail-host-notification"
    states = [Down, Up]
    types = [
        Acknowledgement,
        Custom,
        DowntimeEnd,
        DowntimeRemoved,
        DowntimeStart,
        FlappingEnd,
        FlappingStart,
        Problem,
        Recovery
    ]
}

template Notification "E-Mail (Service)" {
    command = "mail-service-notification"
    states = [Critical, OK, Unknown, Warning]
    types = [
        Acknowledgement,
        Custom,
        DowntimeEnd,
        DowntimeRemoved,
        DowntimeStart,
        FlappingEnd,
        FlappingStart,
        Problem,
        Recovery
    ]
}

```

If I do a locate lookup just for mail-host-notification I only get the following results:

/etc/icinga2/scripts/mail-host-notification.sh

Am I maybe missing a file which links the command “mail-host-notification” to the script located at /etc/icinga2/scripts/mail-host-notification.sh ?

Any suggestions would be helpfull.  
Kind regards from germany

- Pit

---

<div class="post-metadata">

**Author:** ![rivad](https://community.icinga.com/user_avatar/community.icinga.com/rivad/32/5852_2.png) [@rivad](https://community.icinga.com/u/rivad)\
**Post date:** [May 18, 2022, 4:25pm UTC](https://community.icinga.com/t/problem-setting-up-email-notification-mail-host-notification/9857/2 "2022-05-18T16:25:30Z")

</div>

Welcome @glober

Try to create a new mail-host-notification command and use the external command as import.

Maybe rerun the “Director Kickstart Wizard”.

Also if you check if a mail can be send on the cli it would be wise to not do this as root but as the user icinga runs under.
