diff --git a/manifests/jail.pp b/manifests/jail.pp index 196baba..b9ed6c9 100644 --- a/manifests/jail.pp +++ b/manifests/jail.pp @@ -21,6 +21,8 @@ # $action - The action to take when fail2ban finds $maxretry $filter-matching # records in $logpath # $bantime - How much time to apply the ban, in seconds +# $findtime - The counter is set to zero if no match is found within "findtime" +# seconds. define fail2ban::jail ( $jailname = '', @@ -32,6 +34,7 @@ define fail2ban::jail ( $logpath = '', $maxretry = '', $bantime = '', + $findtime = '', $enable = true ) { include concat::setup @@ -119,7 +122,7 @@ define fail2ban::jail ( notify => Service['fail2ban'], } } - concat::fragment{ "fail2ban_jail_$name": + concat::fragment{ "fail2ban_jail_${name}": ensure => $ensure, target => $fail2ban::jails_file, content => template('fail2ban/concat/jail.local-stanza.erb'), diff --git a/spec/defines/fail2ban_jail_spec.rb b/spec/defines/fail2ban_jail_spec.rb index 406d5a2..167fe52 100644 --- a/spec/defines/fail2ban_jail_spec.rb +++ b/spec/defines/fail2ban_jail_spec.rb @@ -1,4 +1,4 @@ -require "#{File.join(File.dirname(__FILE__),'..','spec_helper.rb')}" +require File.join(File.dirname(__FILE__), '..', 'spec_helper.rb') describe 'fail2ban::jail' do @@ -7,14 +7,15 @@ describe 'fail2ban::jail' do let(:facts) { { :ipaddress => '10.42.42.42', :jails_file => '/etc/fail2ban/jail.local', :concat_basedir => '/var/lib/puppet/concat'} } describe 'Test basic jail.local is created' do - let(:params) { { :name => 'sample1', - :port => '42', - :logpath => '/path/to/somelog', - :enable => true, } } + let(:params) { { :name => 'sample1', + :port => '42', + :logpath => '/path/to/somelog', + :enable => true, + :findtime => '9000', } } it { should include_class('concat::setup') } # it { should contain_concat__fragment('fail2ban_jail_sample1').with_target('/etc/fail2ban/jail.local').with_content(/*port = 42 #logpath = \/path\/to\/somelog*/) } - it { should contain_concat__fragment('fail2ban_jail_sample1').with_target('/etc/fail2ban/jail.local').with_content("##################\n[fail2ban::jail]\nenabled = true\nfilter = fail2ban::jail\nport = 42\nlogpath = /path/to/somelog\n\n") } + it { should contain_concat__fragment('fail2ban_jail_sample1').with_target('/etc/fail2ban/jail.local').with_content("##################\n[fail2ban::jail]\nenabled = true\nfilter = fail2ban::jail\nport = 42\nlogpath = /path/to/somelog\nfindtime = 9000\n\n") } end end diff --git a/templates/concat/jail.local-stanza.erb b/templates/concat/jail.local-stanza.erb index 390aca7..453e5be 100644 --- a/templates/concat/jail.local-stanza.erb +++ b/templates/concat/jail.local-stanza.erb @@ -21,4 +21,7 @@ maxretry = <%= @real_maxretry %> <% if @real_bantime != '' -%> bantime = <%= @real_bantime %> <% end -%> +<% if @findtime != '' -%> +findtime = <%= @findtime %> +<% end -%>