Skip to content

Commit

Permalink
Merge pull request #107 from coreone/filters
Browse files Browse the repository at this point in the history
Add filter options
  • Loading branch information
bastelfreak authored Jan 24, 2019
2 parents 0c12580 + c6f814f commit bfc03b8
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
6 changes: 5 additions & 1 deletion manifests/jail.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
Optional[String] $filter_includes = undef,
Optional[String] $filter_failregex = undef,
Optional[String] $filter_ignoreregex = undef,
Optional[Integer] $filter_maxlines = undef,
Optional[String] $filter_datepattern = undef,
$filter_additional_config = undef,
Boolean $enabled = true,
Optional[String] $action = undef,
Expand Down Expand Up @@ -37,7 +39,9 @@
filter_additional_config => $filter_additional_config,
filter_failregex => $filter_failregex,
filter_ignoreregex => $filter_ignoreregex,
journalmatch => $journalmatch
filter_maxlines => $filter_maxlines,
filter_datepattern => $filter_datepattern,
journalmatch => $journalmatch,
}
),
owner => $config_file_owner,
Expand Down
22 changes: 20 additions & 2 deletions spec/defines/fail2ban_jail_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@

let(:params) do
{
'logpath' => '/var/log/syslog',
'filter_failregex' => 'Login failed for user .* from <HOST>'
'logpath' => '/var/log/syslog',
'filter_failregex' => 'Login failed for user .* from <HOST>',
'filter_maxlines' => 10,
'filter_datepattern' => '%%Y-%%m-%%d %%H:%%M(?::%%S)?'
}
end

Expand All @@ -36,6 +38,22 @@
'content' => %r{failregex = Login failed for user .* from <HOST>}
)
end

it do
is_expected.to contain_file('custom_filter_spec_test_jail').with(
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'content' => %r{maxlines = 10}
)
end

it do
is_expected.to contain_file('custom_filter_spec_test_jail').with(
'ensure' => 'file',
'notify' => 'Service[fail2ban]',
'content' => %r{datepattern = %%Y-%%m-%%d %%H:%%M(?::%%S)?}
)
end
end
end
end
6 changes: 6 additions & 0 deletions templates/common/custom_filter.conf.epp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
<% if $journalmatch { -%>
journalmatch = <%= $journalmatch %>
<% } -%>
<% if $filter_maxlines { -%>
maxlines = <%= $filter_maxlines %>
<% } -%>
<% if $filter_datepattern { -%>
datepattern = <%= $filter_datepattern %>
<% } -%>

<% if $findtime { -%>
[INCLUDES]
Expand Down

0 comments on commit bfc03b8

Please sign in to comment.