# Host definitions
#
# Autogenerated by Chef.

define host {
  use server
  address <%= node['ipaddress'] %>
  host_name <%= node['hostname'] %>
  hostgroups <%= node['nagios']['server_role'] %>,<%= node['os'] %>
}

<% @nodes.each do |n| -%>
<% unless n.name == node.name -%>
define host {
  use server
  address <%= n['ipaddress'] %>
  host_name <%= n['hostname'] %>
<% if n.run_list.roles.nil? || n.run_list.roles.length == 0 -%>
  hostgroups all,<%= n.os %>
<% else -%>
  hostgroups <%= n.run_list.roles.to_a.join(",") %>,<%= n['os'] %>
<% end -%>
}
<% end -%>

<% end -%>

<% @unmanaged_hosts.each do |n| -%>
define host {
  use server
  address <%= n['address'] %>
  host_name <%= n['id'] %>
  hostgroups <%= n['hostgroups'].join(",") %>
  notifications_enabled <%= n['notifications'] %>
}
<% end -%>
# Host definitions
#
# Autogenerated by Chef.

define host {
  use server
  address <%= node['ipaddress'] %>
  host_name <%= node['hostname'] %>
  hostgroups <%= node['nagios']['server_role'] %>,<%= node['os'] %>
}

<% @nodes.each do |n| -%>
<% unless n.name == node.name -%>
define host {
  use server
  address <%= n['ipaddress'] %>
  host_name <%= n['hostname'] %>
  <% if node['nagios']['multi_environment_monitoring'] -%>
  <% if n.run_list.roles.nil? || n.run_list.roles.length == 0 -%>
  hostgroups all,<%= n.os %><% if n.chef_environment != '_default' -%>, <%= n.chef_environment %> <% end -%>
  <% else -%>
  hostgroups <%= n.run_list.roles.to_a.join(",") %>,<%= n.os %><% if n.chef_environment != '_default' -%>, <%= n.chef_environment %> <% end -%>
  <% end -%>
  <% elsif -%>
  <% if n.run_list.roles.nil? || n.run_list.roles.length == 0 -%>
  hostgroups all,<%= n.os %>
  <% else -%>
  hostgroups <%= n.run_list.roles.to_a.join(",") %>,<%= n['os'] %>
  <% end -%>
  <% end -%>
}
<% end -%>
<% end -%>

<% @unmanaged_hosts.each do |n| -%>
define host {
  use server
  address <%= n['address'] %>
  host_name <%= n['id'] %>
  hostgroups <%= n['hostgroups'].join(",") %>
  notifications_enabled <%= n['notifications'] %>
}
<% end -%>
Write out hosts with environments if enabled
Write out hosts with environments if enabled
