Jump to content

nagios email and cell notifications


Recommended Posts

Posted

Hello Forum:

 

I am trying to set up nagios to send email and text (to cell phone) notifications.

I have installed nagios 3.0.3 on Centos 5 and it is working well. I also installed ssmtp.

 

Regarding the ssmtp.conf file, I am not sure if I have it configured correctly.

These are my settings in the ssmtp.conf file:

 

[email protected]

RewriteDomain=nagios monitoring system

hostname=penguin

 

I tried the following from the command line, but nothing happens:

 

[root@penguin ssmtp]# mail -s "Test" root

Cc: [email protected].

Null message body; hope that's ok

You have new mail in /var/spool/mail/root

 

My command.cfg is as follows:

 

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/ssmtp -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

}

 

 

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$" | /usr/bin/ssmtp -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

}

 

 

I have looked at various threads about this, but none really explains me how to get this working. Some of the threads I have seen are:

 

Nagios -> Email Arghhhh! by ICTNUT

 

Re: Installing Nagios... what do you want to know?

 

and

Quick Nagios Problem

 

 

Please someone help me.

Thanks.

wbens

Posted (edited)
I tried the following from the command line, but nothing happens:

 

[root@penguin ssmtp]# mail -s "Test" root

Cc: [email protected].

Null message body; hope that's ok

You have new mail in /var/spool/mail/root

 

something did happen, you have an empty email in /var/spool/mail/root

have a look by reading that file ( cat /var/spool/mail/root )

 

If it looks like your getting what you want then you probably just need to setup your Mail Transfer Agent (MTA) The default is sendmail on centos, but I usually replace it with postfix.

 

yum remove sendmail

yum install postfix

 

take a look here

Postfix Basic Configuration

you probably just need to configure a relay (relayhost = xxx.xxx.xxx.xxx) in main.cf and maybe add an alias in /etc/aliases but it will depend on your local config. sorry I can't remember sendmail, and I don't know about ssmtp

 

edit: ok I just googled ssmtp, try the cat /var/spool/mail/root to see if nagios is ok

Edited by CyberNerd
Posted

Hello there:

 

Thanks for your response.

I am trying to get emails using both ssmtp or mailx. Whichever works first, I am sticking to it.

 

This is what I am running on the command line as a test:

 

[root@penguin etc]# /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 **" [email protected]

[root@penguin etc]#

 

 

This does not show any errors. It just returns to the prompt.

 

Using ssmtp, this is what I get:

 

[root@penguin etc]# /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: NOTIFICATIONTYPE\nHost: HOSTNAME\nState: HOSTSTATE\nAddress: HOSTADDRESS\nInfo: HOSTOUTPUT\n\nDate/Time: LONGDATETIME\n" | /usr/sbin/ssmtp -s "** NOTIFICATIONTYPE Host Alert: HOSTNAME is HOSTSTATE **" [email protected]

ssmtp: Cannot open willie@myemail:25

[root@penguin etc]#

 

I am completely clueless. Please, please, please help.

Posted

Indeed, your MTA is unconfigured, you need to fix that first before nagios is going to be able to send you mail.

 

Currently you're sendmail is doing local mail only, you'll probably want to configure it to use a smarthost (unless you can make direct SMTP connections). If you stick with sendmail edit /etc/mail/sendmail.mc, find the line which looks something like:

