diff --git a/templates/default/ossec-server.conf.erb b/templates/default/ossec-server.conf.erb
index ee78c8a..c49981e 100644
--- a/templates/default/ossec-server.conf.erb
+++ b/templates/default/ossec-server.conf.erb
@@ -15,6 +15,53 @@
<% end -%>
+<% node["ossec"]["email_alerts"].sort_by {|k,v| k}.each do |recipient,params|
+ locations = []
+ if params.has_key?('event_location_tag')
+ locations = @ossec_agents.select{
+ |n| n[:tags].include?(
+ params[:event_location_tag]
+ )
+ }.map {|n2| n2.network.lanip || '172.172.172.172'}
+ elsif params.has_key?('resolved_search')
+ locations = params[:resolved_search]
+ end
+ if locations.count > 0
+ locations.sort_by {|k| k}.each do |location| -%>
+
+ <%= recipient %>
+ <%= location %>
+<% params.sort_by {|k,v| k}.each do |key, value|
+ unless key =~ /event_location_tag|event_location_search|resolved_search/
+ if key.eql?('tags')
+ value.sort_by {|k| k}.each do |tag| -%>
+ <<%= tag %> />
+<% end
+ else -%>
+ <<%= key %>><%= value %><%= key %>>
+<% end
+ end
+ end -%>
+
+<% end
+ else -%>
+
+ <%= recipient %>
+<% params.sort_by {|k,v| k}.each do |key, value|
+ unless key =~ /event_location_tag|event_location_search|resolved_search/
+ if key.eql?('tags')
+ value.sort_by {|k| k}.each do |tag| -%>
+ <<%= tag %> />
+<% end
+ else -%>
+ <<%= key %>><%= value %><%= key %>>
+<% end
+ end
+ end -%>
+
+<% end
+ end -%>
+
<% node["ossec"]["load_rules"].each_pair do |name, value|
if value -%>
@@ -83,53 +130,6 @@
<% end -%>
-<% node["ossec"]["email_alerts"].sort_by {|k,v| k}.each do |recipient,params|
- locations = []
- if params.has_key?('event_location_tag')
- locations = @ossec_agents.select{
- |n| n[:tags].include?(
- params[:event_location_tag]
- )
- }.map {|n2| n2.network.lanip || '172.172.172.172'}
- elsif params.has_key?('resolved_search')
- locations = params[:resolved_search]
- end
- if locations.count > 0
- locations.sort_by {|k| k}.each do |location| -%>
-
- <%= recipient %>
- <%= location %>
-<% params.sort_by {|k,v| k}.each do |key, value|
- unless key =~ /event_location_tag|event_location_search|resolved_search/
- if key.eql?('tags')
- value.sort_by {|k| k}.each do |tag| -%>
- <<%= tag %> />
-<% end
- else -%>
- <<%= key %>><%= value %><%= key %>>
-<% end
- end
- end -%>
-
-<% end
- else -%>
-
- <%= recipient %>
-<% params.sort_by {|k,v| k}.each do |key, value|
- unless key =~ /event_location_tag|event_location_search|resolved_search/
- if key.eql?('tags')
- value.sort_by {|k| k}.each do |tag| -%>
- <<%= tag %> />
-<% end
- else -%>
- <<%= key %>><%= value %><%= key %>>
-<% end
- end
- end -%>
-
-<% end
- end -%>
-
<%= node["ossec"]["syscheck"]["frequency"] %>