LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-06-2010, 11:03 AM   #1
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Rep: Reputation: 30
[nagios] send emails to gmail when services are down.


Hello,

so as the title says.
these days i've been trying to send emails to my gmail account and it works now.
thanks to those who helped in my previous thread(: [http://www.linuxquestions.org/questi...ubuntu-823461/] much appreciated.
i'm now just short of one thing:
using postfix, how do i make nagios send notifications to my gmail account when any services go down?

i saw this commands for email in commands.cfg:

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

        }
i know that will be the format of the email if i can receive it.


so what am i missing?

i'm very confused regarding this.

thank you.

Last edited by Xanios; 08-06-2010 at 11:05 AM.
 
Old 08-06-2010, 12:10 PM   #2
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 113Reputation: 113
Quote:
these days i've been trying to send emails to my gmail account and it works now.
Great.

If you want to receive nagios notification just define your email id in contacts.cfg file

Code:
vi /usr/local/nagios/etc/object/contacts.cfg

define contact{
        contact_name                    nagiosadmin  
        use                             generic-contact 
        alias                           Nagios Admin    
        email                          nagios@localhost  <= enter your email id here   
}
And the restart nagios service
 
Old 08-06-2010, 09:24 PM   #3
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
Hi,

i already defined my email id in contacts.cfg:

Code:
define contact{
        contact_name                    nagiosadmin             ; Short name of user
        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)
        alias                           Nagios Admin            ; Full name of user
        host_notifications_enabled      1
        service_notifications_enabled   1
        host_notification_period        24x7
        service_notification_options    w,u,c,r
        host_notification_options       d,u,r
        service_notification_commands   notify-service-by-email
        host_notification_commands      notify-host-by-email
        email                           xanios@gmail.com   ; email
        }
i still ain't getting any email notifications ):
 
Old 08-07-2010, 03:04 AM   #4
sem007
Member
 
Registered: Nov 2006
Distribution: RHEL, CentOS, Debian Lenny, Ubuntu
Posts: 638

Rep: Reputation: 113Reputation: 113
Is there any error in nagios.log file as well as mail.log file ?
 
Old 08-07-2010, 06:34 AM   #5
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
Hi,

in my mail.log file (last 20 lines):

