<commit_before>#
# Cookbook Name:: logstash
# Recipe:: default
#
# Copyright 2015, OpenStreetMap Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "networking"

keys = data_bag_item("logstash", "keys")

package "default-jre-headless"
package "logstash"

cookbook_file "/var/lib/logstash/lumberjack.crt" do
  source "lumberjack.crt"
  user "root"
  group "logstash"
  mode 0o644
  notifies :restart, "service[logstash]"
end

file "/var/lib/logstash/lumberjack.key" do
  content keys["lumberjack"].join("\n")
  user "root"
  group "logstash"
  mode 0o640
  notifies :restart, "service[logstash]"
end

template "/etc/logstash/conf.d/chef.conf" do
  source "logstash.conf.erb"
  user "root"
  group "root"
  mode 0o644
  notifies :reload, "service[logstash]"
end

file "/etc/logrotate.d/logstash" do
  mode 0o644
end

service "logstash" do
  action [:enable, :start]
  supports :status => true, :restart => true, :reload => true
end

template "/etc/cron.daily/expire-logstash" do
  source "expire.erb"
  owner "root"
  group "root"
  mode 0o755
end

forwarders = search(:node, "recipes:logstash\\:\\:forwarder") # ~FC010

forwarders.each do |forwarder|
  forwarder.interfaces(:role => :external) do |interface|
    firewall_rule "accept-lumberjack-#{forwarder}" do
      action :accept
      family interface[:family]
      source "#{interface[:zone]}:#{interface[:address]}"
      dest "fw"
      proto "tcp:syn"
      dest_ports "5043"
      source_ports "1024:"
    end
  end
end

gateways = search(:node, "roles:gateway") # ~FC010

gateways.each do |gateway|
  gateway.interfaces(:role => :external) do |interface|
    firewall_rule "accept-lumberjack-#{gateway}" do
      action :accept<commit_msg>Sort logstash server firewall rules by node name<commit_after>#
# Cookbook Name:: logstash
# Recipe:: default
#
# Copyright 2015, OpenStreetMap Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

include_recipe "networking"

keys = data_bag_item("logstash", "keys")

package "default-jre-headless"
package "logstash"

cookbook_file "/var/lib/logstash/lumberjack.crt" do
  source "lumberjack.crt"
  user "root"
  group "logstash"
  mode 0o644
  notifies :restart, "service[logstash]"
end

file "/var/lib/logstash/lumberjack.key" do
  content keys["lumberjack"].join("\n")
  user "root"
  group "logstash"
  mode 0o640
  notifies :restart, "service[logstash]"
end

template "/etc/logstash/conf.d/chef.conf" do
  source "logstash.conf.erb"
  user "root"
  group "root"
  mode 0o644
  notifies :reload, "service[logstash]"
end

file "/etc/logrotate.d/logstash" do
  mode 0o644
end

service "logstash" do
  action [:enable, :start]
  supports :status => true, :restart => true, :reload => true
end

template "/etc/cron.daily/expire-logstash" do
  source "expire.erb"
  owner "root"
  group "root"
  mode 0o755
end

forwarders = search(:node, "recipes:logstash\\:\\:forwarder") # ~FC010

forwarders.sort_by { |n| n[:fqdn] }.each do |forwarder|
  forwarder.interfaces(:role => :external) do |interface|
    firewall_rule "accept-lumberjack-#{forwarder}" do
      action :accept
      family interface[:family]
      source "#{interface[:zone]}:#{interface[:address]}"
      dest "fw"
      proto "tcp:syn"
      dest_ports "5043"
      source_ports "1024:"
    end
  end
end

gateways = search(:node, "roles:gateway") # ~FC010

gateways.sort_by { |n| n[:fqdn] }.each do |gateway|
  gateway.interfaces(:role => :external) do |interface|
    firewall_rule "accept-lumberjack-#{gateway}" do
      action :accept
{'fraction_non_alphanumeric': 0.1213324509155085, 'fraction_numerical': 0.018530774321641297, 'mean_word_length': 4.152272727272727, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4316306', 'n_tokens_mistral': 1599, 'n_tokens_neox': 1535, 'n_words': 454}