Skip to content

Commit

Permalink
Added option to use content as input for patternfile
Browse files Browse the repository at this point in the history
  • Loading branch information
michakrause authored and Micha Krause committed Jan 22, 2016
1 parent 6023462 commit 2f74aea
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
39 changes: 26 additions & 13 deletions manifests/patternfile.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
# Puppet file resource of the pattern file ( puppet:// )
# Value type is string
# Default value: None
# This variable is required
#
# [*content*]
# Content of the Pattern file
# Value type is string
# Default value: None
#
# [*filename*]
# if you would like the actual file name to be different then the source file name
Expand Down Expand Up @@ -39,25 +43,34 @@
# * Richard Pijnenburg <mailto:richard.pijnenburg@elasticsearch.com>
#
define logstash::patternfile (
$source,
$source = undef,
$content = undef,
$filename = '',
){

validate_re($source, '^(puppet|file)://', 'Source must be either from a puppet fileserver or a locally accessible file (begins with either puppet:// or file://)' )
if $source {
validate_re($source, '^(puppet|file)://', 'Source must be from a puppet fileserver or a locally accessible file (begins with either puppet:// or file://)' )
$filename_real = $filename ? {
'' => inline_template('<%= @source.split("/").last %>'),
default => $filename
}
}
elsif $content {
$filename_real = $title
}
else {
fail("you must specify ${source} or ${content}")
}

$patterns_dir = "${logstash::configdir}/patterns"

$filename_real = $filename ? {
'' => inline_template('<%= @source.split("/").last %>'),
default => $filename
}

file { "${patterns_dir}/${filename_real}":
ensure => 'file',
owner => $logstash::logstash_user,
group => $logstash::logstash_group,
mode => '0644',
source => $source,
ensure => 'file',
owner => $logstash::logstash_user,
group => $logstash::logstash_group,
mode => '0644',
source => $source,
content => $content,
}

}
13 changes: 12 additions & 1 deletion spec/defines/001_logstash_patternfile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
:operatingsystem => 'CentOS',
:kernel => 'Linux'
} end

let(:title) { 'foopatterns' }

let(:pre_condition) { 'class {"logstash": }'}
Expand All @@ -33,6 +33,17 @@

end

context 'using content' do

let(:params) { {
:content => "FOO: BAR"
} }

it { should contain_logstash__patternfile('foopatterns') }
it { should contain_file('/etc/logstash/patterns/foopatterns').with( :content => 'FOO: BAR') }

end

context 'set filename' do

let(:params) { {
Expand Down

0 comments on commit 2f74aea

Please sign in to comment.