Code:
Aug  6 07:42:15 ubuntu postfix/qmgr[6321]: E5AF940A63: from=<>, size=1775, nrcpt=1 (queue active)
Aug  6 07:42:16 ubuntu postfix/smtp[6323]: certificate verification failed for smtp.gmail.com[72.14.213.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Aug  6 07:42:21 ubuntu postfix/smtp[6323]: E5AF940A63: to=<xanios@server.com>, relay=smtp.gmail.com[72.14.213.109]:587, delay=5.3, delays=0.02/0/2.9/2.4, dsn=2.0.0, status=sent (250 2.0.0 OK 1281105742 q27sm1508796wfc.18)
Aug  6 07:42:21 ubuntu postfix/qmgr[6321]: E5AF940A63: removed
Aug  6 07:46:58 ubuntu postfix/qmgr[6321]: 1BA5440A67: from=<xanios@server.com>, size=284, nrcpt=1 (queue active)
Aug  6 07:46:59 ubuntu postfix/smtp[6410]: certificate verification failed for smtp.gmail.com[72.14.213.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Aug  6 07:47:03 ubuntu postfix/smtp[6410]: 1BA5440A67: to=<xanios@gmail.com>, relay=smtp.gmail.com[72.14.213.109]:587, delay=3473, delays=3468/0.06/2.6/2.2, dsn=2.0.0, status=sent (250 2.0.0 OK 1281106024 k23sm2967475waf.5)
Aug  6 07:47:03 ubuntu postfix/qmgr[6321]: 1BA5440A67: removed
Aug  6 18:18:32 ubuntu postfix/master[2396]: daemon started -- version 2.6.5, configuration /etc/postfix
Aug  7 03:28:23 ubuntu postfix/master[2351]: daemon started -- version 2.6.5, configuration /etc/postfix
Aug  7 03:28:26 ubuntu postfix/pickup[2361]: 9CE1240A67: uid=1000 from=<layleng>
Aug  7 03:28:26 ubuntu postfix/cleanup[2543]: 9CE1240A67: message-id=<20100807102826.9CE1240A67@ubuntu>
Aug  7 03:28:26 ubuntu postfix/qmgr[2363]: 9CE1240A67: from=<xanios@server.com>, size=289, nrcpt=1 (queue active)
Aug  7 03:28:28 ubuntu postfix/smtp[2545]: certificate verification failed for smtp.gmail.com[74.125.53.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Aug  7 03:28:33 ubuntu postfix/smtp[2545]: 9CE1240A67: to=<xanios@gmail.com>, relay=smtp.gmail.com[74.125.53.109]:587, delay=6.4, delays=0.2/0.25/3/2.9, dsn=2.0.0, status=sent (250 2.0.0 OK 1281176916 x18sm2858247wfd.20)
Aug  7 03:28:33 ubuntu postfix/cleanup[2543]: 0EE6B40A6A: message-id=<20100807102833.0EE6B40A6A@ubuntu>
Aug  7 03:28:33 ubuntu postfix/bounce[2548]: 9CE1240A67: sender delivery status notification: 0EE6B40A6A
Aug  7 03:28:33 ubuntu postfix/qmgr[2363]: 9CE1240A67: removed
Aug  7 03:28:33 ubuntu postfix/qmgr[2363]: 0EE6B40A6A: from=<>, size=1775, nrcpt=1 (queue active)
Aug  7 03:28:34 ubuntu postfix/smtp[2545]: certificate verification failed for smtp.gmail.com[74.125.53.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
layleng@ubuntu:~$ tail -n 20 /var/log/mail.log
Aug  6 07:42:21 ubuntu postfix/smtp[6323]: E5AF940A63: to=<xanios@server.com>, relay=smtp.gmail.com[72.14.213.109]:587, delay=5.3, delays=0.02/0/2.9/2.4, dsn=2.0.0, status=sent (250 2.0.0 OK 1281105742 q27sm1508796wfc.18)
Aug  6 07:42:21 ubuntu postfix/qmgr[6321]: E5AF940A63: removed
Aug  6 07:46:58 ubuntu postfix/qmgr[6321]: 1BA5440A67: from=<xanios@server.com>, size=284, nrcpt=1 (queue active)
Aug  6 07:46:59 ubuntu postfix/smtp[6410]: certificate verification failed for smtp.gmail.com[72.14.213.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Aug  6 07:47:03 ubuntu postfix/smtp[6410]: 1BA5440A67: to=<xanios@gmail.com>, relay=smtp.gmail.com[72.14.213.109]:587, delay=3473, delays=3468/0.06/2.6/2.2, dsn=2.0.0, status=sent (250 2.0.0 OK 1281106024 k23sm2967475waf.5)
Aug  6 07:47:03 ubuntu postfix/qmgr[6321]: 1BA5440A67: removed
Aug  6 18:18:32 ubuntu postfix/master[2396]: daemon started -- version 2.6.5, configuration /etc/postfix
Aug  7 03:28:23 ubuntu postfix/master[2351]: daemon started -- version 2.6.5, configuration /etc/postfix
Aug  7 03:28:26 ubuntu postfix/pickup[2361]: 9CE1240A67: uid=1000 from=<xanios>
Aug  7 03:28:26 ubuntu postfix/cleanup[2543]: 9CE1240A67: message-id=<20100807102826.9CE1240A67@ubuntu>
Aug  7 03:28:26 ubuntu postfix/qmgr[2363]: 9CE1240A67: from=<xanios@server.com>, size=289, nrcpt=1 (queue active)
Aug  7 03:28:28 ubuntu postfix/smtp[2545]: certificate verification failed for smtp.gmail.com[74.125.53.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Aug  7 03:28:33 ubuntu postfix/smtp[2545]: 9CE1240A67: to=<xanios@gmail.com>, relay=smtp.gmail.com[74.125.53.109]:587, delay=6.4, delays=0.2/0.25/3/2.9, dsn=2.0.0, status=sent (250 2.0.0 OK 1281176916 x18sm2858247wfd.20)
Aug  7 03:28:33 ubuntu postfix/cleanup[2543]: 0EE6B40A6A: message-id=<20100807102833.0EE6B40A6A@ubuntu>
Aug  7 03:28:33 ubuntu postfix/bounce[2548]: 9CE1240A67: sender delivery status notification: 0EE6B40A6A
Aug  7 03:28:33 ubuntu postfix/qmgr[2363]: 9CE1240A67: removed
Aug  7 03:28:33 ubuntu postfix/qmgr[2363]: 0EE6B40A6A: from=<>, size=1775, nrcpt=1 (queue active)
Aug  7 03:28:34 ubuntu postfix/smtp[2545]: certificate verification failed for smtp.gmail.com[74.125.53.109]:587: untrusted issuer /C=US/O=Equifax/OU=Equifax Secure Certificate Authority
Aug  7 03:28:38 ubuntu postfix/smtp[2545]: 0EE6B40A6A: to=<xanios@server.com>, relay=smtp.gmail.com[74.125.53.109]:587, delay=5.1, delays=0.03/0/2.8/2.3, dsn=2.0.0, status=sent (250 2.0.0 OK 1281176921 w8sm2860802wfd.7)
Aug  7 03:28:38 ubuntu postfix/qmgr[2363]: 0EE6B40A6A: removed
there aren't any errors i guess? status sent is 'OK'.


And, whats nagios.log file?

i tried this command but can't access:

Code:
/opt/hptc/nagios/nagios.log
Hmm sorry, and thanks.
 
Old 08-07-2010, 06:41 AM   #6
babunix
Member
 
Registered: Jul 2010
Location: India
Distribution: RHEL, Ubuntu
Posts: 35

Rep: Reputation: Disabled
Quote:
And, whats nagios.log file?

i tried this command but can't access:

Code:

/opt/hptc/nagios/nagios.log

Hmm sorry, and thanks.
generally nagios.log file stored in

Code:
/user/local/nagios/var/nagios.log
as your mail.log file there is no mail sent by nagios user.

monitor nagios.log file and check is there any log which says service-notification-sent via email.
 
Old 08-07-2010, 06:48 AM   #7
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
Hello,

i tried this, they gave me:

Code:
xanios@ubuntu:~$ sudo /user/local/nagios/var/nagios.log
sudo: /user/local/nagios/var/nagios.log: command not found
x_x tried sudo vi /user/local/nagios/var/nagios.log also the same result.


Quote:
as your mail.log file there is no mail sent by nagios user.

monitor nagios.log file and check is there any log which says service-notification-sent via email.
 
Old 08-07-2010, 07:00 AM   #8
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
OK, here is the nagios.log:

Code:
[1280903305] Warning: Return code of 126 for check of service 'MYSQL' on host 'localhost' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903305] Warning: Return code of 126 for check of service 'MYSQL' on host 'wins server 2003' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903305] Warning: Return code of 127 for check of service 'SNMP' on host 'wins xp sp2' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903305] SERVICE NOTIFICATION: nagiosadmin;wins server 2003;IMAP;CRITICAL;notify-service-by-email;Connection refused
[1280903318] Warning: The check of host 'ubuntu' looks like it was orphaned (results never came back).  I'm scheduling an immediate check of the host...
[1280903318] Warning: Return code of 127 for check of service 'SNMP' on host 'ubuntu' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903325] Warning: Return code of 127 for check of service 'SNMP' on host 'wins 7' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903325] SERVICE ALERT: wins 7;SNMP;CRITICAL;SOFT;2;(Return code of 127 is out of bounds - plugin may be missing)
[1280903325] SERVICE ALERT: wins 7;IMAP;CRITICAL;SOFT;2;No route to host
[1280903325] SERVICE ALERT: wins 7;HTTP;CRITICAL;SOFT;2;No route to host
[1280903325] SERVICE ALERT: wins 7;FTP;CRITICAL;SOFT;2;No route to host
[1280903328] SERVICE ALERT: wins 7;HTTPS;WARNING;HARD;1;HTTP WARNING: HTTP/1.1 400 Bad Request - 513 bytes in 0.024 second response time
[1280903328] Warning: Return code of 127 for check of service 'SNMP' on host 'localhost' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903335] Warning: Return code of 126 for check of service 'MYSQL' on host 'wins vista' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903345] Warning: Return code of 126 for check of service 'MYSQL' on host 'wins xp sp2' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903345] Warning: Return code of 127 for check of service 'SNMP' on host 'localhost' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903345] Warning: Return code of 127 for check of service 'SNMP' on host 'wins server 2003' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903345] Warning: Return code of 126 for check of service 'MYSQL' on host 'ubuntu' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903345] Warning: Return code of 127 for check of service 'SNMP' on host 'wins vista' was out of bounds. Make sure the plugin you're trying to run actually exists.
[1280903348] Warning: Return code of 127 for check of service 'SNMP' on host 'wins xp sp2' was out of bounds. Make sure the plugin you're trying to run actually exists.
there isn't any log which "service-notification-sent via email"
it just basically shows the different services i'm monitoring for the different servers.

