Docker-Nagios
Docker-Nagios copied to clipboard
mail: cannot stat /root/.mail Permission denied
Hi, anyone have setup the email notifications?
I have not been able either, @JasonRivers any guidance on this topic?
I have a custom script for this currently, Perhaps I should include it in the container,
my custom script looks like this:
#!/bin/bash
NOTIFICATION_TYPE=$1
if [ "$NOTIFICATION_TYPE" = "service" ]; then
## This is a service notification
SUBJECT="[NAGIOS] ${NAGIOS_NOTIFICATIONTYPE}: ${NAGIOS_SERVICEDESC} on ${NAGIOS_HOSTNAME} is ${NAGIOS_SERVICESTATE}"
MAILBODY="***** Nagios *****\n\nNotification Type: ${NAGIOS_NOTIFICATIONTYPE}\n\nHost\n\nService: ${NAGIOS_SERVICEDESC}\nHost: ${NAGIOS_HOSTNAME}\nAddress: ${NAGIOS_HOSTADDRESS}\nState: ${SERVICESTATE}\n\nDate/Time: ${NAGIOS_LONGDATETIME}\n\nAdditional Info:\n\n${NAGIOS_SERVICEOUTPUT}"
else
## This is a host notification
SUBJECT="[NAGIOS] ${NAGIOS_NOTIFICATIONTYPE}: ${NAGIOS_HOSTNAME} is ${NAGIOS_HOSTSTATE}"
MAILBODY="***** Nagios *****\n\nNotification Type: $NAGIOS_NOTIFICATIONTYPE\n\nHost: $NAGIOS_HOSTNAME\nAddress: $NAGIOS_HOSTADDRESS\nState: $NAGIOS_HOSTSTATE\n\nDate/Time: $NAGIOS_LONGDATETIME\n\nAdditional Info:\n\n$NAGIOS_HOSTOUTPUT"
fi
if [ ${NAGIOS_CONTACTEMAIL} ]; then
MAILFROM="Nagios Monitor <[email protected]>"
/usr/sbin/sendmail -t -i -f "$MAILFROM" <<EOF
From: $MAILFROM
To: $NAGIOS_CONTACTEMAIL
Subject: $SUBJECT
$MAILBODY
EOF
fi
My notify_commands.cfg has this:
define command {
command_name notify-service-by-email
command_line $USER4$/notify_by_email service
}
and the following in contacts.cfg:
define contact {
contact_name JasonEmail
alias Jason Rivers (Email)
use Email
email [email protected]
contact_groups Admins
service_notification_period WorkHours
host_notification_period WorkHours
}
I have a separate contact for services that I want to be notified of 24/7, along with XMPP notifications and SMS notifications.
Hopefully this helps get you up and running, I'll see about including the notify_by_email script within the image
thank you @JasonRivers, I also notice that I was not even able to "sendmail" from the container because it's in a Corporate Network so I also had to update Postfix (/etc/postfix/main.cf) to include myhostname = [linuxboxURL] relayhost = [corporateSMTPServerURL]
Hope this also helps other people