# Contact definitions
#
# Autogenerated by Chef.

define contact {
  contact_name                    root
  alias                           Root
  service_notification_period     24x7
  host_notification_period        24x7
  service_notification_options    w,u,c,r
  host_notification_options       d,r
  service_notification_commands   service-notify-by-email
  host_notification_commands      host-notify-by-email
  email                           root@localhost
}

define contactgroup {
  contactgroup_name admins
  alias             Nagios Administrators
  members           <%= @members.join(',') %><%= ",pagerduty" unless node['nagios']['pagerduty_key'].empty? %>
}

define contactgroup {
  contactgroup_name admins-sms
  alias             Sysadmin SMS
  members           <%= @members.join(',') %>
}

<% @admins.each do |a| -%>
define contact {
  use          default-contact
  contact_name <%= a['id'] %>
<%= "email  #{a['nagios']['email']}" unless a['nagios']['email'].nil? %>
}

<% end -%>

# Contact definitions
#
# Autogenerated by Chef.

define contact {
  contact_name                    root
  alias                           Root
  service_notification_period     24x7
  host_notification_period        24x7
  service_notification_options    w,u,c,r
  host_notification_options       d,r
  service_notification_commands   service-notify-by-email
  host_notification_commands      host-notify-by-email
  email                           root@localhost
}

define contactgroup {
  contactgroup_name admins
  alias             Nagios Administrators
  members           <%= @members.join(',') %><%= ",pagerduty" unless node['nagios']['pagerduty_key'].empty? %>
}

define contactgroup {
  contactgroup_name admins-sms
  alias             Sysadmin SMS
  members           <%= @members.join(',') %>
}

<% @admins.each do |a| -%>
define contact {
  use          default-contact
  contact_name <%= a['id'] %>
  <%= "email  #{a['nagios']['email']}" unless a['nagios'].nil? || a['nagios']['email'].nil? %>
}

<% end -%>

Check to make sure that not just a['nagios']['email'] exists, but also that a['nagios'] exists
Check to make sure that not just a['nagios']['email'] exists, but also that a['nagios'] exists

The previous check only worked if the nagios block existed, but not the
e-mail value.  If the entire nagios block was missing an error would
still be thrown.  I've tested this under both scenarios.