Last edited by Xanios; 08-07-2010 at 07:01 AM.
 
Old 08-07-2010, 07:38 AM   #9
Xanios
Member
 
Registered: Jul 2010
Posts: 216

Original Poster
Rep: Reputation: 30
Nevermind it works already.(:
now i'm able to receive nagios email notifications.

i simply just changed this part:

Code:
define command{
       command_name    notify-host-by-email
       command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HO
STADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEM
AIL$
       }

# '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$\nAddre
ss: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$" | /usr/bin/mail -s "** $NOTIFICATIONTYPE$ Servi
ce Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$
       }
just change /usr/bin/mailx to /usr/bin/mail instead. and it works
thanks to those who've replied.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Use Gmail To Send Emails From A Terminal (Shell) LXer Syndicated Linux News 0 11-06-2009 10:10 AM
nagios monitoring gmail - host down noir911 Linux - Networking 7 06-24-2009 07:52 AM
Gnubiff has troubles with gmail for lot of emails ... :( frenchn00b General 0 05-02-2008 07:13 PM
Exim: forward sent emails to Gmail mrtwice Linux - Software 0 09-08-2007 05:17 PM
moving emails to gmail kiddo Linux - General 4 05-06-2005 12:05 PM


All times are GMT -5. The time now is 11:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration