JasonRivers / Docker-Nagios

Docker image for Nagios
MIT License
231 stars 253 forks source link

How to change the sender nagios@nagios #126

Open SirTerrific opened 2 years ago

SirTerrific commented 2 years ago

Hi, I would like to understand how to modify the sender of the email notification. I have nagios@nagios.

I setuped the variables from the compose correctly with my information "fqdn and relay".

Obviously, all mail notification email a rejected from my smtp.

Also I'm a rookie with nagios and postfix.

Thanks for your work.

braytonstafford commented 2 years ago

Hello,

In my commands.cfg file there are commands defined for notify-host-by-email and notify-service-by-email.

For each of the command_line definitions for these two commands I added a -a switch with the from address I wanted (ie: -a "From: nagios@mydomain.com")

It would be awesome to have an optional docker environment variable for POSTFIX_HOSTNAME that would set the myhostname= configuration property in the /etc/postfix/main.cf because I believe this is where the default sending email address is coming from.

But this is a workaround that's working for me and I hope it helps:

# 'notify-host-by-email' command definition
define command {
    command_name    notify-host-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -a "From: nagios@mydomain.com" -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

# 'notify-service-by-email' command definition
define command {
        command_name    notify-service-by-email
    command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /usr/bin/mail -a "From: nagios@mydomain.com" -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}