Issues getting email notification working

Hello,

I’m new to icinga and trying to get email notifications working for icinga2. I followed this guide and I do not get it running: https://andreas.scherbaum.la/post/2021-11-10_how-to-configure-notifications-in-icinga2-director/

Email itself can be sent by the sent by the server and are also received by the relay exchange server.

Give as much information as you can, e.g.

  • Version used (r2.16.1-1)
  • Operating System and version (ubuntu 26.04)
  • Enabled features: (api checker icingadb mainlog notification)
  • Icinga Web 2 version and modules (System - About) 2.13.0
  • Config validation (icinga2 daemon -C)

root@icinga2host:/etc/icinga2/scripts# icinga2 daemon -C
[2026-06-02 13:41:51 +0200] information/cli: Icinga application loader (version: r2.16.1-1)
[2026-06-02 13:41:51 +0200] information/cli: Loading configuration file(s).
[2026-06-02 13:41:51 +0200] information/ConfigItem: Committing config item(s).
[2026-06-02 13:41:51 +0200] information/ApiListener: My API identity: icinga2host
[2026-06-02 13:41:51 +0200] warning/Checkable: CheckCommand ‘disk-windows’ used by ‘lt-leibert.whberlin.local!check disk plugin test’ (in /var/lib/icinga2/api/packages/director/80be558f-e367-4bd1-aa80-8d145b1bb9d4/zones.d/icinga2host/services.conf: 17:1-17:39) is DEPRECATED and will be removed in v2.18. Further uses of this check command won’t be logged.
[2026-06-02 13:41:51 +0200] warning/ApplyRule: Apply rule ‘mail-icingaadmin’ (in /etc/icinga2/conf.d/notifications.conf: 23:1-23:48) for type ‘Notification’ does not match anywhere!
[2026-06-02 13:41:51 +0200] warning/ApplyRule: Apply rule ‘mail-icingaadmin’ (in /etc/icinga2/conf.d/notifications.conf: 11:1-11:45) for type ‘Notification’ does not match anywhere!
[2026-06-02 13:41:51 +0200] warning/ApplyRule: Apply rule ‘backup-downtime’ (in /etc/icinga2/conf.d/downtimes.conf: 5:1-5:52) for type ‘ScheduledDowntime’ does not match anywhere!
[2026-06-02 13:41:51 +0200] warning/ApplyRule: Apply rule ‘apt’ (in /etc/icinga2/conf.d/apt.conf: 1:0-1:18) for type ‘Service’ does not match anywhere!
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 6 NotificationCommands.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 7 Notifications.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 IcingaApplication.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 2 HostGroups.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 2 Hosts.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 IcingaDB.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 FileLogger.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 4 Zones.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 CheckerComponent.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 2 Endpoints.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 ApiUser.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 ApiListener.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 NotificationComponent.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 280 CheckCommands.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 4 TimePeriods.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 3 Users.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 1 UserGroup.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 5 Services.
[2026-06-02 13:41:51 +0200] information/ConfigItem: Instantiated 3 ServiceGroups.
[2026-06-02 13:41:51 +0200] information/ScriptGlobal: Dumping variables to file ‘/var/cache/icinga2/icinga2.vars’
[2026-06-02 13:41:51 +0200] information/cli: Finished validating the configuration file(s).

I followed the complete guide but I have no idea why it is not working. Can somebody maybe assist me or tell me how to get verbose output from the mail-host-notification.sh to syslog?

Thank you in advance.

Best regards,

Fabian

You can find in the log - i think the debug log - the exact notification command that has been run.

Neither of these Notifications will be sent, as the condition of the apply rule finds no match.

Hello,

I found this in the /var/log/icinga2/icinga2.log

[2026-06-02 14:51:48 +0200] warning/PluginNotificationTask: Notification command for object ‘lt-leibert.whberlin.local!check disk plugin test’ (PID: 147548, arguments: ‘/etc/icinga2/scripts/mail-host-notifications.sh’) terminated with exit code 128, output: execvpe(/etc/icinga2/scripts/mail-host-notifications.sh) failed: No such file or directory

But the script is there.

root@icinga2host:/etc/icinga2/scripts# ls /etc/icinga2/scripts/
host-by-mail.sh host-by-mail.sh.bak mail-host-notification.sh mail-service-notification.sh service-by-mail.sh service-by-mail.sh.bak

Did I enter it correctly here?

“s” or no “s”, that is the question :wink:

