From 82876512357b1d27091bfaf138e1e929347267d5 Mon Sep 17 00:00:00 2001 From: Patrick Connolly Date: Tue, 11 Aug 2015 16:25:31 -0700 Subject: [PATCH] Simplified custom_logstash attr hash. --- README.md | 4 ++-- attributes/logstash.rb | 11 +++++------ recipes/agent.rb | 9 ++++----- recipes/logstash.rb | 9 ++++----- .../cookbooks/wrapper/recipes/logstash_override.rb | 7 ++----- 5 files changed, 17 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index a22694a..f6378ba 100644 --- a/README.md +++ b/README.md @@ -182,8 +182,8 @@ CentOS 6.5 lumberjack - ['elkstack']['config']['custom_logstash']['name'] - Array of strings + ['elkstack']['config']['custom_logstash'] + Hash See `attributes/logstash.rb` for an explanation of how to use this attribute to populate additional logstash configuration file templates [] diff --git a/attributes/logstash.rb b/attributes/logstash.rb index e0d478b..c07146d 100644 --- a/attributes/logstash.rb +++ b/attributes/logstash.rb @@ -62,11 +62,10 @@ server['config_templates_variables'] = config_templates_variables # arbitrary data structure for any arbitrary logstash config -default_unless['elkstack']['config']['custom_logstash']['name'] = [] +default_unless['elkstack']['config']['custom_logstash'] = {} # Currently for arbitrary logstash configs, the recipe that sets up the logstash file should add: # node.default['elkstack']['config']['custom_logstash']['name'].push('') -# and then populate node['elkstack']['config']['custom_logstash'][service_name][setting] with your values -# default['elkstack']['config']['custom_logstash'][]['name'] = 'my_logstashconfig' -# default['elkstack']['config']['custom_logstash'][]['source'] = 'my_logstashconfig.conf.erb' -# default['elkstack']['config']['custom_logstash'][]['cookbook'] = 'your_cookbook' -# default['elkstack']['config']['custom_logstash'][]['variables'] = { :warning => 'foo' } +# and then populate node['elkstack']['config']['custom_logstash'][source_filename][setting] with your values +# default['elkstack']['config']['custom_logstash']['my_logstashconfig']['source'] = 'my_logstashconfig_alt.conf.erb' +# default['elkstack']['config']['custom_logstash']['my_logstashconfig']['cookbook'] = 'your_cookbook' +# default['elkstack']['config']['custom_logstash']['my_logstashconfig']['variables'] = { :warning => 'foo' } diff --git a/recipes/agent.rb b/recipes/agent.rb index b8ada1f..748ce7d 100644 --- a/recipes/agent.rb +++ b/recipes/agent.rb @@ -92,11 +92,10 @@ end # install additional stacks logstash configuration -node['elkstack']['config']['custom_logstash']['name'].each do |logcfg| - logcfg_name = node['elkstack']['config']['custom_logstash'][logcfg]['name'] - logcfg_source = node['elkstack']['config']['custom_logstash'][logcfg]['source'] - logcfg_cookbook = node['elkstack']['config']['custom_logstash'][logcfg]['cookbook'] - logcfg_variables = node['elkstack']['config']['custom_logstash'][logcfg]['variables'] +node['elkstack']['config']['custom_logstash'].keys.each do |logcfg_name| + logcfg_source = node['elkstack']['config']['custom_logstash'][logcfg_name]['source'] + logcfg_cookbook = node['elkstack']['config']['custom_logstash'][logcfg_name]['cookbook'] + logcfg_variables = node['elkstack']['config']['custom_logstash'][logcfg_name]['variables'] # add one more config for our additional logs logstash_custom_config logcfg_name do diff --git a/recipes/logstash.rb b/recipes/logstash.rb index 2e9affb..15b0382 100644 --- a/recipes/logstash.rb +++ b/recipes/logstash.rb @@ -51,11 +51,10 @@ end # install additional stacks logstash configuration -node['elkstack']['config']['custom_logstash']['name'].each do |logcfg| - logcfg_name = node['elkstack']['config']['custom_logstash'][logcfg]['name'] - logcfg_source = node['elkstack']['config']['custom_logstash'][logcfg]['source'] - logcfg_cookbook = node['elkstack']['config']['custom_logstash'][logcfg]['cookbook'] - logcfg_variables = node['elkstack']['config']['custom_logstash'][logcfg]['variables'] +node['elkstack']['config']['custom_logstash'].keys.each do |logcfg_name| + logcfg_source = node['elkstack']['config']['custom_logstash'][logcfg_name]['source'] + logcfg_cookbook = node['elkstack']['config']['custom_logstash'][logcfg_name]['cookbook'] + logcfg_variables = node['elkstack']['config']['custom_logstash'][logcfg_name]['variables'] # add one more config for our additional logs logstash_custom_config logcfg_name do diff --git a/test/fixtures/cookbooks/wrapper/recipes/logstash_override.rb b/test/fixtures/cookbooks/wrapper/recipes/logstash_override.rb index 5dee9b1..ac0d6da 100644 --- a/test/fixtures/cookbooks/wrapper/recipes/logstash_override.rb +++ b/test/fixtures/cookbooks/wrapper/recipes/logstash_override.rb @@ -1,7 +1,4 @@ # Attempt to supply an additional logstash configuration file like a real # wrapper cookbook would -- see README.md. -node.set_unless['elkstack']['config']['custom_logstash']['name'] = [] -node.set['elkstack']['config']['custom_logstash']['name'].push('wrapper') -node.set['elkstack']['config']['custom_logstash']['wrapper']['name'] = 'input_test' -node.set['elkstack']['config']['custom_logstash']['wrapper']['cookbook'] = 'wrapper' -node.set['elkstack']['config']['custom_logstash']['wrapper']['variables'] = { path: '/special_test_path' } +node.set['elkstack']['config']['custom_logstash']['input_test']['cookbook'] = 'wrapper' +node.set['elkstack']['config']['custom_logstash']['input_test']['variables'] = { path: '/special_test_path' }