From b671d003d339b1661489bfadc75fe89c3dc6b5ad Mon Sep 17 00:00:00 2001 From: txaj Date: Wed, 12 Nov 2014 14:59:21 -0700 Subject: [PATCH] Uses the LoadPlugin syntax with bracket when supported This is fully backwards compatible. The version check is done exactly how it's supposed to ; I checked the sources of collectd to be sure there's no conflict. Globals has always defaulted to false so I'm making it default to false in this module. I'm not setting it undef because that's a boolean and we got issues with checking if a boolean is false or undef (see #182). --- manifests/plugin.pp | 12 +++++++----- spec/classes/collectd_plugin_swap_spec.rb | 4 ++-- templates/loadplugin.conf.erb | 13 +++++++++++++ 3 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 templates/loadplugin.conf.erb diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 53fc66cd6..76d411235 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -1,9 +1,11 @@ # define collectd::plugin ( - $ensure = 'present', - $content = undef, - $order = '10', - $plugin = $name + $ensure = 'present', + $content = undef, + $order = '10', + $globals = false, + $interval = undef, + $plugin = $name ) { include collectd::params @@ -16,7 +18,7 @@ owner => root, group => $root_group, mode => '0640', - content => "# Generated by Puppet\nLoadPlugin ${plugin}\n\n${content}", + content => template('collectd/loadplugin.conf.erb'), notify => Service['collectd'], } diff --git a/spec/classes/collectd_plugin_swap_spec.rb b/spec/classes/collectd_plugin_swap_spec.rb index ea9274d0e..3bb6f17e0 100644 --- a/spec/classes/collectd_plugin_swap_spec.rb +++ b/spec/classes/collectd_plugin_swap_spec.rb @@ -26,7 +26,7 @@ should contain_file('swap.load').with({ :ensure => 'present', :path => '/etc/collectd.d/10-swap.conf', - :content => "# Generated by Puppet\nLoadPlugin swap\n\n\n ReportByDevice false\n\n", + :content => "# Generated by Puppet\n\n Globals false\n\n\n\n ReportByDevice false\n\n\n", }) end end @@ -42,7 +42,7 @@ should contain_file('swap.load').with({ :ensure => 'present', :path => '/etc/collectd.d/10-swap.conf', - :content => "# Generated by Puppet\nLoadPlugin swap\n\n\n ReportByDevice false\n ReportBytes true\n\n", + :content => "# Generated by Puppet\n\n Globals false\n\n\n\n ReportByDevice false\n ReportBytes true\n\n\n", }) end end diff --git a/templates/loadplugin.conf.erb b/templates/loadplugin.conf.erb new file mode 100644 index 000000000..d9203dc93 --- /dev/null +++ b/templates/loadplugin.conf.erb @@ -0,0 +1,13 @@ +# Generated by Puppet +<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '4.9.4']) >= 0) -%> +> + Globals <%= @globals %> +<% if @interval and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.2']) >= 0) -%> + Interval <%= @interval %> +<% end -%> + +<% else -%> +LoadPlugin <%= @plugin %> +<% end -%> + +<%= @content %>