/var/log/icinga2/debug.log:

[2026-06-03 07:58:50 +0200] notice/Notification: Attempting to send notifications of type ‘Problem’ for notification object ‘lt-hostname.randomized-domain.local!CheckPartitionSpace!Service Notification’.
[2026-06-03 07:58:50 +0200] debug/Notification: Type ‘Problem’, TypeFilter: Acknowledgement, Custom, DowntimeEnd, DowntimeRemoved, DowntimeStart, FlappingEnd, FlappingStart, Problem and Recovery (FType=32, TypeFilter=511)
[2026-06-03 07:58:50 +0200] debug/Notification: State ‘Warning’, StateFilter: Critical, OK, Unknown and Warning (FState=2, StateFilter=15)
[2026-06-03 07:58:50 +0200] debug/Notification: User ‘alerting-user’ notification ‘lt-hostname.randomized-domain.local!CheckPartitionSpace!Service Notification’, Type ‘Problem’, TypeFilter: Acknowledgement, Custom, DowntimeEnd, DowntimeRemoved, DowntimeStart, FlappingEnd, FlappingStart, Problem and Recovery (FType=32, TypeFilter=511)
[2026-06-03 07:58:50 +0200] debug/Notification: User ‘alerting-user’ notification ‘lt-hostname.randomized-domain.local!CheckPartitionSpace!Service Notification’, State ‘Warning’, StateFilter: Critical, Down, OK, Unknown, Up and Warning (FState=2, StateFilter=63)
[2026-06-03 07:58:50 +0200] information/Notification: Sending ‘Problem’ notification ‘lt-hostname.randomized-domain.local!CheckPartitionSpace!Service Notification’ for user ‘alerting-user’
[2026-06-03 07:58:50 +0200] debug/JsonRpcConnection: Processed JSON-RPC ‘event::CheckResult’ message for identity ‘lt-hostname.randomized-domain.local’ (took total 0ms).
[2026-06-03 07:58:50 +0200] notice/ApiListener: Relaying ‘event::SetNextCheck’ message
[2026-06-03 07:58:50 +0200] notice/ApiListener: Relaying ‘event::CheckResult’ message
[2026-06-03 07:58:50 +0200] notice/ApiListener: Relaying ‘event::SendNotifications’ message
[2026-06-03 07:58:50 +0200] notice/ApiListener: Relaying ‘event::SetForceNextNotification’ message
[2026-06-03 07:58:50 +0200] notice/ApiListener: Relaying ‘event::UpdateLastNotifiedStatePerUser’ message
[2026-06-03 07:58:50 +0200] notice/ApiListener: Relaying ‘event::NotificationSentToAllUsers’ message
[2026-06-03 07:58:50 +0200] notice/Process: Running command ‘/etc/icinga2/scripts/mail-host-notification.sh’: PID 6630
[2026-06-03 07:58:50 +0200] information/Notification: Completed sending ‘Problem’ notification ‘lt-hostname.randomized-domain.local!CheckPartitionSpace!Service Notification’ for checkable ‘lt-hostname.randomized-domain.local!CheckPartitionSpace’ and user ‘alerting-user’ using command ‘Notify Hosts verbose’.
[2026-06-03 07:58:50 +0200] notice/ApiListener: Relaying ‘event::NotificationSentUser’ message
[2026-06-03 07:58:50 +0200] notice/Process: PID 6630 (‘/etc/icinga2/scripts/mail-host-notification.sh’) terminated with exit code 1
[2026-06-03 07:58:50 +0200] warning/PluginNotificationTask: Notification command for object ‘lt-hostname.randomized-domain.local!CheckPartitionSpace’ (PID: 6630, arguments: ‘/etc/icinga2/scripts/mail-host-notification.sh’) terminated with exit code 1, output: Required parameter ‘LONGDATETIME’ is missing.

Required parameters:
-d LONGDATETIME ($icinga.long_date_time$)
-l HOSTNAME ($host.name$)
-n HOSTDISPLAYNAME ($host.display_name$)
-o HOSTOUTPUT ($host.output$)
-r USEREMAIL ($user.email$)
-s HOSTSTATE ($host.state$)
-t NOTIFICATIONTYPE ($notification.type$)

