Page 1 of 1

$CONTACTEMAIL$ Macro...where does it come from?

Posted: Tue Apr 22, 2014 9:01 am
by ghuey
I am trying to setup email notifications for more than one contact and cannot seem to get it working. My default setup with a single contact works like a champ so it is an issue with how I am trying to use contact groups I believe.

What I am not clear on is the process how an email for the $CONTACTEMAIL$ Macro used by my email notification comes from. I have two different contacts in my contacts.cfg, who are then assigned to contact groups in my contactgroups.cfg file. From there I have the contact group specified in the services.cfg for the services that I want the other person to receive emails for. Triggering some test alarms yields no emails so I am not sure what is going on.

Any clarification or direction would be appreciated...

Re: $CONTACTEMAIL$ Macro...where does it come from?

Posted: Tue Apr 22, 2014 9:18 am
by slansing
You should be able to just copy or duplicate your working contact, and change the copy's name and address in the configuration file, then add it to the contact group. That macro pulls the address(s) you give your contacts when setting them up:

http://nagios.sourceforge.net/docs/3_0/ ... ml#contact
http://nagios.sourceforge.net/docs/3_0/ ... ntactgroup

Re: $CONTACTEMAIL$ Macro...where does it come from?

Posted: Tue Apr 22, 2014 12:13 pm
by ghuey
slansing wrote:You should be able to just copy or duplicate your working contact, and change the copy's name and address in the configuration file, then add it to the contact group. That macro pulls the address(s) you give your contacts when setting them up:

http://nagios.sourceforge.net/docs/3_0/ ... ml#contact
http://nagios.sourceforge.net/docs/3_0/ ... ntactgroup
Agreed...it should be that easy, and this is what I have done, but it is still not working. There is a piece in the chain that is not configured correctly on my part and I am probably not presenting all the information here.

My Host check uses the following command: check-host-alive

$USER1$/check_ping -H $HOSTADDRESS$ -w 3000.0,80% -c 5000.0,100% -p 5

Now I am getting emails for this check when it fails. I don't see how since I cannot see where an email address or macro is specified for this check. This part of the reason I am confused but I think I am starting to narrow it down.

Re: $CONTACTEMAIL$ Macro...where does it come from?

Posted: Tue Apr 22, 2014 1:42 pm
by abrist
ghuey wrote: I don't see how since I cannot see where an email address or macro is specified for this check.
The macro is from a contact, which most likely was inherited from a contact group, host, or hostgroup. Can you post the configs for this host, one of its services, both contacts, and the contact group? (obfuscate emails/etc if you wish)

Re: $CONTACTEMAIL$ Macro...where does it come from?

Posted: Tue Apr 22, 2014 4:43 pm
by ghuey
abrist wrote:
ghuey wrote: I don't see how since I cannot see where an email address or macro is specified for this check.
The macro is from a contact, which most likely was inherited from a contact group, host, or hostgroup. Can you post the configs for this host, one of its services, both contacts, and the contact group? (obfuscate emails/etc if you wish)
I have butchered these pretty bad in my testing, but here it goes:

hosts.cfg

Code: Select all

define host {
                host_name                             EXCHANGE
                address                               172.x.x.x
                check_command                         check-host-alive
                notification_interval                 15
                notification_options                  d,u,r
                max_check_attempts                    3
                active_checks_enabled                 1
                passive_checks_enabled                0
                notifications_enabled                 1
                check_period                          24x7
                notification_period                   24x7
                contact_groups                        admins
}
services.cfg

Code: Select all

define service {
                service_description                   Check Openmanage
                check_command                         check_openmanage!172.x.x.x!Slight-NMS
                host_name                             EXCHANGE
                check_period                          24x7
                contact_groups                        GlenHome,admins
                event_handler_enabled                 0
                max_check_attempts                    3
                check_interval                        5
                retry_interval                        1
                active_checks_enabled                 1
                passive_checks_enabled                0
                notifications_enabled                 1
                check_freshness                       0
                freshness_threshold                   86400
}
contacts.cfg

Code: Select all

define contact {
                contact_name                          nagiosadmin
                alias                                 Nagios Admin
                host_notification_options             d,u,r,f
                service_notification_options          w,u,c,r,f
                email                                 [email protected]
                host_notification_period              24x7
                service_notification_period           24x7
                host_notification_commands            notify-host-by-email
                service_notification_commands         notify-service-by-email
}

define contact {
                contact_name                          glentext
                alias                                 Glen Smith
                host_notification_options             d,u,r,f
                service_notification_options          w,u,c,r,f
                email                                 [email protected]
                host_notification_period              24x7
                service_notification_period           24x7
                host_notification_commands            notify-host-by-email
                service_notification_commands         notify-service-by-email
}

define contact {
                contact_name                          glengmail
                alias                                 Glen Gmail
                host_notification_options             d,u,r,f
                service_notification_options          w,u,c,r,f
                email                                 [email protected]
                host_notification_period              24x7
                service_notification_period           24x7
                host_notification_commands            notify-host-by-email
                service_notification_commands         notify-service-by-email
}

define contact {
                contact_name                          asmith
                alias                                 aaron
                host_notification_options             d,u,r,f
                service_notification_options          w,u,c,r,f
                email                                 [email protected]
                host_notification_period              24x7
                service_notification_period           24x7
                host_notification_commands            notify-host-by-email
                service_notification_commands         notify-service-by-email
}

define contact {
                contact_name                          chad
                alias                                 Chad Smith
                host_notification_options             d,u,r,f
                service_notification_options          w,u,c,r,f
                email                                 [email protected]
                host_notification_period              24x7
                service_notification_period           24x7
                host_notification_commands            notify-host-by-email
                service_notification_commands         notify-service-by-email
}
contactgroups.cfg

Code: Select all

define contactgroup {
                contactgroup_name                     admins
                alias                                 Nagios Administrators
                members                               nagiosadmin
}

define contactgroup {
                contactgroup_name                     GlenHome
                alias                                 GlenHome
                members                               glengmail
}

define contactgroup {
                contactgroup_name                     asmithgroup
                alias                                 Arron Email
                members                               asmith
}
check commands

Code: Select all

notify-host-by-email

/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  <--  This is a custom notification script used, but works fine

/usr/local/nagios/libexec/nagios_send_service_mail.pl \ -H 172.30.1.12 -r $CONTACTEMAIL$ -f html -u

Re: $CONTACTEMAIL$ Macro...where does it come from?

Posted: Wed Apr 23, 2014 11:26 am
by sreinhardt
the contact email is being pulled in via a path that would look something like: host\service->contact group(admins)->contact(nagiosadmin)->email(gsmith..company.com). When nagios calls the notification command associated with your contact due to an event needing a notification sent, it simply pulls the email address out of the contact information and stores that in the macro structs used for such things.

Is it your gmail contact\address that is not working properly? If so, most likely this is due to either your local mailer, used by notify-host\service-by-email, forwarding directly to your internal server which denies it based on not allowing mail relaying.(perfectly normal and standard setup) It could also be that your ISP is set to deny outbound smtp connections, less likely if you are on a commercial line. Finally it could be that gmail is not allowing you to communicate with them directly, not normally the case if they suspect something is up they usually just put your mail in spam.

With all that, I would look at how your local mailer is setup, such as to forward just to the internal server, and either alter the mail server it is sending to, to allow nagios to relay through it, or correct the local mailer so that it sends to a gmails mail servers if that is the destined domain.