From ea05a30447537a249fc455c8f8af5819cd0ca3ca Mon Sep 17 00:00:00 2001 From: rmenezes Date: Mon, 6 Jul 2015 21:28:25 -0700 Subject: [PATCH] Add the ability pass multiple networks for the community string --- spec/classes/snmp_init_spec.rb | 10 ++++++++++ templates/snmpd.conf.erb | 24 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/spec/classes/snmp_init_spec.rb b/spec/classes/snmp_init_spec.rb index 327563f4..7f418d59 100644 --- a/spec/classes/snmp_init_spec.rb +++ b/spec/classes/snmp_init_spec.rb @@ -790,6 +790,16 @@ ]) end end + + describe 'ro_network => [ "127.0.0.1", "192.168.1.1/24", ]' do + let(:params) {{ :ro_network => [ '127.0.0.1', '192.168.1.1/24', ] }} + it 'should contain File[snmpd.conf] with contents "127.0.0.1" and "192.168.1.1/24"' do + verify_contents(catalogue, 'snmpd.conf', [ + 'rocommunity public 127.0.0.1', + 'rocommunity public 192.168.1.1/24', + ]) + end + end end context 'on a supported osfamily (Debian), custom parameters' do diff --git a/templates/snmpd.conf.erb b/templates/snmpd.conf.erb index 21679016..7bd48d75 100644 --- a/templates/snmpd.conf.erb +++ b/templates/snmpd.conf.erb @@ -15,17 +15,41 @@ agentaddress <%= @agentaddress.join(',') %> # ------------------------------------------------------------------------------ # Traditional Access Control <% if @ro_community and (@ro_community.size > 0) -%> +<% if (@ro_network.is_a?(Array)) and (@ro_network.count > 0) -%> +<% @ro_network.each do |ro_net| -%> +rocommunity <%= @ro_community %> <%= ro_net %> +<% end -%> +<% else -%> rocommunity <%= @ro_community %> <%= @ro_network %> <% end -%> +<% end -%> <% if @ro_community6 and (@ro_community6.size > 0) -%> +<% if (@ro_network6.is_a?(Array)) and (@ro_network6.count > 0) -%> +<% @ro_network6.each do |ro_net6| -%> +rocommunity6 <%= @ro_community6 %> <%= ro_net6 %> +<% end -%> +<% else -%> rocommunity6 <%= @ro_community6 %> <%= @ro_network6 %> <% end -%> +<% end -%> <% if @rw_community and (@rw_community.size > 0) -%> +<% if (@rw_network.is_a?(Array)) and (@rw_network.count > 0) -%> +<% @rw_network.each do |rw_net| -%> +rwcommunity <%= @rw_community %> <%= rw_net %> +<% end -%> +<% else -%> rwcommunity <%= @rw_community %> <%= @rw_network %> <% end -%> +<% end -%> <% if @rw_community6 and (@rw_community6.size > 0) -%> +<% if (@rw_network6.is_a?(Array)) and (@rw_network6.count > 0) -%> +<% @rw_network6.each do |rw_net6| -%> +rwcommunity6 <%= @rw_community6 %> <%= rw_net6 %> +<% end -%> +<% else -%> rwcommunity6 <%= @rw_community6 %> <%= @rw_network6 %> <% end -%> +<% end -%> # ------------------------------------------------------------------------------ # VACM Configuration