diff --git a/README.md b/README.md index 31356f647..7b55998e6 100644 --- a/README.md +++ b/README.md @@ -1374,6 +1374,44 @@ class { 'collectd::plugin::postgresql': } ``` +#### Class: `collectd::plugin::powerdns` + +You can either specify powerdns servers / recursors at once: + +```puppet +class { 'collectd::plugin::powerdns': + recursors => { + 'recursor1' => { + 'socket' => '/var/run/my-socket', + 'collect' => ['cache-hits', 'cache-misses'], + }, + 'recursor2' => {} + }, + servers => { + 'server1' => { + 'socket' => '/var/run/my-socket', + 'collect' => ['latency', 'recursing-answers', 'recursing-questions'], + } + }, +} +``` + +Or define single server / recursor: + +```puppet +collectd::plugin::powerdns::recursor { 'my-recursor' : + socket => '/var/run/my-socket', + collect => ['cache-hits', 'cache-misses'], +} +``` + +```puppet +collectd::plugin::powerdns::server { 'my-server' : + socket => '/var/run/my-socket', + collect => ['latency', 'recursing-answers', 'recursing-questions'], +} +``` + #### Class: `collectd::plugin::processes` You can either specify processes / process matches at once: diff --git a/manifests/plugin/powerdns.pp b/manifests/plugin/powerdns.pp new file mode 100644 index 000000000..a49f8b9e9 --- /dev/null +++ b/manifests/plugin/powerdns.pp @@ -0,0 +1,56 @@ +# See http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_powerdns +class collectd::plugin::powerdns ( + Enum['present', 'absent'] $ensure = 'present', + Integer $order = 10, + Optional[Numeric] $interval = undef, + Optional[Hash[String, Hash]] $servers = undef, + Optional[Hash[String, Hash]] $recursors = undef, + Optional[String] $local_socket = undef, +) { + + include collectd + + collectd::plugin { 'powerdns': + ensure => $ensure, + order => $order, + interval => $interval, + } + + concat { "${collectd::plugin_conf_dir}/powerdns-config.conf": + ensure => $ensure, + mode => $collectd::config_mode, + owner => $collectd::config_owner, + group => $collectd::config_group, + notify => Service[$collectd::service_name], + ensure_newline => true, + } + concat::fragment { 'collectd_plugin_powerdns_conf_header': + order => '00', + content => epp('collectd/plugin/powerdns-header.conf.epp'), + target => "${collectd::plugin_conf_dir}/powerdns-config.conf", + } + + concat::fragment { 'collectd_plugin_powerdns_conf_footer': + order => '99', + content => '', + target => "${collectd::plugin_conf_dir}/powerdns-config.conf", + } + + $defaults = { 'ensure' => $ensure } + + if $servers { + create_resources( + collectd::plugin::powerdns::server, + $servers, + $defaults, + ) + } + + if $recursors { + create_resources( + collectd::plugin::powerdns::recursor, + $recursors, + $defaults + ) + } +} diff --git a/manifests/plugin/powerdns/recursor.pp b/manifests/plugin/powerdns/recursor.pp new file mode 100644 index 000000000..85ff06c21 --- /dev/null +++ b/manifests/plugin/powerdns/recursor.pp @@ -0,0 +1,19 @@ +define collectd::plugin::powerdns::recursor ( + Enum['present', 'absent'] $ensure = 'present', + Optional[String[1]] $socket = undef, + Array[String[1]] $collect = [], +) { + + include collectd::plugin::powerdns + include collectd + + concat::fragment{ "collectd_plugin_powerdns_conf_recursor_${name}": + order => '51', + content => epp('collectd/plugin/powerdns/recursor.conf.epp', { + 'name' => $name, + 'socket' => $socket, + 'collect' => $collect, + }), + target => "${collectd::plugin_conf_dir}/powerdns-config.conf", + } +} diff --git a/manifests/plugin/powerdns/server.pp b/manifests/plugin/powerdns/server.pp new file mode 100644 index 000000000..79d87da80 --- /dev/null +++ b/manifests/plugin/powerdns/server.pp @@ -0,0 +1,19 @@ +define collectd::plugin::powerdns::server ( + Enum['present', 'absent'] $ensure = 'present', + Optional[String[1]] $socket = undef, + Array[String[1]] $collect = [], +) { + + include collectd::plugin::powerdns + include collectd + + concat::fragment{ "collectd_plugin_powerdns_conf_server_${name}": + order => '50', + content => epp('collectd/plugin/powerdns/server.conf.epp', { + 'name' => $name, + 'socket' => $socket, + 'collect' => $collect, + }), + target => "${collectd::plugin_conf_dir}/powerdns-config.conf", + } +} diff --git a/spec/classes/collectd_plugin_powerdns_spec.rb b/spec/classes/collectd_plugin_powerdns_spec.rb new file mode 100644 index 000000000..e8c578c47 --- /dev/null +++ b/spec/classes/collectd_plugin_powerdns_spec.rb @@ -0,0 +1,109 @@ +require 'spec_helper' + +describe 'collectd::plugin::powerdns', type: :class do + on_supported_os(baseline_os_hash).each do |os, facts| + context "on #{os} " do + let :facts do + facts + end + + options = os_specific_options(facts) + context ':ensure => present' do + context ':ensure => present and default parameters' do + it "Will create #{options[:plugin_conf_dir]}/10-powerdns.conf to load the plugin" do + is_expected.to contain_file('powerdns.load').with( + ensure: 'present', + path: "#{options[:plugin_conf_dir]}/10-powerdns.conf", + content: %r{LoadPlugin powerdns} + ) + end + + it "Will create #{options[:plugin_conf_dir]}/powerdns-config.conf" do + is_expected.to contain_concat("#{options[:plugin_conf_dir]}/powerdns-config.conf").that_requires('File[collectd.d]') + is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_header').with( + content: "\n", + target: "#{options[:plugin_conf_dir]}/powerdns-config.conf", + order: '00' + ) + end + + it "Will create #{options[:plugin_conf_dir]}/powerdns-config.conf" do + is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_footer').with( + content: %r{}, + target: "#{options[:plugin_conf_dir]}/powerdns-config.conf", + order: '99' + ) + end + end + context ':ensure => present and overrided parameters' do + let :params do + { + local_socket: '/var/run/whatever', + servers: { + one: { + collect: %w[latency recursing-answers recursing-questions], + socket: '/var/run/server1.sock' + }, + two: {} + }, + recursors: { + three: { + collect: %w[cache-hits cache-misses], + socket: '/var/run/server3.sock' + }, + four: {} + } + } + end + + it "Will create #{options[:plugin_conf_dir]}/powerdns-config.conf" do + is_expected.to contain_concat("#{options[:plugin_conf_dir]}/powerdns-config.conf").that_requires('File[collectd.d]') + is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_header').with( + content: " + LocalSocket \"/var/run/whatever\" +", + target: "#{options[:plugin_conf_dir]}/powerdns-config.conf", + order: '00' + ) + is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_server_one').with( + content: " + Collect \"latency\" + Collect \"recursing-answers\" + Collect \"recursing-questions\" + Socket \"/var/run/server1.sock\" + +", + target: "#{options[:plugin_conf_dir]}/powerdns-config.conf", + order: '50' + ) + is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_server_two').with( + content: " + +", + target: "#{options[:plugin_conf_dir]}/powerdns-config.conf", + order: '50' + ) + + is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_recursor_three').with( + content: " + Collect \"cache-hits\" + Collect \"cache-misses\" + Socket \"/var/run/server3.sock\" + +", + target: "#{options[:plugin_conf_dir]}/powerdns-config.conf", + order: '51' + ) + is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_recursor_four').with( + content: " + +", + target: "#{options[:plugin_conf_dir]}/powerdns-config.conf", + order: '51' + ) + end + end + end + end + end +end diff --git a/templates/plugin/powerdns-header.conf.epp b/templates/plugin/powerdns-header.conf.epp new file mode 100644 index 000000000..859ca7f17 --- /dev/null +++ b/templates/plugin/powerdns-header.conf.epp @@ -0,0 +1,4 @@ + +<% unless $collectd::plugin::powerdns::local_socket =~ Undef { -%> + LocalSocket "<%= $collectd::plugin::powerdns::local_socket %>" +<% } -%> diff --git a/templates/plugin/powerdns/recursor.conf.epp b/templates/plugin/powerdns/recursor.conf.epp new file mode 100644 index 000000000..72d063d19 --- /dev/null +++ b/templates/plugin/powerdns/recursor.conf.epp @@ -0,0 +1,12 @@ +<%- | String $name, + Optional[String] $socket = undef, + Array[String] $collect = [], +| -%> + "> +<% $collect.each |$k| { -%> + Collect "<%= $k %>" +<% } -%> +<% unless $socket =~ Undef { -%> + Socket "<%= $socket %>" +<% } -%> + diff --git a/templates/plugin/powerdns/server.conf.epp b/templates/plugin/powerdns/server.conf.epp new file mode 100644 index 000000000..45148ca69 --- /dev/null +++ b/templates/plugin/powerdns/server.conf.epp @@ -0,0 +1,12 @@ +<%- | String $name, + Optional[String] $socket = undef, + Array[String] $collect = [], +| -%> + "> +<% $collect.each |$k| { -%> + Collect "<%= $k %>" +<% } -%> +<% unless $socket =~ Undef { -%> + Socket "<%= $socket %>" +<% } -%> +