Hi,
I’ve been playing around with IcingaWeb2 in the last couple of days.
I want to insert an email notification system where I get emails when there is something wrong.
I have struggled to do that though.
Here are some snippets from my config files.
/etc/icinga2/conf.d/notifications.conf
apply Notification "mail-icingaadmin" to Host {
import "mail-host-notification"
user_groups = [ "icingaadmins" ]
users = host.vars.notification.mail.users
assign where host.address != " users = host.vars.notification.mail.users"
}
apply Notification "mail-icingaadmin" to Service {
import "mail-service-notification"
user_groups = [ "icingaadmins" ]
users = host.vars.notification.mail.users
assign where host.address != ""
}
/etc/icinga2/conf.d/hosts.conf
object Host "svr_testblade" {
import "generic-host"
address = "123.456.123.456"
check_command = "hostalive"
vars.os = "Servers"
vars.notification["mail"] = {
groups = ["icingaadmins"]
users = ["icingaadmin"]
/etc/icinga2/conf.d/users.conf
object User "icingaadmin" {
import "generic-user"
display_name = "Icinga2 Admin"
groups = [ "icingaadmins" ]
email = "myemail@domain.com"
}
object UserGroup "icingaadmins" {
display_name = "Icinga2 Admin Group"
}
/etc/icinga2/scripts/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
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" | $MAILBIN -r "icinga2@domain.com" -s "$SUBJECT" $USERMAIL
fi
else
/usr/bin/printf "%b" "$NOTIFICATION_MESSAGE" \ | $MAILBIN -s "$SUBJECT" $USEREMAIL
fi
template=`cat <<TEMPLATE
***** Icinga EPAY *****
Notification Type: $NOTIFICATIONTYPE
Host: $HOSTALIAS
Address: $HOSTADDRESS
State: $HOSTSTATE
Date/Time: $LONGDATETIME
Additional Info: $HOSTOUTPUT
Comment: [$NOTIFICATIONAUTHORNAME] $NOTIFICATIONCOMMENT
TEMPLATE
`
echo "TEST" | msmtp=myemail@domain.com -s "$NOTIFICATIONTYPE - $HOSTDISPLAYNAME is $HOSTSTATE" $USEREMAIL
#!/bin/sh
Here ist something from the icinga2 log whenever I want to send a forced custom notification.
[2020-06-04 13:59:44 +0200] information/Notification: Sending 'Custom' notification 'svr_testblade!mail-icingaadmin' for user 'icingaadmin'
[2020-06-04 13:59:44 +0200] information/Notification: Completed sending 'Custom' notification 'svr_testblade!mail-icingaadmin' for checkable 'svr_testblade' and user 'icingaadmin'.
[2020-06-04 13:59:44 +0200] information/HttpServerConnection: HTTP client disconnected (from [127.0.0.1]:55712)
[2020-06-04 14:00:44 +0200] warning/Process: Killing process group 24605 ('/etc/icinga2/scripts/mail-host-notification.sh' '-4' '123.456.123.456' '-6' '' '-b' 'bak0523' '-c' 'Test123' '-d' '2020-06-04 13:59:44 +0200' '-l' 'svr_testblade' '-n' 'svr_testblade' '-o' 'PING OK - Packet loss = 0%, RTA = 0.85 ms' '-r' 'gabriel.laszlo@bk-group.eu' '-s' 'UP' '-t' 'CUSTOM' '-v' 'false') after timeout of 60 seconds
[2020-06-04 14:00:44 +0200] warning/Process: PID 24605 was terminated by signal 9 (Killed)
[2020-06-04 14:00:44 +0200] warning/PluginNotificationTask: Notification command for object 'svr_testblade' (PID: 24605, arguments: '/etc/icinga2/scripts/mail-host-notification.sh' '-4' '123.456.123.456' '-6' '' '-b' 'bak0523' '-c' 'Test123' '-d' '2020-06-04 13:59:44 +0200' '-l' 'svr_testblade' '-n' 'svr_testblade' '-o' 'PING OK - Packet loss = 0%, RTA = 0.85 ms' '-r' 'myemail@domain.com' '-s' 'UP' '-t' 'CUSTOM' '-v' 'false') terminated with exit code 128, output: <Timeout exceeded.><Terminated by signal 9 (Killed).>
[2020-06-04 14:00:52 +0200] information/WorkQueue: #5 (IdoMysqlConnection, ido-mysql) items: 1, rate: 3.45/s (207/min 22972/5min 25138/15min);
I did not recive any email. After I tried this a couple of times, i got a mail but from “nagios@monitoring” which I never defined anywhere and i even searched all the configs for nagios and didn’t find any script that adds nagios@ to my Hostname (monitoring).
I would appriciate if someone could help me with this.
Kind regards,
Gabriel Laszlo