Page 1 of 1

Configuring nagios emails to gmail

Posted: Tue May 17, 2016 3:59 am
by SaltyBear
Hi,

I've been trying to configure my nagios so that it sends notifications to a gmail account.
So far it does not seem to work, I did the following

Code: Select all

sudo apt-get install ssmtp

Code: Select all

#Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
[email protected]
#I recommend setting this 

mailhub=smtp.gmail.com:587

# Where will the mail seem to come from?
rewriteDomain=

#The full hostname
hostname=harenhall.the.realm
UseTLS=YES
UseSTARTTLS=YES
AuthMethod=LOGIN
[email protected]
AuthPass=nagios852

# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
# This is optional if you're going to use revaliases - I didn't
FromLineOverride=YES

Code: Select all

sudo chown root:nagios /etc/ssmtp/ssmtp.conf
sudo chmod 640 /etc/ssmtp/ssmtp.conf

Code: Select all

#'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" | /bin/mail -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" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
        }
Mail.log only contains this

Code: Select all

May 17 11:05:12 lannister sendmail[4550]: alias database /etc/mail/aliases rebuilt by administrator
May 17 11:05:12 lannister sendmail[4550]: /etc/mail/aliases: 0 aliases, longest 0 bytes, 0 bytes total
May 17 11:05:13 lannister sm-mta[4616]: starting daemon (8.14.4): SMTP+queueing@00:10:00
Can anyone help me?

Re: Configuring nagios emails to gmail

Posted: Tue May 17, 2016 4:49 am
by rhassing
Is it possible to send an email from the command line?

Re: Configuring nagios emails to gmail

Posted: Tue May 17, 2016 4:57 am
by SaltyBear
rhassing wrote:Is it possible to send an email from the command line?
I tried it with the command

Code: Select all

echo "testing for nagios alerts"|mail -s "test nagiosalerts" [email protected]
But this returns errors

Code: Select all

mail: Cannot open mailer: No such file or directory
mail: cannot send message: No such file or directory

Re: Configuring nagios emails to gmail

Posted: Tue May 17, 2016 5:09 am
by rhassing
I guess this is not really Nagios related, but maybe you could have a look at:
http://www.linuxquestions.org/questions ... il-874471/

Re: Configuring nagios emails to gmail

Posted: Tue May 17, 2016 10:04 am
by rkennedy
You will need to enable SMTP support in Gmail as well. The fact that it doesn't work over the CLI, means that Nagios for sure won't be able to. The error indicates that you are possibly missing dependencies that SSMTP requires.

Were you following a specific guide to set this up? Can you link us to it?

Re: Configuring nagios emails to gmail

Posted: Thu May 19, 2016 5:59 am
by SaltyBear
You can close this topic, it has been resolved with the help of a classmate :)
Basically I switched to mailx which worked without any problems from the start.