dnl # Uncomment and edit the following line if your outgoing mail needs to
dnl # be sent out through an external mail server:
dnl # 
define(`SMART_HOST',`some.smart.host') 

 

And edit it with your smarthost, for instance I've got:

define(`SMART_HOST',`mail.wildern.hants.sch.uk')

 

You then need to compile(?) your config using m4, do something like:

jim@veestar:~$ m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

 

Then reload the MTA config

jim@veestar:~$ /etc/init.d/sendmail reload

 

Incidentily, nagios should send you mail out of the box if your MTA is working, and you might want to specify some aliases.

 

jim@veestar:~$ cat /etc/aliases | grep root
...
root:           [email protected]

 

And use

newaliases

to load the modifications.

Posted (edited)

Hello Guys:

 

Thanks a lot for your feedback on this matter. I have followed your instructions, but I think it is not yet working.

 

Here are the things I have done on the command line:

 

[root@penguin mail]# /etc/init.d/sendmail reload

reloading sendmail: [ OK ]

reloading sm-client: [ OK ]

 

[root@penguin mail]# /usr/sbin/ssmtp -s TEST [email protected] < /dev/null

ssmtp: Cannot open [email protected]:25

 

I then check on port 25:

 

[root@penguin mail]# lsof -i tcp:25

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

sendmail 25003 root 4u IPv4 6455510 TCP penguin.com:smtp (LISTEN)

 

and killed the process:

 

[root@penguin mail]# kill -9 25003

 

Same result again:

 

[root@penguin mail]# /usr/sbin/ssmtp -s TEST [email protected] < /dev/null

ssmtp: Cannot open [email protected]:25

 

Check on port 25, and nothing was listening on it:

 

[root@penguin mail]# lsof -i tcp:25

 

Restarted services:

 

[root@penguin mail]# /etc/init.d/sendmail restart

Shutting down sm-client: [ OK ]

Shutting down sendmail: [FAILED]

Starting sendmail: [ OK ]

Starting sm-client: [ OK ]

 

Check on port 25 one more time, and things were listening on it:

 

[root@penguin mail]# lsof -i tcp:25

COMMAND PID USER FD TYPE DEVICE SIZE NODE NAME

sendmail 25074 root 4u IPv4 6456172 TCP penguin.com:smtp (LISTEN)

sendmail 25075 root 10u IPv6 6456209 TCP penguin.com:tappi-boxnet->mx00.perfora.net:smtp (ESTABLISHED)

sendmail 25075 root 11u IPv6 6456209 TCP penguin.com:tappi-boxnet->mx00.perfora.net:smtp (ESTABLISHED)

sendmail 25075 root 12u IPv6 6456213 TCP penguin.com:maincontrol->mx01.perfora.net:smtp (ESTABLISHED)

sendmail 25075 root 15u IPv6 6456213 TCP penguin.com:maincontrol->mx01.perfora.net:smtp (ESTABLISHED)

 

Followed one of your commands and got the ssmtp: Cannot open [email protected]:25 response:

 

[root@penguin mail]# /usr/sbin/ssmtp -s TEST [email protected] < /dev/null

ssmtp: Cannot open [email protected]:25

 

I then tried testing this nagios command:

 

[root@penguin mail]# /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 **" [email protected]

[root@penguin mail]#

 

However, I did not get any email.

 

This is my sendmail.cf file:

 

divert(-1)dnl

dnl #

dnl # make -C /etc/mail

dnl #

include(`/usr/share/sendmail-cf/m4/cf.m4')dnl

VERSIONID(`setup for linux')dnl

OSTYPE(`linux')dnl

dnl #

dnl # Do not advertize sendmail version.

dnl #

dnl define(`confSMTP_LOGIN_MSG', `$j Sendmail; $b')dnl

dnl define(`confLOG_LEVEL', `9')dnl

dnl define(`SMART_HOST', `smtp.1and1.com')dnl

 

define(`confDEF_USER_ID', ``8:12'')dnl

dnl define(`confAUTO_REBUILD')dnl

define(`confTO_CONNECT', `1m')dnl

define(`confTRY_NULL_MX_LIST', `True')dnl

define(`confDONT_PROBE_INTERFACES', `True')dnl

define(`PROCMAIL_MAILER_PATH', `/usr/bin/procmail')dnl

define(`ALIAS_FILE', `/etc/aliases')dnl

define(`STATUS_FILE', `/var/log/mail/statistics')dnl

define(`UUCP_MAILER_MAX', `2000000')dnl

define(`confUSERDB_SPEC', `/etc/mail/userdb.db')dnl

define(`confPRIVACY_FLAGS', `authwarnings,novrfy,noexpn,restrictqrun')dnl

define(`confAUTH_OPTIONS', `A')dnl

 

dnl define(`confAUTH_OPTIONS', `A p')dnl

 

dnl TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl

 

dnl define(`confCACERT_PATH', `/etc/pki/tls/certs')dnl

dnl define(`confCACERT', `/etc/pki/tls/certs/ca-bundle.crt')dnl

dnl define(`confSERVER_CERT', `/etc/pki/tls/certs/sendmail.pem')dnl

dnl define(`confSERVER_KEY', `/etc/pki/tls/certs/sendmail.pem')dnl

 

dnl define(`confDONT_BLAME_SENDMAIL', `groupreadablekeyfile')dnl

 

dnl define(`confTO_QUEUEWARN', `4h')dnl

dnl define(`confTO_QUEUERETURN', `5d')dnl

dnl define(`confQUEUE_LA', `12')dnl

dnl define(`confREFUSE_LA', `18')dnl

define(`confTO_IDENT', `0')dnl

dnl FEATURE(delay_checks)dnl

FEATURE(`no_default_msa', `dnl')dnl

FEATURE(`smrsh', `/usr/sbin/smrsh')dnl

FEATURE(`mailertable', `hash -o /etc/mail/mailertable.db')dnl

FEATURE(`virtusertable', `hash -o /etc/mail/virtusertable.db')dnl

FEATURE(redirect)dnl

FEATURE(always_add_domain)dnl

FEATURE(use_cw_file)dnl

FEATURE(use_ct_file)dnl

 

dnl define(`confMAX_DAEMON_CHILDREN', `20')dnl

dnl define(`confCONNECTION_RATE_THROTTLE', `3')dnl

 

FEATURE(local_procmail, `', `procmail -t -Y -a $h -d $u')dnl

FEATURE(`access_db', `hash -T -o /etc/mail/access.db')dnl

FEATURE(`blacklist_recipients')dnl

EXPOSED_USER(`root')dnl

 

dnl define(`confLOCAL_MAILER', `cyrusv2')dnl

dnl define(`CYRUSV2_MAILER_ARGS', `FILE /var/lib/imap/socket/lmtp')dnl

 

DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl

dnl DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl

 

dnl DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl

dnl DAEMON_OPTIONS(`port=smtp,Addr=::1, Name=MTA-v6, Family=inet6')dnl

 

dnl DAEMON_OPTIONS(`Name=MTA-v4, Family=inet, Name=MTA-v6, Family=inet6')

FEATURE(`accept_unresolvable_domains')dnl

 

dnl FEATURE(`relay_based_on_MX')dnl

LOCAL_DOMAIN(`localhost.localdomain')dnl

 

dnl MASQUERADE_AS(`mydomain.com')dnl

dnl FEATURE(masquerade_envelope)dnl

dnl FEATURE(masquerade_entire_domain)dnl

 

dnl MASQUERADE_DOMAIN(localhost)dnl

dnl MASQUERADE_DOMAIN(localhost.localdomain)dnl

dnl MASQUERADE_DOMAIN(mydomainalias.com)dnl

dnl MASQUERADE_DOMAIN(mydomain.lan)dnl

MAILER(smtp)dnl

MAILER(procmail)dnl

dnl MAILER(cyrusv2)dnl

 

I followed all the steps you guys instructed me. Do you have any idea as to why this is not working yet?

 

Thanks guys.

--Willie

Edited by wbens
Posted

Hello again:

 

I have made a couple of changes on my ssmtp.conf file. Here they are:

 

root=admin

mailhub=smtp.1and1.com

RewriteDomain=1and1.com

FromLineOverride=YES

 

Then I restart sendmail, and when I ran the command, here is the response I got:

[root@penguin ssmtp]# /usr/sbin/ssmtp -s TEST [email protected] < /dev/null

ssmtp: RCPT TO: (550 must be authenticated)

 

I will google for this to see what I come up with, but if you have any ideas, please let me know.

 

Thanks.

Posted

Hello Guys:

 

This is to let you know that I am getting email sent from nagios to my hotmail address. However, when I send to my outlook address (my email at work), I do not get anything. I guess that should be a problem with my outlook configuration.

 

Now, I am working on getting messages sent to cell phones. If you have any suggestions on this, please let me know.

 

Thanks.

--Willie

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...