rohit01 / docker_shinken

Automated docker builds for shinken images
http://www.rohit.io/blog/rip-nagios-hello-docker-shinken.html
55 stars 41 forks source link

sending mail #25

Closed cornernote closed 6 years ago

cornernote commented 6 years ago

Hello,

It seems that out of the box it doesn't send emails. I have been fiddling for a while looking for a solution that works and can't seem to find anything.

Are you able to put together an example of how you get it to send email?

I added this to Dockerfile:

FROM rohit01/shinken_thruk_graphite:latest

# Install mail requirements
RUN apt-get update
RUN apt-get install -y ssmtp mailutils

# Cleanup
RUN apt-get clean
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

Then added to config:

define command {
    command_name    notify-host-by-gmail
    command_line    echo "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDate/Time: $LONGDATETIME$" | /usr/bin/mail -s "** Nagios $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **"
}

define command {
    command_name    notify-service-by-gmail
    command_line    echo "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info: $SERVICEOUTPUT$" | /usr/bin/mail -s "** Nagios $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **"
}

define notificationway {
    notificationway_name            gmail
    service_notification_period     24x7
    host_notification_period        24x7
    service_notification_options    w,u,c,r,f
    host_notification_options       d,u,r,f,s
    service_notification_commands   notify-service-by-gmail
    host_notification_commands      notify-host-by-gmail
    min_business_impact             1
}

define contact {
    use                             generic-contact
    contact_name                    me
    alias                           Me
    email                           me@example.com
    notificationways                gmail
}

I'm not sure how to check what's wrong, but I'm not getting emails.

I get an email if I do this:

docker-compose exec shinken bash
echo "Hello World" | mail -s "Test Email" me@example.com
cornernote commented 6 years ago

I realised I didnt have $CONTACTEMAIL$ in my command.

Should be:

define command {
    command_name    notify-host-by-gmail
    command_line    echo "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\nDate/Time: $LONGDATETIME$" | /usr/bin/mail -s "** Nagios $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$
}

define command {
    command_name    notify-service-by-gmail
    command_line    echo "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\nDate/Time: $LONGDATETIME$\nAdditional Info: $SERVICEOUTPUT$" | /usr/bin/mail -s "** Nagios $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
}

Now I get emails! Woohoo!