Configuring nagios emails to gmail

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
SaltyBear
Posts: 20
Joined: Mon Apr 25, 2016 6:32 am

Configuring nagios emails to gmail

Post 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?
User avatar
rhassing
Posts: 416
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Configuring nagios emails to gmail

Post by rhassing »

Is it possible to send an email from the command line?
Rob Hassing
Image
SaltyBear
Posts: 20
Joined: Mon Apr 25, 2016 6:32 am

Re: Configuring nagios emails to gmail

Post 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
User avatar
rhassing
Posts: 416
Joined: Sat Oct 05, 2013 10:29 pm
Location: Netherlands

Re: Configuring nagios emails to gmail

Post 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/
Rob Hassing
Image
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Configuring nagios emails to gmail

Post 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?
Former Nagios Employee
SaltyBear
Posts: 20
Joined: Mon Apr 25, 2016 6:32 am

Re: Configuring nagios emails to gmail

Post 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.
Locked