Skip to content

Commit

Permalink
ping: set parameters type and add Size
Browse files Browse the repository at this point in the history
This change:
* adds the parameter type for all options
* adds the missing option size
* converts template to epp
  • Loading branch information
sileht committed Jun 12, 2018
1 parent e69dd24 commit 55286fb
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 32 deletions.
19 changes: 10 additions & 9 deletions manifests/plugin/ping.pp
@@ -1,14 +1,15 @@
# See http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_ping
class collectd::plugin::ping (
Array $hosts,
$ensure = 'present',
$manage_package = undef,
$interval = undef,
$timeout = undef,
$ttl = undef,
$source_address = undef,
$device = undef,
$max_missed = undef,
Enum['present', 'absent'] $ensure = 'present',
Optional[Boolean] $manage_package = undef,
Optional[Numeric] $interval = undef,
Optional[Numeric] $timeout = undef,
Optional[Integer[0,255]] $ttl = undef,
Optional[String] $source_address = undef,
Optional[String] $device = undef,
Optional[Integer[-1]] $max_missed = undef,
Optional[Integer[0]] $size = undef,
) {

include ::collectd
Expand All @@ -26,6 +27,6 @@
collectd::plugin { 'ping':
ensure => $ensure,
interval => $interval,
content => template('collectd/plugin/ping.conf.erb'),
content => epp('collectd/plugin/ping.conf.epp'),
}
}
44 changes: 44 additions & 0 deletions spec/classes/collectd_plugin_ping_spec.rb
Expand Up @@ -26,6 +26,50 @@
end
end

context 'all options set' do
let :params do
{
hosts: ['google.com'],
manage_package: true,
interval: 1.23,
timeout: 0.5,
ttl: 5,
source_address: '123.123.123.123',
device: 'eth0',
max_missed: 12,
size: 5
}
end

content = <<EOS
# Generated by Puppet
<LoadPlugin ping>
Globals false
Interval 1.23
</LoadPlugin>
<Plugin ping>
Host "google.com"
Interval "1.23"
Timeout "0.5"
TTL "5"
SourceAddress "123.123.123.123"
Device "eth0"
MaxMissed "12"
Size "5"
</Plugin>
EOS

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

context ':hosts => [\'google.com\', \'puppetlabs.com\']' do
let :params do
{ hosts: ['google.com', 'puppetlabs.com'] }
Expand Down
26 changes: 26 additions & 0 deletions templates/plugin/ping.conf.epp
@@ -0,0 +1,26 @@
<Plugin ping>
<% $collectd::plugin::ping::hosts.each |$host| { -%>
Host "<%= $host %>"
<% } -%>
<% if $collectd::plugin::ping::interval { -%>
Interval "<%= $collectd::plugin::ping::interval %>"
<% } -%>
<% if $collectd::plugin::ping::timeout { -%>
Timeout "<%= $collectd::plugin::ping::timeout %>"
<% } -%>
<% if $collectd::plugin::ping::ttl { -%>
TTL "<%= $collectd::plugin::ping::ttl %>"
<% } -%>
<% if $collectd::plugin::ping::source_address { -%>
SourceAddress "<%= $collectd::plugin::ping::source_address %>"
<% } -%>
<% if $collectd::plugin::ping::device { -%>
Device "<%= $collectd::plugin::ping::device %>"
<% } -%>
<% if $collectd::plugin::ping::max_missed { -%>
MaxMissed "<%= $collectd::plugin::ping::max_missed %>"
<% } -%>
<% if $collectd::plugin::ping::size { -%>
Size "<%= $collectd::plugin::ping::size %>"
<% } -%>
</Plugin>
23 changes: 0 additions & 23 deletions templates/plugin/ping.conf.erb

This file was deleted.

0 comments on commit 55286fb

Please sign in to comment.