Optional parameters:
-4 HOSTADDRESS ($address$)
-6 HOSTADDRESS6 ($address6$)
-X HOSTNOTES ($host.notes$)
-b NOTIFICATIONAUTHORNAME ($notification.author$)
-c NOTIFICATIONCOMMENT ($notification.comment$)
-i ICINGAWEB2URL ($notification_icingaweb2url$, Default: unset)
-f MAILFROM ($notification_mailfrom$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
-v ($notification_sendtosyslog$, Default: false)

/var/log/icinga2/icinga2.log

[2026-06-03 07:58:18 +0200] information/Notification: Sending ‘Problem’ notification ‘lt-hostname.randomized-domain.local!check disk plugin test!Service Notification’ for user ‘alerting-user’
[2026-06-03 07:58:18 +0200] information/Notification: Completed sending ‘Problem’ notification ‘lt-hostname.randomized-domain.local!check disk plugin test!Service Notification’ for checkable ‘lt-hostname.randomized-domain.local!check disk plugin test’ and user ‘alerting-user’ using command ‘Notify Hosts verbose’.
[2026-06-03 07:58:18 +0200] warning/PluginNotificationTask: Notification command for object ‘lt-hostname.randomized-domain.local!check disk plugin test’ (PID: 6439, arguments: ‘/etc/icinga2/scripts/mail-host-notification.sh’) terminated with exit code 1, output: Required parameter ‘LONGDATETIME’ is missing.

Required parameters:
-d LONGDATETIME ($icinga.long_date_time$)
-l HOSTNAME ($host.name$)
-n HOSTDISPLAYNAME ($host.display_name$)
-o HOSTOUTPUT ($host.output$)
-r USEREMAIL ($user.email$)
-s HOSTSTATE ($host.state$)
-t NOTIFICATIONTYPE ($notification.type$)

Optional parameters:
-4 HOSTADDRESS ($address$)
-6 HOSTADDRESS6 ($address6$)
-X HOSTNOTES ($host.notes$)
-b NOTIFICATIONAUTHORNAME ($notification.author$)
-c NOTIFICATIONCOMMENT ($notification.comment$)
-i ICINGAWEB2URL ($notification_icingaweb2url$, Default: unset)
-f MAILFROM ($notification_mailfrom$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
-v ($notification_sendtosyslog$, Default: false)
[2026-06-03 07:58:50 +0200] information/Checkable: Checkable ‘lt-hostname.randomized-domain.local!CheckPartitionSpace’ has 1 notification(s). Checking filters for type ‘Problem’, sends will be logged.
[2026-06-03 07:58:50 +0200] information/Notification: Sending ‘Problem’ notification ‘lt-hostname.randomized-domain.local!CheckPartitionSpace!Service Notification’ for user ‘alerting-user’
[2026-06-03 07:58:50 +0200] information/Notification: Completed sending ‘Problem’ notification ‘lt-hostname.randomized-domain.local!CheckPartitionSpace!Service Notification’ for checkable ‘lt-hostname.randomized-domain.local!CheckPartitionSpace’ and user ‘alerting-user’ using command ‘Notify Hosts verbose’.
[2026-06-03 07:58:50 +0200] warning/PluginNotificationTask: Notification command for object ‘lt-hostname.randomized-domain.local!CheckPartitionSpace’ (PID: 6630, arguments: ‘/etc/icinga2/scripts/mail-host-notification.sh’) terminated with exit code 1, output: Required parameter ‘LONGDATETIME’ is missing.

Required parameters:
-d LONGDATETIME ($icinga.long_date_time$)
-l HOSTNAME ($host.name$)
-n HOSTDISPLAYNAME ($host.display_name$)
-o HOSTOUTPUT ($host.output$)
-r USEREMAIL ($user.email$)
-s HOSTSTATE ($host.state$)
-t NOTIFICATIONTYPE ($notification.type$)

Optional parameters:
-4 HOSTADDRESS ($address$)
-6 HOSTADDRESS6 ($address6$)
-X HOSTNOTES ($host.notes$)
-b NOTIFICATIONAUTHORNAME ($notification.author$)
-c NOTIFICATIONCOMMENT ($notification.comment$)
-i ICINGAWEB2URL ($notification_icingaweb2url$, Default: unset)
-f MAILFROM ($notification_mailfrom$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
-v ($notification_sendtosyslog$, Default: false)

Do you have an idea why it exits with the error code, that the argument LONGDATETIME was not set?

Well you need to set this. Im not sure whether you are using the director or not.

In the director it would take an argument like this:

Or in Icinga DSL add an -d Argument to the NotificationCommand:

object NotificationCommand "mail-host-notification" {
    import "plugin-notification-command"
    command = [ "/etc/icinga2/scripts/mail-host-notification.sh" ]
    arguments += {
        "-d" = "$icinga.long_date_time$"
    }
}

Hello,

I could solve the issue by adding the arguments.

Now I have a new phenomen:

For every service I get the exact same output message:

The host was never down so it just gives the exact same output for every event.

Does anybody have an idea where this could come from?

got an idea on the problem… can you show the Config of the NotificationCommand

root@icinga2host:~# cat /etc/icinga2/scripts/mail-host-notification.sh
#!/usr/bin/env bash

SPDX-FileCopyrightText: 2012 Icinga GmbH https://icinga.com

SPDX-License-Identifier: GPL-2.0-or-later

Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license

PROG=“basename $0
ICINGA2HOST=“hostname
MAILBIN=“mail”

if [ -z “which $MAILBIN” ] ; then
echo “$MAILBIN not found in $PATH. Consider installing it.”
exit 1
fi

Function helpers

Usage() {
cat << EOF

Required parameters:
-d LONGDATETIME ($icinga.long_date_time$)
-l HOSTNAME ($host.name$)
-n HOSTDISPLAYNAME ($host.display_name$)
-o HOSTOUTPUT ($host.output$)
-r USEREMAIL ($user.email$)
-s HOSTSTATE ($host.state$)
-t NOTIFICATIONTYPE ($notification.type$)

Optional parameters:
-4 HOSTADDRESS ($address$)
-6 HOSTADDRESS6 ($address6$)
-X HOSTNOTES ($host.notes$)
-b NOTIFICATIONAUTHORNAME ($notification.author$)
-c NOTIFICATIONCOMMENT ($notification.comment$)
-i ICINGAWEB2URL ($notification_icingaweb2url$, Default: unset)
-f MAILFROM ($notification_mailfrom$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
-v ($notification_sendtosyslog$, Default: false)

EOF
}

Help() {
Usage;
exit 0;
}

Error() {
if [ “$1” ]; then
echo $1
fi
Usage;
exit 1;
}

urlencode() {
local LANG=C i=0 c e s=“$1”

while [ $i -lt ${#1} ]; do
[ “$i” -eq 0 ] || s=“${s#?}”
c=${s%“${s#?}”}
[ -z “${c#[[:alnum:].~_-]}” ] || c=$(printf ‘%%%02X’ “'$c”)
e=“${e}${c}”
i=$((i + 1))
done
echo “$e”
}

Main

while getopts 4:6::b:c:d:f:hi:l:n:o:r:s:t:v:X: opt
do
case “$opt” in
4) HOSTADDRESS=$OPTARG ;;
6) HOSTADDRESS6=$OPTARG ;;
b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
c) NOTIFICATIONCOMMENT=$OPTARG ;;
d) LONGDATETIME=$OPTARG ;; # required
f) MAILFROM=$OPTARG ;;
h) Help ;;
i) ICINGAWEB2URL=$OPTARG ;;
l) HOSTNAME=$OPTARG ;; # required
n) HOSTDISPLAYNAME=$OPTARG ;; # required
o) HOSTOUTPUT=$OPTARG ;; # required
X) HOSTNOTES=$OPTARG ;;
r) USEREMAIL=$OPTARG ;; # required
s) HOSTSTATE=$OPTARG ;; # required
t) NOTIFICATIONTYPE=$OPTARG ;; # required
v) VERBOSE=$OPTARG ;;
?) echo “ERROR: Invalid option -$OPTARG” >&2
Error ;;
:slight_smile: echo “Missing option argument for -$OPTARG” >&2
Error ;;
*) echo “Unimplemented option: -$OPTARG” >&2
Error ;;
esac
done

