From ccf120d91010c3aa0962333e20153ae8a0e5b292 Mon Sep 17 00:00:00 2001 From: Jacob Dearing Date: Mon, 27 Jul 2015 17:06:11 -0500 Subject: [PATCH] rework logstash --- libraries/provider_logstash.rb | 39 ++++++++- libraries/provider_logstash_config.rb | 79 ------------------- libraries/resource_logstash.rb | 12 ++- .../default/logstash/conf.d/00-input.conf.erb | 8 -- .../logstash/conf.d/99-output.conf.erb | 4 - .../10-syslog.conf.erb => logstash.conf.erb} | 16 +++- templates/default/sv-logstash-run.erb | 5 +- 7 files changed, 61 insertions(+), 102 deletions(-) delete mode 100644 libraries/provider_logstash_config.rb delete mode 100755 templates/default/logstash/conf.d/00-input.conf.erb delete mode 100755 templates/default/logstash/conf.d/99-output.conf.erb rename templates/default/logstash/{conf.d/10-syslog.conf.erb => logstash.conf.erb} (59%) mode change 100755 => 100644 diff --git a/libraries/provider_logstash.rb b/libraries/provider_logstash.rb index 9c8a1a5..4d35e7d 100644 --- a/libraries/provider_logstash.rb +++ b/libraries/provider_logstash.rb @@ -6,11 +6,19 @@ class Logstash < Chef::Provider::LWRPBase provides :logstash service_name = 'logstash' - action :install do + home_dir = "/opt/logstash/logstash-#{new_resource.version}" + user new_resource.user group new_resource.group + directory "#{home_dir}/config" do + owner new_resource.user + group new_resource.group + mode '0755' + action :create + end + ark service_name do checksum new_resource.checksum group new_resource.group @@ -21,11 +29,40 @@ class Logstash < Chef::Provider::LWRPBase version new_resource.version end + template "#{home_dir}/config/logging.yml" do + source 'logstash/logging.yml.erb' + owner 'root' + group 'root' + mode '0644' + cookbook new_resource.source + end + + template "#{home_dir}/config/logstash.conf" do + source 'logstash/logstash.conf.erb' + owner 'root' + group 'root' + mode '0644' + cookbook new_resource.source + variables options: { + 'port' => new_resource.port, + 'key' => new_resource.key, + 'crt' => new_resource.crt, + 'key_location' => new_resource.key_location, + 'crt_location' => new_resource.crt_location + } + end + runit_service service_name do default_logger true owner new_resource.user group new_resource.user cookbook new_resource.source + options new_resource.runit_options.merge( + 'home_dir' => home_dir, + 'user' => new_resource.user, + 'group' => new_resource.group, + 'config_file' => 'config/logstash.conf' + ) action [:create, :enable] end end diff --git a/libraries/provider_logstash_config.rb b/libraries/provider_logstash_config.rb deleted file mode 100644 index da280b0..0000000 --- a/libraries/provider_logstash_config.rb +++ /dev/null @@ -1,79 +0,0 @@ -class Chef - class Provider - class LogstashConfig < Chef::Provider::LWRPBase - use_inline_resources if defined?(use_inline_resources) - - provides :logstash_config - - action :create do - [new_resource.ls_conf_dir, - new_resource.ls_home, - '/var/log/logstash/', - '/etc/logstash' - ].each do |dir| - directory dir do - mode '0755' - action :create - recursive true - end - end - - template '/etc/logstash/config' do - source 'logstash/logstash.sysconfig.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - variables options: { - 'javacmd' => new_resource.javacmd, - 'ls_home' => new_resource.ls_home, - 'ls_opts' => new_resource.ls_opts, - 'ls_heap_size' => new_resource.ls_heap_size, - 'ls_java_opts' => new_resource.ls_java_opts, - 'ls_pidfile' => new_resource.ls_pidfile, - 'ls_user' => new_resource.ls_user, - 'ls_group' => new_resource.ls_group, - 'ls_log_file' => new_resource.ls_log_file, - 'ls_use_gc_logging' => new_resource.ls_use_gc_logging, - 'ls_conf_dir' => new_resource.ls_conf_dir, - 'ls_open_files' => new_resource.ls_open_files, - 'ls_nice' => new_resource.ls_nice - } - end - - template "#{new_resource.ls_conf_dir}/00-input.conf" do - source 'logstash/conf.d/00-input.conf.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - variables options: { - 'port' => new_resource.port, - 'key' => new_resource.key, - 'crt' => new_resource.crt, - 'key_location' => new_resource.key_location, - 'crt_location' => new_resource.crt_location - } - end - - template "#{new_resource.ls_conf_dir}/99-input.conf" do - source 'logstash/conf.d/99-output.conf.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - end - - template "#{new_resource.ls_conf_dir}/10-syslog.conf" do - source 'logstash/conf.d/10-syslog.conf.erb' - owner 'root' - group 'root' - mode '0644' - cookbook new_resource.source - end - end - action :delete do - end - end - end -end diff --git a/libraries/resource_logstash.rb b/libraries/resource_logstash.rb index c26d4fe..43e556c 100644 --- a/libraries/resource_logstash.rb +++ b/libraries/resource_logstash.rb @@ -25,12 +25,6 @@ class Logstash < Chef::Resource::LWRPBase attribute :owner, kind_of: String, default: 'logstash' attribute :path, kind_of: String, default: '/opt/logstash' - end - - class LogstashConfig < Chef::Resource::LWRPBase - resource_name :logstash_config - default_action :create - actions [:create, :delete] attribute :crt, kind_of: String, default: '' attribute :crt_location, kind_of: String, default: '/etc/logstash/logstash.crt' @@ -50,7 +44,11 @@ class LogstashConfig < Chef::Resource::LWRPBase attribute :ls_use_gc_logging, kind_of: [TrueClass, FalseClass], default: true attribute :ls_user, kind_of: String, default: 'logstash' attribute :port, kind_of: Integer, default: 5043 - attribute :source, kind_of: String, default: 'elk' + + # RUNIT + attribute :runit_args, kind_of: Hash, default: {} + attribute :runit_options, kind_of: Hash, default: {} + attribute :runit_env, kind_of: Hash, default: {} end end end diff --git a/templates/default/logstash/conf.d/00-input.conf.erb b/templates/default/logstash/conf.d/00-input.conf.erb deleted file mode 100755 index d0d6962..0000000 --- a/templates/default/logstash/conf.d/00-input.conf.erb +++ /dev/null @@ -1,8 +0,0 @@ -input { - lumberjack { - port => "<%= @options['port'] %>" - type => "logs" - ssl_certificate => "<%= @options['crt_location'] %>" - ssl_key => "<%= @options['key_location'] %>" - } -} diff --git a/templates/default/logstash/conf.d/99-output.conf.erb b/templates/default/logstash/conf.d/99-output.conf.erb deleted file mode 100755 index 58c3ef4..0000000 --- a/templates/default/logstash/conf.d/99-output.conf.erb +++ /dev/null @@ -1,4 +0,0 @@ -output { - elasticsearch { host => localhost } - stdout { codec => rubydebug } -} diff --git a/templates/default/logstash/conf.d/10-syslog.conf.erb b/templates/default/logstash/logstash.conf.erb old mode 100755 new mode 100644 similarity index 59% rename from templates/default/logstash/conf.d/10-syslog.conf.erb rename to templates/default/logstash/logstash.conf.erb index 3344a78..ee381ce --- a/templates/default/logstash/conf.d/10-syslog.conf.erb +++ b/templates/default/logstash/logstash.conf.erb @@ -1,3 +1,12 @@ +input { + lumberjack { + port => "<%= @options['port'] %>" + type => "logs" + ssl_certificate => "<%= @options['crt_location'] %>" + ssl_key => "<%= @options['key_location'] %>" + } +} + filter { if [type] == "syslog" { grok { @@ -10,4 +19,9 @@ filter { match => [ "syslog_timestamp", "MMM d HH:mm:ss", "MMM dd HH:mm:ss" ] } } -} \ No newline at end of file +} + +output { + elasticsearch { host => localhost } + stdout { codec => rubydebug } +} diff --git a/templates/default/sv-logstash-run.erb b/templates/default/sv-logstash-run.erb index 4790176..fb42860 100644 --- a/templates/default/sv-logstash-run.erb +++ b/templates/default/sv-logstash-run.erb @@ -1,6 +1,7 @@ #!/bin/sh -cd /home/logstash +cd <%= @options['home_dir'] %> exec 2>&1 -exec /usr/bin/env logstash -c /etc/logstash/config +chpst -u :<%= @options['user'] %>:<%= @options['group'] %> +exec ./bin/logstash -f <%= @options['config_file'] %>