From ba5a69d01aa206da022a199bae85f8da94f12319 Mon Sep 17 00:00:00 2001 From: Daniel Wiltshire Date: Sun, 9 Jun 2019 09:14:15 +0100 Subject: [PATCH] added defined type class wrapper for pipelines renamed class to pipeline_config using array removed underscore from pipelineconfig class name renamed pipelineconfig to pipeline_files for readability renamed pipelineconfig.pp to pipeline_files.pp changed dynamic values to static for testing require the configfile removed dollar symbols sourced from removed parameters from class changed from test content to array content converted id value back to test value converted pipeline_files to Hash added test notify converted to dynamic hash content added pretty JSON converter added pretty JSON converter with output changed to notify changed to notify with brackets removed pretty JSON converter added .each for removed notify added examples added usage section for pipeline_files fixed linting issues wrote test cases for pipeline-files --- README.md | 31 +++++++++++++++++++ manifests/init.pp | 2 ++ manifests/pipeline_files.pp | 29 ++++++++++++++++++ spec/acceptance/class_logstash_spec.rb | 41 ++++++++++++++++++++++++++ 4 files changed, 103 insertions(+) create mode 100644 manifests/pipeline_files.pp diff --git a/README.md b/README.md index 15597a9f..c3d2275c 100644 --- a/README.md +++ b/README.md @@ -256,6 +256,37 @@ my_logstash_configs: In this example, templates for the config files are stored in the custom, site-specific module "`site_logstash`". +You can also use the `pipeline_files` class within an ENC to generate pipeline configuration files: + +```yaml +--- +pipeline1: + content: 'input {} filter {} output {}' +``` + +Or, with a specific destination file path: + +```yaml +--- +pipeline2: + path: /etc/logstash/pipelines.d/pipeline2.pipeline + content: 'input {} filter {} output {}' +``` + +`content` can also span multiple lines: + +```yaml +--- +pipeline2.pipeline: + content: | + input { + syslog {} + } + output { + elasticsearch {} + } +``` + ### Patterns Many plugins (notably [Grok](http://logstash.net/docs/latest/filters/grok)) use *patterns*. While many are included in Logstash already, additional site-specific patterns can be managed as well. diff --git a/manifests/init.pp b/manifests/init.pp index c63a6068..92af063c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -152,6 +152,7 @@ $startup_options = {}, $jvm_options = [], Array $pipelines = [], + Hash $pipeline_files = {}, Boolean $manage_repo = true, ) { @@ -171,4 +172,5 @@ include logstash::package include logstash::config include logstash::service + include logstash::pipeline_files } diff --git a/manifests/pipeline_files.pp b/manifests/pipeline_files.pp new file mode 100644 index 00000000..47eadede --- /dev/null +++ b/manifests/pipeline_files.pp @@ -0,0 +1,29 @@ +# This class manages pipeline configuration files for Logstash. +# +# @example Include this class to ensure its resources are available. +# include logstash::pipeline_files +# +# @example Pass values to this class using an ENC with a specific path +# pipeline2: +# path: "/etc/logstash/conf.d/pipeline2.pipeline" +# content: pipeline2 +# +# @example Pass values to this class using an ENC without a specific path +# pipeline2: +# content: pipeline2 +# +# @author https://github.com/XeonFibre +# +class logstash::pipeline_files { + + $pipeline_files = $logstash::pipeline_files + + if(!empty($pipeline_files)) { + $pipeline_files.each |String $id, Hash $attributes| { + logstash::configfile { $id: + content => $attributes[content], + path => $attributes[path], + } + } + } +} diff --git a/spec/acceptance/class_logstash_spec.rb b/spec/acceptance/class_logstash_spec.rb index 42947214..2ddd7a95 100644 --- a/spec/acceptance/class_logstash_spec.rb +++ b/spec/acceptance/class_logstash_spec.rb @@ -263,6 +263,47 @@ end end + describe 'pipeline_files_parameter' do + context "with specific config path declared" do + before(:context) do + pipeline_files_puppet = <<-END + { "logstash-pipeline1.conf" => + { + "path" => "/etc/logstash/conf.d/logstash-pipeline1.conf", + "content" => "My config" + } + } + END + install_logstash_from_local_file("pipeline_files => #{pipeline_files_puppet}") + end + + it 'should render them to /etc/logstash/conf.d/logstash-pipeline1.conf' do + result = shell('cat /etc/logstash/conf.d/logstash-pipeline1.conf').stdout + expect(result).to eq("My config") + end + + end + + context "without specific config path declared" do + before(:context) do + pipeline_files_puppet = <<-END + { "logstash-pipeline2.conf" => + { + "content" => "My config" + } + } + END + install_logstash_from_local_file("pipeline_files => #{pipeline_files_puppet}") + end + + it 'should render them to /etc/logstash/conf.d/logstash-pipeline2.conf' do + result = shell('cat /etc/logstash/conf.d/logstash-pipeline2.conf').stdout + expect(result).to eq("My config") + end + + end + end + describe 'xpack_management_enabled_parameter' do context 'when set true with dotted notation' do before(:context) do