shift $((OPTIND - 1))

Keep formatting in sync with mail-service-notification.sh

for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME HOSTOUTPUT HOSTSTATE USEREMAIL NOTIFICATIONTYPE ; do
eval “PAR=$${P}”

    if [ ! "$PAR" ] ; then
            Error "Required parameter '$P' is missing."
    fi

done

Build the message’s subject

SUBJECT=“[$NOTIFICATIONTYPE] Host $HOSTDISPLAYNAME is $HOSTSTATE!”

Build the notification message

NOTIFICATION_MESSAGE=`cat << EOF
***** Host Monitoring on $ICINGA2HOST *****

$HOSTDISPLAYNAME is $HOSTSTATE!

Info: $HOSTOUTPUT

When: $LONGDATETIME
Host: $HOSTNAME
EOF
`

Check whether IPv4 was specified.

if [ -n “$HOSTADDRESS” ] ; then
NOTIFICATION_MESSAGE=“$NOTIFICATION_MESSAGE
IPv4: $HOSTADDRESS”
fi

Check whether IPv6 was specified.

if [ -n “$HOSTADDRESS6” ] ; then
NOTIFICATION_MESSAGE=“$NOTIFICATION_MESSAGE
IPv6: $HOSTADDRESS6”
fi

Check whether host notes was specified.

