Activities

October 2010
M T W T F S S
« Sep   Nov »
 123
45678910
11121314151617
18192021222324
25262728293031

Nagios with SMTP outgoing authentications

My requirement is that few of my critical notification mails are not delivered to my gamil and yahoo id. After further checking it has been found that those mails are treated as spam. I need all my nagios alert mails should free from spam filtration.

So I decided to use trusted SMTP server to use my nagios notification mails. Also configure postfix as relay mail server using external smtp.

This process utilizes a perl script called “sendEmail”.

1) Download from http://caspian.dotconf.net/menu/Software/SendEmail.
2) Extract the file and copy the sendEmail into /usr/local/bin.
3)

#chmod +x /usr/local/bin/sendEmail

.

Now the setup and customization of Nagios.

1) Edit

# vi /usr/local/nagios/etc/resource.cfg

– add the following 3 new entries.

$USER5$=email_address
$USER6$=password
$USER7$=SMTP server ip

2) Edit

#vi /usr/local/nagios/etc/objects/commands.cfg

Change command_line for command_name notify-host-by-email:

Change/replace host-notify-email and service-notify-email command with the following lines.command_line for command_name notify-service-by-email:

# 'notify-host-by-email' command definition
define command{
        command_name    notify-host-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n" | /usr/bin/sendEmail -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" -m "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$nHost: $HOSTNAME$nState: $HOSTSTATE$nAddress: $HOSTADDRESS$nInfo: $HOSTOUTPUT$nnDate/Time: $LONGDATETIME$n"
        }

# 'notify-service-by-email' command definition
define command{
command_name    notify-service-by-email
command_line /usr/bin/printf "%b" "***** Nagios *****nnNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$i\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/sendEmail -s $USER7$ -xu $USER5$ -xp $USER6$ -t $CONTACTEMAIL$ -f $USER5$ -l /var/log/sendEmail -u "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" -m "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\n\nHost: $HOSTALIAS$\n\nAddress: $HOSTADDRESS$\n\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$"
}

You can get the exact code from here as certain characters may miss while copying.

3)

#touch /var/log/sendEmail

4)

#chown nagios:nagios /var/log/sendEmail

5) Now restart Nagios service

Testing:

Go into Nagios and set a false service in it. and check the the file entries

/var/log/sendEmail

log file. you should see something like “Email was sent successfully”.

6 comments to Nagios with SMTP outgoing authentications

  • akash

    Not working for me, I am using gmail server account

    • hello,

      Use a standard SMTP account which using the port 25 and having smtp authentication enabled. Gmail using enhanced SMTP service which won’t wont work for you. Also gmail has limited smtp relay (250/day).

  • Eddie

    I’m getting the following error messages when trying to use Gmail:

    sendEmail[15866]: NOTICE => Authentication not supported by the remote SMTP server!
    sendEmail[15866]: NOTICE => Authentication not supported by the remote SMTP server!

    I’m on a Red Hat 6 64bit and just finished installing “sendEmail” from the instructions above.

  • Eddie

    errrr., K, I just saw this will not work with Gmail. Any suggestions for another comparable email service out there that would work?

    Thanks

  • Eddie

    I got it to work! I was missing the Perl Modules Net::SSLeay and IO::Socket::SSL which I installed and it works perfectly!

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>