LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   [nagios] send emails to gmail when services are down. (https://www.linuxquestions.org/questions/linux-newbie-8/%5Bnagios%5D-send-emails-to-gmail-when-services-are-down-824596/)

Xanios 08-06-2010 10:03 AM

[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.

sem007 08-06-2010 11:10 AM

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

Xanios 08-06-2010 08:24 PM

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 ):

sem007 08-07-2010 02:04 AM

Is there any error in nagios.log file as well as mail.log file ?

Xanios 08-07-2010 05:34 AM

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.

babunix 08-07-2010 05:41 AM

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.

Xanios 08-07-2010 05:48 AM

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.

Xanios 08-07-2010 06:00 AM

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.

Xanios 08-07-2010 06:38 AM

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.


All times are GMT -5. The time now is 05:07 PM.