if [ -n “$HOSTNOTES” ] ; then
NOTIFICATION_MESSAGE=“$NOTIFICATION_MESSAGE
Host notes: $HOSTNOTES”
fi

Check whether author and comment was specified.

if [ -n “$NOTIFICATIONCOMMENT” ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

Comment by $NOTIFICATIONAUTHORNAME:
$NOTIFICATIONCOMMENT"
fi

Check whether Icinga Web 2 URL was specified.

if [ -n “$ICINGAWEB2URL” ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

$ICINGAWEB2URL/icingadb/host?name=$(urlencode “$HOSTNAME”)"
fi

Check whether verbose mode was enabled and log to syslog.

if [ “$VERBOSE” = “true” ] ; then
logger “$PROG sends $SUBJECT => $USEREMAIL”
fi

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” | tr -d ‘\015’
| $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” | tr -d ‘\015’
| $MAILBIN -r “$MAILFROM” -s “$SUBJECT” $USEREMAIL
fi

else
/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE” | tr -d ‘\015’
| $MAILBIN -s “$SUBJECT” $USEREMAIL
fi

I did setup the notifications in the icinga director, therefore I think the configuration is also visible in the director only:

If you meant something else then these configs please tell me what you need.

root@icinga2host:~# cat /etc/icinga2/scripts/mail-service-notification.sh
#!/usr/bin/env bash

SPDX-FileCopyrightText: 2012 Icinga GmbH https://icinga.com

SPDX-License-Identifier: GPL-2.0-or-later

Except of function urlencode which is Copyright (C) by Brian White (brian@aljex.com) used under MIT license

PROG=“basename $0
ICINGA2HOST=“hostname
MAILBIN=“mail”

if [ -z “which $MAILBIN” ] ; then
echo “$MAILBIN not found in $PATH. Consider installing it.”
exit 1
fi

Function helpers

Usage() {
cat << EOF

Required parameters:
-d LONGDATETIME ($icinga.long_date_time$)
-e SERVICENAME ($service.name$)
-l HOSTNAME ($host.name$)
-n HOSTDISPLAYNAME ($host.display_name$)
-o SERVICEOUTPUT ($service.output$)
-r USEREMAIL ($user.email$)
-s SERVICESTATE ($service.state$)
-t NOTIFICATIONTYPE ($notification.type$)
-u SERVICEDISPLAYNAME ($service.display_name$)

Optional parameters:
-4 HOSTADDRESS ($address$)
-6 HOSTADDRESS6 ($address6$)
-X HOSTNOTES ($host.notes$)
-x SERVICENOTES ($service.notes$)
-b NOTIFICATIONAUTHORNAME ($notification.author$)
-c NOTIFICATIONCOMMENT ($notification.comment$)
-i ICINGAWEB2URL ($notification_icingaweb2url$, Default: unset)
-f MAILFROM ($notification_mailfrom$, requires GNU mailutils (Debian/Ubuntu) or mailx (RHEL/SUSE))
-v ($notification_sendtosyslog$, Default: false)

EOF
}

Help() {
Usage;
exit 0;
}

Error() {
if [ “$1” ]; then
echo $1
fi
Usage;
exit 1;
}

urlencode() {
local LANG=C i=0 c e s=“$1”

while [ $i -lt ${#1} ]; do
[ “$i” -eq 0 ] || s=“${s#?}”
c=${s%“${s#?}”}
[ -z “${c#[[:alnum:].~_-]}” ] || c=$(printf ‘%%%02X’ “'$c”)
e=“${e}${c}”
i=$((i + 1))
done
echo “$e”
}

Main

while getopts 4:6:b:c:d:e:f:hi:l:n:o:r:s:t:u:v:X:x: opt
do
case “$opt” in
4) HOSTADDRESS=$OPTARG ;;
6) HOSTADDRESS6=$OPTARG ;;
b) NOTIFICATIONAUTHORNAME=$OPTARG ;;
c) NOTIFICATIONCOMMENT=$OPTARG ;;
d) LONGDATETIME=$OPTARG ;; # required
e) SERVICENAME=$OPTARG ;; # required
f) MAILFROM=$OPTARG ;;
h) Usage ;;
i) ICINGAWEB2URL=$OPTARG ;;
l) HOSTNAME=$OPTARG ;; # required
n) HOSTDISPLAYNAME=$OPTARG ;; # required
X) HOSTNOTES=$OPTARG ;;
x) SERVICENOTES=$OPTARG ;;
o) SERVICEOUTPUT=$OPTARG ;; # required
r) USEREMAIL=$OPTARG ;; # required
s) SERVICESTATE=$OPTARG ;; # required
t) NOTIFICATIONTYPE=$OPTARG ;; # required
u) SERVICEDISPLAYNAME=$OPTARG ;; # required
v) VERBOSE=$OPTARG ;;
?) echo “ERROR: Invalid option -$OPTARG” >&2
Usage ;;
:slight_smile: echo “Missing option argument for -$OPTARG” >&2
Usage ;;
*) echo “Unimplemented option: -$OPTARG” >&2
Usage ;;
esac
done

shift $((OPTIND - 1))

Keep formatting in sync with mail-host-notification.sh

for P in LONGDATETIME HOSTNAME HOSTDISPLAYNAME SERVICENAME SERVICEDISPLAYNAME SERVICEOUTPUT SERVICESTATE USEREMAIL NOTIFICATIONTYPE ; do
eval “PAR=$${P}”

    if [ ! "$PAR" ] ; then
            Error "Required parameter '$P' is missing."
    fi

done

Build the message’s subject

SUBJECT=“[$NOTIFICATIONTYPE] $SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!”

Build the notification message

NOTIFICATION_MESSAGE=`cat << EOF
***** Service Monitoring on $ICINGA2HOST *****

$SERVICEDISPLAYNAME on $HOSTDISPLAYNAME is $SERVICESTATE!

Info: $SERVICEOUTPUT

When: $LONGDATETIME
Service: $SERVICENAME
Host: $HOSTNAME
EOF
`

Check whether IPv4 was specified.

if [ -n “$HOSTADDRESS” ] ; then
NOTIFICATION_MESSAGE=“$NOTIFICATION_MESSAGE
IPv4: $HOSTADDRESS”
fi

Check whether IPv6 was specified.

if [ -n “$HOSTADDRESS6” ] ; then
NOTIFICATION_MESSAGE=“$NOTIFICATION_MESSAGE
IPv6: $HOSTADDRESS6”
fi

Check whether host notes was specified.

if [ -n “$HOSTNOTES” ] ; then
NOTIFICATION_MESSAGE=“$NOTIFICATION_MESSAGE
Host notes: $HOSTNOTES”
fi

Check whether service notes was specified.

if [ -n “$SERVICENOTES” ] ; then
NOTIFICATION_MESSAGE=“$NOTIFICATION_MESSAGE
Service notes: $SERVICENOTES”
fi

Check whether author and comment was specified.

if [ -n “$NOTIFICATIONCOMMENT” ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

Comment by $NOTIFICATIONAUTHORNAME:
$NOTIFICATIONCOMMENT"
fi

Check whether Icinga Web 2 URL was specified.

if [ -n “$ICINGAWEB2URL” ] ; then
NOTIFICATION_MESSAGE="$NOTIFICATION_MESSAGE

$ICINGAWEB2URL/icingadb/service?name=$(urlencode “$SERVICENAME”)&host.name=$(urlencode “$HOSTNAME”)"
fi

Check whether verbose mode was enabled and log to syslog.

if [ “$VERBOSE” = “true” ] ; then
logger “$PROG sends $SUBJECT => $USEREMAIL”
fi

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” | tr -d ‘\015’
| $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” | tr -d ‘\015’
| $MAILBIN -r “$MAILFROM” -s “$SUBJECT” $USEREMAIL
fi

else
/usr/bin/printf “%b” “$NOTIFICATION_MESSAGE” | tr -d ‘\015’
| $MAILBIN -s “$SUBJECT” $USEREMAIL
fi

Thank you for your help.

Could solve the issue. I had the same arguments for check_host as check_service. Therefore I always got the message when a service was checked that the host is up. Thank you all for your help.