Skip to content

Commit

Permalink
Merge pull request #694 from herver/gh-693
Browse files Browse the repository at this point in the history
Add support for Chain6 directive
  • Loading branch information
traylenator committed Sep 19, 2017
2 parents 0ce348d + 70aba80 commit 64744f5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -885,7 +885,10 @@ class { 'collectd::plugin::ipmi':
class { 'collectd::plugin::iptables':
chains => {
'nat' => 'In_SSH',
'filter' => 'HTTP'
'filter' => 'HTTP',
},
chains6 => {
'filter' => 'HTTP6',
},
}
```
Expand Down
5 changes: 4 additions & 1 deletion examples/plugins/iptables.pp
@@ -1,8 +1,11 @@
include ::collectd

class { '::collectd::plugin::iptables':
chains => {
chains => {
'nat' => 'In_SSH',
'filter' => 'HTTP',
},
chains6 => {
'filter' => 'HTTP6',
},
}
2 changes: 2 additions & 0 deletions manifests/plugin/iptables.pp
Expand Up @@ -4,6 +4,7 @@
$ensure_package = 'present',
$manage_package = undef,
$chains = {},
$chains6 = {},
$interval = undef,
) {

Expand All @@ -12,6 +13,7 @@
$_manage_package = pick($manage_package, $::collectd::manage_package)

validate_hash($chains)
validate_hash($chains6)

if $::osfamily == 'RedHat' {
if $_manage_package {
Expand Down
14 changes: 14 additions & 0 deletions spec/classes/collectd_plugin_iptables_spec.rb
Expand Up @@ -26,6 +26,20 @@
end
end

context ':ensure => present and :chains6 => { \'filter\' => \'In6_SSH\' }' do
let :params do
{ chains6: { 'filter' => 'In6_SSH' } }
end

it "Will create #{options[:plugin_conf_dir]}/10-iptables.conf" do
is_expected.to contain_file('iptables.load').with(
ensure: 'present',
path: "#{options[:plugin_conf_dir]}/10-iptables.conf",
content: %r{Chain6 filter In6_SSH}
)
end
end

context ':ensure => present and :chains has two chains from the same table' do
let :params do
{ chains: {
Expand Down
11 changes: 9 additions & 2 deletions templates/plugin/iptables.conf.erb
@@ -1,9 +1,16 @@
<% if @chains -%>
<Plugin iptables>
<% if @chains -%>
<% @chains.each_pair do |table,chains|
Array(chains).each do |chain| -%>
Chain <%= table %> <%= chain %>
<% end -%>
<% end -%>
</Plugin>
<% end -%>
<% if @chains6 -%>
<% @chains6.each_pair do |table6,chains6|
Array(chains6).each do |chain6| -%>
Chain6 <%= table6 %> <%= chain6 %>
<% end -%>
<% end -%>
<% end -%>
</Plugin>

0 comments on commit 64744f5

Please sign in to comment.