From 80a6650164fa17894d108f2e259a575de5c208f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20B=C3=A9rtoli?= Date: Sun, 24 Nov 2013 19:24:09 -0300 Subject: [PATCH] Add multiple logpaths support (closes #11) --- manifests/jail.pp | 9 ++++--- spec/defines/fail2ban_jail_spec.rb | 35 ++++++++++++++++++++++++-- templates/concat/jail.local-stanza.erb | 4 +-- 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/manifests/jail.pp b/manifests/jail.pp index 52742dc..68512b9 100644 --- a/manifests/jail.pp +++ b/manifests/jail.pp @@ -78,9 +78,12 @@ define fail2ban::jail ( default => $action, } - $real_logpath = $logpath ? { - '' => '', - default => $logpath, + $array_logpath = is_array($logpath) ? { + false => $logpath ? { + '' => [], + default => [$logpath], + }, + default => $logpath, } $real_maxretry = $maxretry ? { diff --git a/spec/defines/fail2ban_jail_spec.rb b/spec/defines/fail2ban_jail_spec.rb index fecfa05..cfb1884 100644 --- a/spec/defines/fail2ban_jail_spec.rb +++ b/spec/defines/fail2ban_jail_spec.rb @@ -27,7 +27,9 @@ filter = fail2ban::jail " end - it { should contain_concat__fragment('fail2ban_jail_sample1').with_target('/etc/fail2ban/jail.local').with_content(expected) } + it 'should create a named jail, enabled and with a filter of the same name' do + should contain_concat__fragment('fail2ban_jail_sample1').with_target('/etc/fail2ban/jail.local').with_content(expected) + end end describe 'Test jail.local is created with all options' do @@ -62,6 +64,35 @@ findtime = 9000 " end - it { should contain_concat__fragment('fail2ban_jail_sample1').with_target('/etc/fail2ban/jail.local').with_content(expected) } + it 'should create a customized jail, with own actions parsing a single log file' do + should contain_concat__fragment('fail2ban_jail_sample1').with_target('/etc/fail2ban/jail.local').with_content(expected) + end + end + describe 'Test jail.local is created with multiple logpaths' do + let(:params) do + { + :name => 'title_sample2', + :jailname => 'sample2', + :port => '44', + :logpath => [ '/path/to/somelog_1', '/path/to/somelog_2' ], + :bantime => '3003', + } + end + let(:expected) do +"################## +[sample2] +enabled = true +filter = sample2 +port = 44 +logpath = /path/to/somelog_1 + /path/to/somelog_2 +bantime = 3003 + +" + end + + it 'should create a customized jail, with own actions parsing a single log file' do + should contain_concat__fragment('fail2ban_jail_title_sample2').with_target('/etc/fail2ban/jail.local').with_content(expected) + end end end diff --git a/templates/concat/jail.local-stanza.erb b/templates/concat/jail.local-stanza.erb index 91155ad..381b808 100644 --- a/templates/concat/jail.local-stanza.erb +++ b/templates/concat/jail.local-stanza.erb @@ -10,8 +10,8 @@ port = <%= @array_port * ',' %> <% if @array_action != [] -%> action = <%= @array_action.join("\n\t") %> <% end -%> -<% if @real_logpath != '' -%> -logpath = <%= @real_logpath %> +<% if @array_logpath != [] -%> +logpath = <%= @array_logpath.join("\n\t") %> <% end -%> <% if @real_maxretry != '' -%> maxretry = <%= @real_maxretry %>