diff --git a/README.md b/README.md index 5535e2500..68c0872a7 100644 --- a/README.md +++ b/README.md @@ -27,9 +27,10 @@ declaration: ```puppet class { '::collectd': - purge => true, - recurse => true, - purge_config => true, + purge => true, + recurse => true, + purge_config => true, + minimum_version => '5.4', } ``` @@ -38,6 +39,10 @@ the default configurations shipped in collectd.conf and use custom configurations stored in conf.d. From here you can set up additional plugins as shown below. +Specifying the version or minimum_version of collectd as shown above reduces the need for +two puppet runs to coverge. See [Puppet needs two runs to correctly write my conf, why?](#puppet-needs-two-runs-to-correctly-write-my-conf,-why?) below. + + Simple Plugins -------------- @@ -1087,7 +1092,12 @@ See metadata.json for supported platforms ##Known issues -Some plugins will need two runs of Puppet to fully generate the configuration for collectd. See [this issue](https://github.com/puppet-community/puppet-collectd/issues/162). +###Puppet needs two runs to correctly write my conf, why? + +Some plugins will need two runs of Puppet to fully generate the configuration for collectd. See [this issue](https://github.com/pdxcat/puppet-module-collectd/issues/162). +This can be avoided by specifying an explicit version (`$version`) or a minimum version (`$minimum_version`) for the collectd class. e.g. Setting either of these to 1.2.3 will +make this module assume on the first run (when the fact responsible to provide the collectd version is not yet available) that your systems are running collectd 1.2.3 +and generate the configuration accordingly. ##Development diff --git a/manifests/init.pp b/manifests/init.pp index 7f8703fe8..34e573b7c 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -14,12 +14,16 @@ $write_queue_limit_low = undef, $package_name = $collectd::params::package, $version = installed, + $minimum_version = undef, ) inherits collectd::params { $plugin_conf_dir = $collectd::params::plugin_conf_dir validate_bool($purge_config, $fqdnlookup) validate_array($include, $typesdb) + # Version for templates + $_collectd_version = pick($::collectd_version, regsubst($version, '^\d+(?:\.\d+){1.2}', '\0'), $minimum_version) + package { $package_name: ensure => $version, name => $package_name, diff --git a/spec/classes/collectd_plugin_cpu_spec.rb b/spec/classes/collectd_plugin_cpu_spec.rb index 4f22c4845..325aed4ff 100644 --- a/spec/classes/collectd_plugin_cpu_spec.rb +++ b/spec/classes/collectd_plugin_cpu_spec.rb @@ -33,7 +33,7 @@ context 'cpu options should be set with collectd 5.5' do let :facts do {:osfamily => 'RedHat', - :collectd_version => '5.5', + :_collectd_version => '5.5', } end let :params do diff --git a/spec/classes/collectd_plugin_exec_spec.rb b/spec/classes/collectd_plugin_exec_spec.rb index d3cf96638..bb46aa052 100644 --- a/spec/classes/collectd_plugin_exec_spec.rb +++ b/spec/classes/collectd_plugin_exec_spec.rb @@ -9,7 +9,7 @@ :id => 'root', :kernel => 'Linux', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :collectd_version => '5.0' + :_collectd_version => '5.0' } end diff --git a/spec/classes/collectd_plugin_libvirt_spec.rb b/spec/classes/collectd_plugin_libvirt_spec.rb index cf1edef11..f86666f72 100644 --- a/spec/classes/collectd_plugin_libvirt_spec.rb +++ b/spec/classes/collectd_plugin_libvirt_spec.rb @@ -9,10 +9,10 @@ } end - context 'with collectd_version < 5.0' do + context 'with _collectd_version < 5.0' do let :facts do { :osfamily => 'Debian', - :collectd_version => '4.10.1', + :_collectd_version => '4.10.1', } end @@ -22,10 +22,10 @@ end end - context 'with collectd_version >= 5.0' do + context 'with _collectd_version >= 5.0' do let :facts do { :osfamily => 'Debian', - :collectd_version => '5.0.0', + :_collectd_version => '5.0.0', } end diff --git a/spec/classes/collectd_plugin_memory_spec.rb b/spec/classes/collectd_plugin_memory_spec.rb index 5b7d1df19..118d2956d 100644 --- a/spec/classes/collectd_plugin_memory_spec.rb +++ b/spec/classes/collectd_plugin_memory_spec.rb @@ -18,7 +18,7 @@ context ':ensure => present, specific params, collectd version 5.4.2' do let :facts do { :osfamily => 'Redhat', - :collectd_version => '5.4.2' + :_collectd_version => '5.4.2' } end @@ -38,7 +38,7 @@ context ':ensure => present, specific params, collectd version 5.5.0' do let :facts do { :osfamily => 'Redhat', - :collectd_version => '5.5.0' + :_collectd_version => '5.5.0' } end diff --git a/spec/classes/collectd_plugin_openvpn_spec.rb b/spec/classes/collectd_plugin_openvpn_spec.rb index 97e71a8d2..a08fb904f 100644 --- a/spec/classes/collectd_plugin_openvpn_spec.rb +++ b/spec/classes/collectd_plugin_openvpn_spec.rb @@ -8,7 +8,7 @@ context ':ensure => present, default params' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4', + :_collectd_version => '5.4', } end @@ -24,7 +24,7 @@ context ':statusfile param is an array' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4', + :_collectd_version => '5.4', } end @@ -47,7 +47,7 @@ context ':statusfile is a string but not an absolute path' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4', + :_collectd_version => '5.4', } end @@ -64,7 +64,7 @@ context ':statusfile param is not a string or array' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4', + :_collectd_version => '5.4', } end @@ -80,7 +80,7 @@ context ':improvednamingschema is not a bool' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4'} + :_collectd_version => '5.4'} end let :params do {:improvednamingschema => "true"} @@ -94,7 +94,7 @@ context ':collectcompression is not a bool' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4'} + :_collectd_version => '5.4'} end let :params do {:collectcompression => "true"} @@ -108,7 +108,7 @@ context ':collectindividualusers is not a bool' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4'} + :_collectd_version => '5.4'} end let :params do {:collectindividualusers => "true"} @@ -122,7 +122,7 @@ context ':collectusercount is not a bool' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4'} + :_collectd_version => '5.4'} end let :params do {:collectusercount => "true"} @@ -136,7 +136,7 @@ context ':interval is not default and is an integer' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4'} + :_collectd_version => '5.4'} end let :params do {:interval => 15} @@ -154,7 +154,7 @@ context ':ensure => absent' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4', + :_collectd_version => '5.4', } end let :params do diff --git a/spec/classes/collectd_plugin_processes_spec.rb b/spec/classes/collectd_plugin_processes_spec.rb index 31fc8ecbf..0e058e129 100644 --- a/spec/classes/collectd_plugin_processes_spec.rb +++ b/spec/classes/collectd_plugin_processes_spec.rb @@ -8,7 +8,7 @@ :id => 'root', :kernel => 'Linux', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :collectd_version => '5.0' + :_collectd_version => '5.0' } end diff --git a/spec/classes/collectd_plugin_python_spec.rb b/spec/classes/collectd_plugin_python_spec.rb index aa711030e..847e3489e 100644 --- a/spec/classes/collectd_plugin_python_spec.rb +++ b/spec/classes/collectd_plugin_python_spec.rb @@ -9,7 +9,7 @@ :id => 'root', :kernel => 'Linux', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :collectd_version => '5.0' + :_collectd_version => '5.0' } end diff --git a/spec/classes/collectd_plugin_swap_spec.rb b/spec/classes/collectd_plugin_swap_spec.rb index 6451f1f83..cfb0d7878 100644 --- a/spec/classes/collectd_plugin_swap_spec.rb +++ b/spec/classes/collectd_plugin_swap_spec.rb @@ -18,7 +18,7 @@ context ':ensure => present, specific params, collectd version 5.0' do let :facts do { :osfamily => 'Redhat', - :collectd_version => '5.0' + :_collectd_version => '5.0' } end @@ -34,7 +34,7 @@ context ':ensure => present, specific params, collectd version 5.2.0' do let :facts do { :osfamily => 'Redhat', - :collectd_version => '5.2.0' + :_collectd_version => '5.2.0' } end @@ -50,7 +50,7 @@ context ':ensure => present, specific params, collectd version 5.5.0' do let :facts do { :osfamily => 'Redhat', - :collectd_version => '5.5.0' + :_collectd_version => '5.5.0' } end diff --git a/spec/classes/collectd_plugin_varnish_spec.rb b/spec/classes/collectd_plugin_varnish_spec.rb index a49ab4379..de5c053c7 100644 --- a/spec/classes/collectd_plugin_varnish_spec.rb +++ b/spec/classes/collectd_plugin_varnish_spec.rb @@ -4,7 +4,7 @@ context 'When the version is not 5.4' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.3', + :_collectd_version => '5.3', } end let :params do @@ -23,7 +23,7 @@ context 'When the version is nil' do let :facts do { :osfamily => 'RedHat', - :collectd_version => nil, + :_collectd_version => nil, } end let :params do @@ -43,7 +43,7 @@ context 'When the version is 5.4' do let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4', + :_collectd_version => '5.4', } end context 'when there are no params given' do diff --git a/spec/classes/collectd_plugin_write_graphite_spec.rb b/spec/classes/collectd_plugin_write_graphite_spec.rb index f763178c2..ddc9eb3cb 100644 --- a/spec/classes/collectd_plugin_write_graphite_spec.rb +++ b/spec/classes/collectd_plugin_write_graphite_spec.rb @@ -9,7 +9,7 @@ :id => 'root', :kernel => 'Linux', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :collectd_version => '5.0' + :_collectd_version => '5.0' } end @@ -101,7 +101,7 @@ :id => 'root', :kernel => 'Linux', :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - :collectd_version => '5.3' + :_collectd_version => '5.3' } end let :params do diff --git a/spec/defines/collectd_plugin_network_listener_spec.rb b/spec/defines/collectd_plugin_network_listener_spec.rb index 9270b025a..6ddd641fc 100644 --- a/spec/defines/collectd_plugin_network_listener_spec.rb +++ b/spec/defines/collectd_plugin_network_listener_spec.rb @@ -6,7 +6,7 @@ let :facts do { :osfamily => 'Redhat', - :collectd_version => '4.6' + :_collectd_version => '4.6' } end let (:title) {'mylistener'} @@ -29,7 +29,7 @@ let :facts do { :osfamily => 'Redhat', - :collectd_version => '5.1.0' + :_collectd_version => '5.1.0' } end let (:title) {'mylistener'} diff --git a/spec/defines/collectd_plugin_network_server_spec.rb b/spec/defines/collectd_plugin_network_server_spec.rb index 5c39654ca..395079087 100644 --- a/spec/defines/collectd_plugin_network_server_spec.rb +++ b/spec/defines/collectd_plugin_network_server_spec.rb @@ -6,7 +6,7 @@ let :facts do { :osfamily => 'Redhat', - :collectd_version => '5.1.0' + :_collectd_version => '5.1.0' } end let (:title) {'node1'} diff --git a/spec/defines/collectd_plugin_spec.rb b/spec/defines/collectd_plugin_spec.rb index b2e59c0a5..0bf10d88f 100644 --- a/spec/defines/collectd_plugin_spec.rb +++ b/spec/defines/collectd_plugin_spec.rb @@ -6,7 +6,7 @@ let(:title) { 'test' } let :facts do { - :collectd_version => '5.3', + :_collectd_version => '5.3', :osfamily => 'Debian', } end @@ -21,7 +21,7 @@ let(:title) { 'test' } let :facts do { - :collectd_version => '4.9.3', + :_collectd_version => '4.9.3', :osfamily => 'Debian', } end diff --git a/spec/defines/collectd_plugin_write_graphite_spec.rb b/spec/defines/collectd_plugin_write_graphite_spec.rb index 882d37064..3ec8f5819 100644 --- a/spec/defines/collectd_plugin_write_graphite_spec.rb +++ b/spec/defines/collectd_plugin_write_graphite_spec.rb @@ -14,7 +14,7 @@ let(:title) { 'graphite_udp' } let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.3', + :_collectd_version => '5.3', :concat_basedir => tmpfilename('collectd-graphite'), } end @@ -34,7 +34,7 @@ let(:title) { 'wg' } let :facts do { :osfamily => 'RedHat', - :collectd_version => '5.4', + :_collectd_version => '5.4', :concat_basedir => tmpfilename('collectd-graphite'), } end diff --git a/templates/loadplugin.conf.erb b/templates/loadplugin.conf.erb index d9203dc93..1758b3325 100644 --- a/templates/loadplugin.conf.erb +++ b/templates/loadplugin.conf.erb @@ -1,8 +1,8 @@ # Generated by Puppet -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '4.9.4']) >= 0) -%> +<% 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) -%> +<% if @interval and @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.2']) >= 0) -%> Interval <%= @interval %> <% end -%> diff --git a/templates/mysql-database.conf.erb b/templates/mysql-database.conf.erb index 04c2c23c2..26faa05af 100644 --- a/templates/mysql-database.conf.erb +++ b/templates/mysql-database.conf.erb @@ -5,7 +5,7 @@ Host "<%= @host %>" User "<%= @username %>" Password "<%= @password %>" -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.0']) >= 0) -%> +<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.0']) >= 0) -%> Port "<%= @port %>" <% else -%> Port <%= @port %> diff --git a/templates/plugin/cpu.conf.erb b/templates/plugin/cpu.conf.erb index 68c3b5f53..5b9285cee 100644 --- a/templates/plugin/cpu.conf.erb +++ b/templates/plugin/cpu.conf.erb @@ -1,4 +1,4 @@ -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.5']) >= 0) -%> +<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.5']) >= 0) -%> ReportByState = <%= @reportbystate %> ReportByCpu = <%= @reportbycpu %> diff --git a/templates/plugin/curl-page.conf.erb b/templates/plugin/curl-page.conf.erb index 3caf4b011..527a0718c 100644 --- a/templates/plugin/curl-page.conf.erb +++ b/templates/plugin/curl-page.conf.erb @@ -16,10 +16,10 @@ <% if @cacert -%> CACert "<%= @cacert %>" <% end -%> -<% if @header and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%> +<% if @header and @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.3']) >= 0) -%> Header "<%= @header %>" <% end -%> -<% if @post and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%> +<% if @post and @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.3']) >= 0) -%> Post "<%= @post %>" <% end -%> <% unless @measureresponsetime.nil? -%> diff --git a/templates/plugin/df.conf.erb b/templates/plugin/df.conf.erb index 8f1ef1492..f0f1d869b 100644 --- a/templates/plugin/df.conf.erb +++ b/templates/plugin/df.conf.erb @@ -9,7 +9,7 @@ ReportByDevice <%= @reportbydevice %> ReportInodes <%= @reportinodes %> ReportReserved <%= @reportreserved %> -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.4']) >= 0) -%> +<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.4']) >= 0) -%> ValuesAbsolute <%= @valuesabsolute %> ValuesPercentage <%= @valuespercentage %> <% end -%> diff --git a/templates/plugin/libvirt.conf.erb b/templates/plugin/libvirt.conf.erb index fa6fa6569..d8d23eddf 100644 --- a/templates/plugin/libvirt.conf.erb +++ b/templates/plugin/libvirt.conf.erb @@ -19,10 +19,10 @@ HostnameFormat "<%= @hostname_format %>" <% end -%> <% if @interface_format != nil - if @collectd_version and (scope.function_versioncmp([@collectd_version, '5']) >= 0) -%> + if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5']) >= 0) -%> InterfaceFormat "<%= @interface_format %>" <% else - scope.function_warning(['ignoring interface_format parameter because collectd_version is < 5 or undefined']) + scope.function_warning(['ignoring interface_format parameter because _collectd_version is < 5 or undefined']) end end -%> diff --git a/templates/plugin/memory.conf.erb b/templates/plugin/memory.conf.erb index 899e4e0c8..11644b753 100644 --- a/templates/plugin/memory.conf.erb +++ b/templates/plugin/memory.conf.erb @@ -1,4 +1,4 @@ -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.5']) >= 0) -%> +<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.5']) >= 0) -%> ValuesAbsolute = <%= @valuesabsolute %> ValuesPercentage = <%= @valuespercentage %> diff --git a/templates/plugin/network/listener.conf.erb b/templates/plugin/network/listener.conf.erb index e1d310ed4..b217f968f 100644 --- a/templates/plugin/network/listener.conf.erb +++ b/templates/plugin/network/listener.conf.erb @@ -1,5 +1,5 @@ -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '4.7']) >= 0) -%> +<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '4.7']) >= 0) -%> " "<%= @port %>"> <% if @securitylevel -%> SecurityLevel "<%= @securitylevel %>" diff --git a/templates/plugin/network/server.conf.erb b/templates/plugin/network/server.conf.erb index 417bf0674..382a02e14 100644 --- a/templates/plugin/network/server.conf.erb +++ b/templates/plugin/network/server.conf.erb @@ -1,5 +1,5 @@ -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '4.7']) >= 0) -%> +<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '4.7']) >= 0) -%> " "<%= @port %>"> <% if @securitylevel -%> SecurityLevel "<%= @securitylevel %>" diff --git a/templates/plugin/ntpd.conf.erb b/templates/plugin/ntpd.conf.erb index 881534671..2bb71d7ab 100644 --- a/templates/plugin/ntpd.conf.erb +++ b/templates/plugin/ntpd.conf.erb @@ -2,7 +2,7 @@ Host "<%= @host %>" Port "<%= @port %>" ReverseLookups <%= @reverselookups %> -<% if @collectd_version and scope.function_versioncmp([@collectd_version, '5.2']) > 0 -%> +<% if @_collectd_version and scope.function_versioncmp([@_collectd_version, '5.2']) > 0 -%> IncludeUnitID <%= @includeunitid %> <% end -%> diff --git a/templates/plugin/swap.conf.erb b/templates/plugin/swap.conf.erb index ff1047535..783b61781 100644 --- a/templates/plugin/swap.conf.erb +++ b/templates/plugin/swap.conf.erb @@ -1,9 +1,9 @@ ReportByDevice <%= @reportbydevice %> -<% if @collectd_version and scope.function_versioncmp([@collectd_version, '5.2']) > 0 -%> +<% if @_collectd_version and scope.function_versioncmp([@_collectd_version, '5.2']) > 0 -%> ReportBytes <%= @reportbytes %> <% end -%> -<% if @collectd_version and scope.function_versioncmp([@collectd_version, '5.5']) > 0 -%> +<% if @_collectd_version and scope.function_versioncmp([@_collectd_version, '5.5']) > 0 -%> ValuesAbsolute = <%= @valuesabsolute %> ValuesPercentage = <%= @valuespercentage %> <% end -%> diff --git a/templates/plugin/unixsock.conf.erb b/templates/plugin/unixsock.conf.erb index 844d7e727..14d8e6c0d 100644 --- a/templates/plugin/unixsock.conf.erb +++ b/templates/plugin/unixsock.conf.erb @@ -2,7 +2,7 @@ SocketFile "<%= @socketfile %>" SocketGroup "<%= @socketgroup %>" SocketPerms "<%= @socketperms %>" -<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '5']) >= 0) -%> +<% if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5']) >= 0) -%> DeleteSocket "<%= @deletesocket %>" <% end -%> diff --git a/templates/plugin/write_graphite/carbon.conf.erb b/templates/plugin/write_graphite/carbon.conf.erb index 5094a1135..9946b519b 100644 --- a/templates/plugin/write_graphite/carbon.conf.erb +++ b/templates/plugin/write_graphite/carbon.conf.erb @@ -1,4 +1,4 @@ -<%- if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%> +<%- if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.3']) >= 0) -%> "> <%- else -%> @@ -13,11 +13,11 @@ StoreRates <%= @storerates %> AlwaysAppendDS <%= @alwaysappendds %> SeparateInstances <%= @separateinstances %> -<%- if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.4']) >= 0) -%> +<%- if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.4']) >= 0) -%> LogSendErrors <%= @logsenderrors %> Protocol "<%= @protocol %>" <%- end -%> -<%- if @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%> +<%- if @_collectd_version and (scope.function_versioncmp([@_collectd_version, '5.3']) >= 0) -%> <%- else -%>