diff --git a/manifests/plugin/ping.pp b/manifests/plugin/ping.pp index f370404de..634e9ec1d 100644 --- a/manifests/plugin/ping.pp +++ b/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 @@ -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'), } } diff --git a/spec/classes/collectd_plugin_ping_spec.rb b/spec/classes/collectd_plugin_ping_spec.rb index 781549aa6..6f4dfdb71 100644 --- a/spec/classes/collectd_plugin_ping_spec.rb +++ b/spec/classes/collectd_plugin_ping_spec.rb @@ -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 = < + Globals false + Interval 1.23 + + + + Host "google.com" + Interval "1.23" + Timeout "0.5" + TTL "5" + SourceAddress "123.123.123.123" + Device "eth0" + MaxMissed "12" + Size "5" + + +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'] } diff --git a/templates/plugin/ping.conf.epp b/templates/plugin/ping.conf.epp new file mode 100644 index 000000000..80e3bfe1e --- /dev/null +++ b/templates/plugin/ping.conf.epp @@ -0,0 +1,26 @@ + +<% $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 %>" +<% } -%> + diff --git a/templates/plugin/ping.conf.erb b/templates/plugin/ping.conf.erb deleted file mode 100644 index b1ed394c7..000000000 --- a/templates/plugin/ping.conf.erb +++ /dev/null @@ -1,23 +0,0 @@ - -<% @hosts.each do |host| -%> - Host "<%= host %>" -<% end -%> -<% if @interval %> - Interval "<%= @interval %>" -<% end -%> -<% if @timeout %> - Timeout "<%= @timeout %>" -<% end -%> -<% if @ttl %> - TTL "<%= @ttl %>" -<% end -%> -<% if @source_address %> - SourceAddress "<%= @source_address %>" -<% end -%> -<% if @device %> - Device "<%= @device %>" -<% end -%> -<% if @max_missed %> - MaxMissed "<%= @max_missed %>" -<% end -%> -