X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/21055bd108fecc2b7309c60358f86ae3afecfcfa..5bb7bf7aa78aa8bc9876f3ec3502572f4b6809d3:/cookbooks/logstash/recipes/default.rb?ds=sidebyside diff --git a/cookbooks/logstash/recipes/default.rb b/cookbooks/logstash/recipes/default.rb index df54a7280..bbe845021 100644 --- a/cookbooks/logstash/recipes/default.rb +++ b/cookbooks/logstash/recipes/default.rb @@ -1,8 +1,8 @@ # -# Cookbook Name:: logstash +# Cookbook:: logstash # Recipe:: default # -# Copyright 2015, OpenStreetMap Foundation +# 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. @@ -17,36 +17,21 @@ # limitations under the License. # +include_recipe "elasticsearch" include_recipe "networking" keys = data_bag_item("logstash", "keys") package %w[ - default-jre-headless + openjdk-11-jre-headless 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 - cookbook_file "/var/lib/logstash/beats.crt" do source "beats.crt" user "root" group "logstash" - mode 0o644 + mode "644" notifies :restart, "service[logstash]" end @@ -54,7 +39,7 @@ file "/var/lib/logstash/beats.key" do content keys["beats"].join("\n") user "root" group "logstash" - mode 0o640 + mode "640" notifies :restart, "service[logstash]" end @@ -62,74 +47,49 @@ template "/etc/logstash/conf.d/chef.conf" do source "logstash.conf.erb" user "root" group "root" - mode 0o644 - notifies :reload, "service[logstash]" + mode "644" + notifies :start, "service[logstash]" end file "/etc/logrotate.d/logstash" do - mode 0o644 + mode "644" +end + +template "/etc/default/logstash" do + source "logstash.default.erb" + user "root" + group "root" + mode "644" + notifies :restart, "service[logstash]" 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 + mode "755" 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 +forwarders = [] - firewall_rule "accept-beats-#{forwarder}" do - action :accept - family interface[:family] - source "#{interface[:zone]}:#{interface[:address]}" - dest "fw" - proto "tcp:syn" - dest_ports "5044" - source_ports "1024:" - end - end +search(:node, "recipes:logstash\\:\\:forwarder").each do |forwarder| + forwarders.append(forwarder.ipaddresses(:role => :external)) 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 - family interface[:family] - source "#{interface[:zone]}:#{interface[:address]}" - dest "fw" - proto "tcp:syn" - dest_ports "5043" - source_ports "1024:" - end +search(:node, "roles:gateway").each do |forwarder| + forwarders.append(forwarder.ipaddresses(:role => :external)) +end - firewall_rule "accept-beats-#{gateway}" do - action :accept - family interface[:family] - source "#{interface[:zone]}:#{interface[:address]}" - dest "fw" - proto "tcp:syn" - dest_ports "5044" - source_ports "1024:" - end - end +firewall_rule "accept-logstash" do + action :accept + context :incoming + protocol :tcp + source forwarders + dest_ports %w[5043 5044] + source_ports "1024-65535" + not_if { forwarders.empty? } end