Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add powerdns plugin #824

Merged
merged 1 commit into from
Jul 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
56 changes: 56 additions & 0 deletions manifests/plugin/powerdns.pp
Original file line number Diff line number Diff line change
@@ -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 => '</Plugin>',
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
)
}
}
19 changes: 19 additions & 0 deletions manifests/plugin/powerdns/recursor.pp
Original file line number Diff line number Diff line change
@@ -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",
}
}
19 changes: 19 additions & 0 deletions manifests/plugin/powerdns/server.pp
Original file line number Diff line number Diff line change
@@ -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",
}
}
109 changes: 109 additions & 0 deletions spec/classes/collectd_plugin_powerdns_spec.rb
Original file line number Diff line number Diff line change
@@ -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: "<Plugin \"powerdns\">\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{</Plugin>},
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: "<Plugin \"powerdns\">
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: " <Server \"one\">
Collect \"latency\"
Collect \"recursing-answers\"
Collect \"recursing-questions\"
Socket \"/var/run/server1.sock\"
</Server>
",
target: "#{options[:plugin_conf_dir]}/powerdns-config.conf",
order: '50'
)
is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_server_two').with(
content: " <Server \"two\">
</Server>
",
target: "#{options[:plugin_conf_dir]}/powerdns-config.conf",
order: '50'
)

is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_recursor_three').with(
content: " <Recursor \"three\">
Collect \"cache-hits\"
Collect \"cache-misses\"
Socket \"/var/run/server3.sock\"
</Recursor>
",
target: "#{options[:plugin_conf_dir]}/powerdns-config.conf",
order: '51'
)
is_expected.to contain_concat__fragment('collectd_plugin_powerdns_conf_recursor_four').with(
content: " <Recursor \"four\">
</Recursor>
",
target: "#{options[:plugin_conf_dir]}/powerdns-config.conf",
order: '51'
)
end
end
end
end
end
end
4 changes: 4 additions & 0 deletions templates/plugin/powerdns-header.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<Plugin "powerdns">
<% unless $collectd::plugin::powerdns::local_socket =~ Undef { -%>
LocalSocket "<%= $collectd::plugin::powerdns::local_socket %>"
<% } -%>
12 changes: 12 additions & 0 deletions templates/plugin/powerdns/recursor.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%- | String $name,
Optional[String] $socket = undef,
Array[String] $collect = [],
| -%>
<Recursor "<%= $name %>">
<% $collect.each |$k| { -%>
Collect "<%= $k %>"
<% } -%>
<% unless $socket =~ Undef { -%>
Socket "<%= $socket %>"
<% } -%>
</Recursor>
12 changes: 12 additions & 0 deletions templates/plugin/powerdns/server.conf.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<%- | String $name,
Optional[String] $socket = undef,
Array[String] $collect = [],
| -%>
<Server "<%= $name %>">
<% $collect.each |$k| { -%>
Collect "<%= $k %>"
<% } -%>
<% unless $socket =~ Undef { -%>
Socket "<%= $socket %>"
<% } -%>
</Server>