diff --git a/templates/munin-node.conf.erb b/templates/munin-node.conf.erb index 4d95b77..724bee0 100644 --- a/templates/munin-node.conf.erb +++ b/templates/munin-node.conf.erb @@ -1,44 +1,61 @@ # /etc/munin/munin-node.conf - config-file for munin-node # # This file is handled by puppet, any local changes will be lost # +<% + require 'ipaddr' + + addresses = [] + unrecognized = [] + + Array(@allow).flatten.each do |line| + begin + a = IPAddr.new(line) + if a.ipv4? or a.ipv6? + addresses << line + end + rescue IPAddr::InvalidAddressError + # Treat invalid addresses as "allow" arguments, as they can be + # regular expressions. + unrecognized << line + end + end +-%> host_name <%= scope.lookupvar('::fqdn') %> log_level 4 log_file <%= @log_dir %>/munin-node.log port 4949 pid_file /var/run/munin/munin-node.pid background 1 setsid 1 # Which port to bind to; user root group <%= @file_group %> # Regexps for files to ignore ignore_file ~$ ignore_file \.bak$ ignore_file %$ ignore_file \.dpkg-(tmp|new|old|dist)$ ignore_file \.rpm(save|new)$ ignore_file \.puppet-bak$ # Hosts to allow - -<% Array(@allow).flatten.each do |line| -%> -<% if line.match(/^\d+\.\d+\.\d+\.\d+$/) -%> -<%= line.gsub(".", "\\.").sub(/^/, "allow ^").sub(/$/, "$") %> -<% elsif line.match(/^\d+\.\d+\.\d+\.\d+\/\d+$/) -%> -<%= line.sub(/^/, "cidr_allow ") %> -<% elsif line.match(/^[0-9a-f:]+$/i) -%> -<%= line.sub(/^/, "allow ^").sub(/$/, "$") %> -<% elsif line.match(/^[0-9a-f:]+\/\d+$/i) -%> -<%= line.sub(/^/, "cidr_allow ") %> -<% end -%> -<% end -%> +<% addresses.each do |line| -%> +<% if line.match(/\//) -%> +cidr_allow <%= line %> +<% else -%> +allow ^<%= Regexp.quote(line) %>$ +<% end -%> +<% end -%> +<% unrecognized.each do |line| -%> +allow <%= line %> +<% end -%> <% Array(@nodeconfig).each do |line| -%> <%= line %> <% end -%>