From fa4b6be94e2372bb80d0a177ef94b831b7e3009c Mon Sep 17 00:00:00 2001 From: Lukas Bezdicka Date: Mon, 11 May 2015 13:36:22 +0200 Subject: [PATCH] Update module-collectd to 6a9f9492af6a3a59b74f043ce6bb8227909224b2 6a9f9492af6a3a59b74f043ce6bb8227909224b2 Merge pull request #255 from deric/python 7e58baa1e4a01beef1aa3c3d9f46e834107319e0 Implement support for mupltiple Python modules 6343c5bd7975890878ed9716a145ec891b7c76aa Merge pull request #260 from dene14/master 9916bbed88d746a5cdc64e61d5d71d0f74b64300 Added absent timers for statsd module. e01c6f21241e282d5f2008c794109af9af01c45f Merge pull request #259 from deric/meta 6461edbc543c9067ee19b01ea7d89a1e72490c9d fix license name to follow http://spdx.org/licenses/ conventions 5ffa441be68241e6c3d1bec0bf3d02d235e2f95a added metadata-json-lint gem 9dba7e5f548af6eb7449339f71932ae8278a2884 Merge pull request #258 from txaj/testing_on_3_7 e8db40330753daed24ba1108d1bdf915973a3622 Merge pull request #254 from pdxcat/release_3_3_0 e2fe68f1ce84bc9bc053df16dab25c2a055ed2bd Check against puppet 3.7.5 c45093add06883781c2c68d93f91544b670330fc Merge pull request #256 from txaj/release_3_3_0_fix 599716b1583c9d721356af08fae062e4c05ffdbc Bump concat fixture version fe119af271897d2e7d5681aa13f84a2db337d9a9 Fix tests 5ab404d680a29f5b7175e65ea6a393f501a74543 Pin concat to 1.2.0 in .fixtures.yml f9690497d6576c4de21441243b9f992033dd8135 Release 3.3.0 --- Puppetfile | 2 +- module-collectd/.fixtures.yml | 7 +- module-collectd/.travis.yml | 4 + module-collectd/CHANGELOG.md | 17 ++ module-collectd/Gemfile | 1 + module-collectd/Gemfile.lock | 192 ++++++++----- module-collectd/README.md | 59 +++- module-collectd/manifests/params.pp | 7 + module-collectd/manifests/plugin/python.pp | 104 ++++--- .../manifests/plugin/python/module.pp | 39 +++ module-collectd/manifests/plugin/statsd.pp | 4 + module-collectd/metadata.json | 4 +- .../spec/classes/collectd_init_spec.rb | 2 +- .../spec/classes/collectd_plugin_disk_spec.rb | 2 +- .../classes/collectd_plugin_filecount_spec.rb | 2 +- .../classes/collectd_plugin_interface_spec.rb | 2 +- .../classes/collectd_plugin_iptables_spec.rb | 2 +- .../spec/classes/collectd_plugin_irq_spec.rb | 2 +- .../classes/collectd_plugin_python_spec.rb | 265 ++++++++++++++++++ .../classes/collectd_plugin_tcpconns_spec.rb | 4 +- .../classes/collectd_plugin_unixsock_spec.rb | 2 +- .../collectd_plugin_python_module_spec.rb | 99 +++++++ .../defines/collectd_plugin_python_spec.rb | 67 ----- .../templates/plugin/python/header.conf.erb | 10 + .../templates/plugin/python/module.conf.erb | 7 + .../templates/plugin/statsd.conf.erb | 12 + module-collectd/templates/python.conf.erb | 16 -- 27 files changed, 721 insertions(+), 213 deletions(-) create mode 100644 module-collectd/manifests/plugin/python/module.pp create mode 100644 module-collectd/spec/classes/collectd_plugin_python_spec.rb create mode 100644 module-collectd/spec/defines/collectd_plugin_python_module_spec.rb delete mode 100644 module-collectd/spec/defines/collectd_plugin_python_spec.rb create mode 100644 module-collectd/templates/plugin/python/header.conf.erb create mode 100644 module-collectd/templates/plugin/python/module.conf.erb delete mode 100644 module-collectd/templates/python.conf.erb diff --git a/Puppetfile b/Puppetfile index cc75037df..18a2a652b 100644 --- a/Puppetfile +++ b/Puppetfile @@ -95,7 +95,7 @@ mod 'memcached', :git => 'https://github.com/saz/puppet-memcached.git' mod 'module-collectd', - :commit => '1bd511019fe1da9b305b259862aa27516f083be6', + :commit => '6a9f9492af6a3a59b74f043ce6bb8227909224b2', :git => 'https://github.com/pdxcat/puppet-module-collectd.git' mod 'module-data', diff --git a/module-collectd/.fixtures.yml b/module-collectd/.fixtures.yml index c65bd570a..99067d889 100644 --- a/module-collectd/.fixtures.yml +++ b/module-collectd/.fixtures.yml @@ -1,6 +1,9 @@ fixtures: repositories: - 'stdlib': 'git://github.com/puppetlabs/puppetlabs-stdlib' - 'concat': 'git://github.com/puppetlabs/puppetlabs-concat' + stdlib: + repo: 'git://github.com/puppetlabs/puppetlabs-stdlib' + concat: + repo: 'git://github.com/puppetlabs/puppetlabs-concat' + ref: '1.2.1' symlinks: 'collectd': "#{source_dir}" diff --git a/module-collectd/.travis.yml b/module-collectd/.travis.yml index ba1771143..1d6ecb14d 100644 --- a/module-collectd/.travis.yml +++ b/module-collectd/.travis.yml @@ -14,5 +14,9 @@ matrix: env: PUPPET_GEM_VERSION="~> 3.5.0" STRICT_VARIABLES="yes" - rvm: 2.0.0 env: PUPPET_GEM_VERSION="~> 3.5.0" STRICT_VARIABLES="yes" + - rvm: 1.9.3 + env: PUPPET_GEM_VERSION="~> 3.7.5" STRICT_VARIABLES="yes" + - rvm: 2.0.0 + env: PUPPET_GEM_VERSION="~> 3.7.5" STRICT_VARIABLES="yes" notifications: email: false diff --git a/module-collectd/CHANGELOG.md b/module-collectd/CHANGELOG.md index eda6f6fb0..f2414f1bf 100644 --- a/module-collectd/CHANGELOG.md +++ b/module-collectd/CHANGELOG.md @@ -1,3 +1,20 @@ +## 2015-04-22 Release 3.3.0 + +### Backwards-incompatible changes: + +* Drop Ruby 1.8.7 support +* Package collectd-python is no longer available in EPEL + +### Features: + +* Allow disable forwarding in network::server + +### Bugs/Maint: + +* Fix permission on MySQL plugin file +* Only set LogSendErrors option if collectd version >= 5.4. +* CreateFiles/CreateFilesAsync expect boolean values + ## 2015-01-24 Release 3.2.0 ### Backwards-incompatible changes: diff --git a/module-collectd/Gemfile b/module-collectd/Gemfile index abcb4b54e..4d302c2c5 100644 --- a/module-collectd/Gemfile +++ b/module-collectd/Gemfile @@ -8,6 +8,7 @@ group :development, :unit_tests do gem 'simplecov', :require => false gem 'puppet_facts', :require => false gem 'json', :require => false + gem 'metadata-json-lint', :require => false end group :system_tests do diff --git a/module-collectd/Gemfile.lock b/module-collectd/Gemfile.lock index 3e406d83c..1a5005f05 100644 --- a/module-collectd/Gemfile.lock +++ b/module-collectd/Gemfile.lock @@ -1,30 +1,29 @@ GEM remote: https://rubygems.org/ specs: - CFPropertyList (2.2.8) - activesupport (4.2.0) + CFPropertyList (2.3.1) + activesupport (4.2.1) i18n (~> 0.7) json (~> 1.7, >= 1.7.7) minitest (~> 5.1) thread_safe (~> 0.3, >= 0.3.4) tzinfo (~> 1.1) - addressable (2.3.6) - archive-tar-minitar (0.5.2) + addressable (2.3.8) autoparse (0.3.3) addressable (>= 2.3.1) extlib (>= 0.9.15) multi_json (>= 1.0.0) - aws-sdk (1.60.2) - aws-sdk-v1 (= 1.60.2) - aws-sdk-v1 (1.60.2) + aws-sdk (1.64.0) + aws-sdk-v1 (= 1.64.0) + aws-sdk-v1 (1.64.0) json (~> 1.4) nokogiri (>= 1.4.4) - beaker (2.1.0) + beaker (2.10.0) aws-sdk (~> 1.57) docker-api fission (~> 0.4) fog (~> 1.25) - google-api-client (~> 0.7) + google-api-client (~> 0.8) hocon (~> 0.0.4) inifile (~> 2.0) json (~> 1.8) @@ -32,36 +31,40 @@ GEM net-scp (~> 1.2) net-ssh (~> 2.9) rbvmomi (~> 1.8) + rsync (~> 1.0.9) unf (~> 0.1) - beaker-rspec (4.0.0) + beaker-rspec (5.0.2) beaker (~> 2.0) rspec - serverspec (~> 1.0) - specinfra (~> 1.0) + serverspec (~> 2) + specinfra (~> 2) builder (3.2.2) diff-lcs (1.2.5) docile (1.1.5) - docker-api (1.17.0) - archive-tar-minitar + docker-api (1.21.1) excon (>= 0.38.0) json - excon (0.42.1) + excon (0.45.3) extlib (0.9.16) - facter (2.3.0) - CFPropertyList (~> 2.2.6) - faraday (0.9.0) + facter (1.7.6) + faraday (0.9.1) multipart-post (>= 1.2, < 3) fission (0.5.0) CFPropertyList (~> 2.2) - fog (1.26.0) + fog (1.29.0) fog-atmos + fog-aws (~> 0.0) fog-brightbox (~> 0.4) - fog-core (~> 1.27, >= 1.27.1) + fog-core (~> 1.27, >= 1.27.4) fog-ecloud fog-json + fog-local + fog-powerdns (>= 0.1.1) fog-profitbricks fog-radosgw (>= 0.0.2) + fog-riakcs fog-sakuracloud (>= 0.0.4) + fog-serverlove fog-softlayer fog-storm_on_demand fog-terremark @@ -73,102 +76,135 @@ GEM fog-atmos (0.1.0) fog-core fog-xml + fog-aws (0.1.2) + fog-core (~> 1.27) + fog-json (~> 1.0) + fog-xml (~> 0.1) + ipaddress (~> 0.8) fog-brightbox (0.7.1) fog-core (~> 1.22) fog-json inflecto (~> 0.0.2) - fog-core (1.27.2) + fog-core (1.30.0) builder - excon (~> 0.38) + excon (~> 0.45) formatador (~> 0.2) mime-types net-scp (~> 1.1) net-ssh (>= 2.1.3) - fog-ecloud (0.0.2) + fog-ecloud (0.1.1) fog-core fog-xml - fog-json (1.0.0) + fog-json (1.0.1) + fog-core (~> 1.0) multi_json (~> 1.0) - fog-profitbricks (0.0.1) + fog-local (0.2.1) + fog-core (~> 1.27) + fog-powerdns (0.1.1) + fog-core (~> 1.27) + fog-json (~> 1.0) + fog-xml (~> 0.1) + fog-profitbricks (0.0.2) fog-core fog-xml nokogiri - fog-radosgw (0.0.3) + fog-radosgw (0.0.4) fog-core (>= 1.21.0) fog-json fog-xml (>= 0.0.1) - fog-sakuracloud (0.1.1) + fog-riakcs (0.1.0) fog-core fog-json - fog-softlayer (0.3.26) + fog-xml + fog-sakuracloud (1.0.1) + fog-core + fog-json + fog-serverlove (0.1.2) fog-core fog-json - fog-storm_on_demand (0.1.0) + fog-softlayer (0.4.5) fog-core fog-json - fog-terremark (0.0.3) + fog-storm_on_demand (0.1.1) + fog-core + fog-json + fog-terremark (0.1.0) fog-core fog-xml - fog-vmfusion (0.0.1) + fog-vmfusion (0.1.0) fission fog-core - fog-voxel (0.0.2) + fog-voxel (0.1.0) fog-core fog-xml - fog-xml (0.1.1) + fog-xml (0.1.2) fog-core nokogiri (~> 1.5, >= 1.5.11) formatador (0.2.5) - google-api-client (0.8.1.1) + google-api-client (0.8.6) activesupport (>= 3.2) addressable (~> 2.3) autoparse (~> 0.3) extlib (~> 0.9) faraday (~> 0.9) + googleauth (~> 0.3) launchy (~> 2.4) multi_json (~> 1.10) retriable (~> 1.4) signet (~> 0.6) + googleauth (0.4.0) + faraday (~> 0.9) + jwt (~> 1.4) + logging (~> 1.8) + memoist (~> 0.11) + multi_json (= 1.11) + signet (~> 0.6) hiera (1.3.4) json_pure - highline (1.6.21) - hocon (0.0.6) + hocon (0.0.7) i18n (0.7.0) inflecto (0.0.2) inifile (2.0.2) ipaddress (0.8.0) - json (1.8.1) - json_pure (1.8.1) - jwt (1.2.0) + json (1.8.2) + json_pure (1.8.2) + jwt (1.4.1) launchy (2.4.3) addressable (~> 2.3) + little-plugger (1.1.3) + logging (1.8.2) + little-plugger (>= 1.1.3) + multi_json (>= 1.8.4) + memoist (0.12.0) metaclass (0.0.4) + metadata-json-lint (0.0.6) + json + spdx-licenses (~> 1.0) mime-types (2.4.3) - mini_portile (0.6.1) - minitest (5.5.0) + mini_portile (0.6.2) + minitest (5.6.0) mocha (1.1.0) metaclass (~> 0.0.1) - multi_json (1.10.1) + multi_json (1.11.0) multipart-post (2.0.0) net-scp (1.2.1) net-ssh (>= 2.6.5) - net-ssh (2.9.1) - nokogiri (1.6.5) + net-ssh (2.9.2) + nokogiri (1.6.6.2) mini_portile (~> 0.6.0) - puppet (3.7.3) + puppet (3.7.5) facter (> 1.6, < 3) hiera (~> 1.0) json_pure puppet-lint (1.1.0) - puppet-syntax (1.4.0) + puppet-syntax (2.0.0) rake puppet_facts (0.2.1) - puppetlabs_spec_helper (0.8.2) + puppetlabs_spec_helper (0.10.2) mocha puppet-lint puppet-syntax rake - rspec rspec-puppet rake (10.4.2) rbvmomi (1.8.2) @@ -176,44 +212,53 @@ GEM nokogiri (>= 1.4.1) trollop retriable (1.4.1) - rspec (2.99.0) - rspec-core (~> 2.99.0) - rspec-expectations (~> 2.99.0) - rspec-mocks (~> 2.99.0) - rspec-core (2.99.2) - rspec-expectations (2.99.2) - diff-lcs (>= 1.1.3, < 2.0) - rspec-its (1.0.1) - rspec-core (>= 2.99.0.beta1) - rspec-expectations (>= 2.99.0.beta1) - rspec-mocks (2.99.2) - rspec-puppet (1.0.1) + rspec (3.2.0) + rspec-core (~> 3.2.0) + rspec-expectations (~> 3.2.0) + rspec-mocks (~> 3.2.0) + rspec-core (3.2.3) + rspec-support (~> 3.2.0) + rspec-expectations (3.2.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.2.0) + rspec-its (1.2.0) + rspec-core (>= 3.0.0) + rspec-expectations (>= 3.0.0) + rspec-mocks (3.2.1) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.2.0) + rspec-puppet (2.1.0) rspec - serverspec (1.16.0) - highline - net-ssh - rspec (~> 2.99) + rspec-support (3.2.2) + rsync (1.0.9) + serverspec (2.14.1) + multi_json + rspec (~> 3.0) rspec-its - specinfra (~> 1.27) + specinfra (~> 2.25) signet (0.6.0) addressable (~> 2.3) extlib (~> 0.9) faraday (~> 0.9) jwt (~> 1.0) multi_json (~> 1.10) - simplecov (0.9.1) + simplecov (0.10.0) docile (~> 1.1.0) - multi_json (~> 1.0) - simplecov-html (~> 0.8.0) - simplecov-html (0.8.0) - specinfra (1.27.5) - thread_safe (0.3.4) - trollop (2.0) + json (~> 1.8) + simplecov-html (~> 0.10.0) + simplecov-html (0.10.0) + spdx-licenses (1.0.0) + json + specinfra (2.30.0) + net-scp + net-ssh + thread_safe (0.3.5) + trollop (2.1.2) tzinfo (1.2.2) thread_safe (~> 0.1) unf (0.1.4) unf_ext - unf_ext (0.0.6) + unf_ext (0.0.7.1) PLATFORMS ruby @@ -222,6 +267,7 @@ DEPENDENCIES beaker-rspec facter json + metadata-json-lint puppet puppet-lint puppet_facts diff --git a/module-collectd/README.md b/module-collectd/README.md index 03b611fea..fd7d44c75 100644 --- a/module-collectd/README.md +++ b/module-collectd/README.md @@ -198,7 +198,7 @@ collectd::plugin::curl::page { } ``` -You can as well configure this plugin with a parameterized class : +You can as well configure this plugin with a parameterized class : ```puppet class { 'collectd::plugin::curl': @@ -449,7 +449,7 @@ collectd::plugin::network::listener{'hostname': } ``` -You can as well configure this plugin with a parameterized class : +You can as well configure this plugin with a parameterized class : ```puppet class { 'collectd::plugin::network': @@ -527,7 +527,7 @@ This define will load a new perl plugin. #####Parameters: * `module` (String): name of perl module to load (mandatory) -* `enable_debugger` (False or String): whether to load the perl debugger. See *collectd-perl* manpage for more details. +* `enable_debugger` (False or String): whether to load the perl debugger. See *collectd-perl* manpage for more details. * `include_dir` (String or Array): directories to add to *@INC* * `provider` (`"package"`,`"cpan"`,`"file"` or `false`): method to get the plugin code * `source` (String): this parameter is consumed by the provider to infer the source of the plugin code @@ -650,13 +650,54 @@ class { 'collectd::plugin::processes': ####Class: `collectd::plugin::python` + * `modulepaths` is an array of paths where will be Collectd looking for Python modules, Puppet will ensure that each of specified directories exists and it is owned by `root` (and `chmod 0750`). If you don't specify any `modulepaths` a default value for given distribution will be used. + * `modules` a Hash containing configuration of Python modules, where the key is the module name + * `globals` Unlike most other plugins, this one should set `Globals true`. This will cause collectd to export the name of all objects in the Python interpreter for all plugins to see. If you don't do this or your platform does not support it, the embedded interpreter will start anyway but you won't be able to load certain Python modules, e.g. "time". + * `interactive` when `true` it will launch an interactive Python interpreter that reads from and writes to the terminal (default: `false`) + * `logtraces` if a Python script throws an exception it will be logged by collectd with the name of the exception and the message (default: `false`) + + See [collectd-python documentation](https://collectd.org/documentation/manpages/collectd-python.5.shtml) for more details. + +NOTE: Since `v3.4.0` the syntax of this plugin has changed. Make sure to update your existing configuration. Now you can specify multiple Python modules at once: + +```puppet +class { 'collectd::plugin::python': + modulepaths => ['/usr/share/collectd/python'], + modules => { + 'elasticsearch': { + 'script_source' => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', + 'config' => {'Cluster' => 'elasticsearch'}, + }, + 'another-module': { + 'config' => {'Verbose' => 'true'}, + } + } + logtraces => true, + interactive => false +} +``` +When `script_source` provided, a file called `{module}.py` will be created in `$modulepath/$module.py`. + +Or define single module: + ```puppet -collectd::plugin::python { - 'elasticsearch': - modulepath => '/usr/lib/collectd', - module => 'elasticsearch', - script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', - config => {'Cluster' => 'elasticsearch'}, +collectd::plugin::python::module {'zk-collectd': + script_source => 'puppet:///modules/myorg/zk-collectd.py', + config => { + 'Hosts' => "localhost:2181" + } +} +``` + +Each plugin might use different `modulepath`, however make sure that all paths are included in `collectd::plugin::python` variable `modulepaths`. If no `modulepath` is specified, OS default will be used. + +```puppet +collectd::plugin::python::module {'my-module': + modulepath => '/var/share/collectd', + script_source => 'puppet:///modules/myorg/my-module.py', + config => { + 'Key' => "value" + } } ``` diff --git a/module-collectd/manifests/params.pp b/module-collectd/manifests/params.pp index 0960c6ee6..991f857c2 100644 --- a/module-collectd/manifests/params.pp +++ b/module-collectd/manifests/params.pp @@ -11,6 +11,7 @@ $config_file = "${collectd_dir}/collectd.conf" $root_group = 'root' $java_dir = '/usr/share/collectd/java' + $python_dir = '/usr/share/collectd/python' } 'Solaris': { $package = 'CSWcollectd' @@ -21,6 +22,7 @@ $config_file = "${collectd_dir}/collectd.conf" $root_group = 'root' $java_dir = undef + $python_dir = '/opt/csw/share/collectd/python' } 'Redhat': { $package = 'collectd' @@ -31,6 +33,7 @@ $config_file = '/etc/collectd.conf' $root_group = 'root' $java_dir = '/usr/share/collectd/java' + $python_dir = '/usr/share/collectd/python' } 'Suse': { $package = 'collectd' @@ -41,6 +44,7 @@ $config_file = '/etc/collectd.conf' $root_group = 'root' $java_dir = undef + $python_dir = '/usr/share/collectd/python' } 'FreeBSD': { $package = 'collectd5' @@ -51,6 +55,7 @@ $config_file = '/usr/local/etc/collectd.conf' $root_group = 'wheel' $java_dir = undef + $python_dir = '/usr/local/share/collectd/python' } 'Archlinux': { $package = 'collectd' @@ -61,6 +66,7 @@ $config_file = '/etc/collectd.conf' $root_group = 'wheel' $java_dir = undef + $python_dir = '/usr/share/collectd/python' } 'Gentoo': { $package = 'app-admin/collectd' @@ -71,6 +77,7 @@ $config_file = '/etc/collectd.conf' $root_group = 'collectd' $java_dir = undef + $python_dir = '/usr/share/collectd/python' } default: { diff --git a/module-collectd/manifests/plugin/python.pp b/module-collectd/manifests/plugin/python.pp index 2c2c3919f..1b38cfb9c 100644 --- a/module-collectd/manifests/plugin/python.pp +++ b/module-collectd/manifests/plugin/python.pp @@ -1,45 +1,81 @@ # See http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_python -define collectd::plugin::python ( - $modulepath, - $module, - $script_source, - $ensure = present, - $config = {}, - $order = '10', +class collectd::plugin::python ( + $modulepaths = [], + $ensure = present, + $modules = {}, + # Unlike most other plugins, this one should set "Globals true". This will cause collectd + # to export the name of all objects in the Python interpreter for all plugins to see. + $globals = true, + $order = '10', + $interval = undef, + # Python 2 defaults to 'ascii' and Python 3 to 'utf-8' + $encoding = undef, + $interactive = false, + $logtraces = false, ) { include collectd::params - validate_hash($config) + validate_hash($modules) + validate_bool($interactive) + validate_bool($logtraces) + validate_bool($globals) + validate_array($modulepaths) - $conf_dir = $collectd::params::plugin_conf_dir + $module_dirs = empty($modulepaths) ? { + true => [$collectd::params::python_dir], + # use paths provided by the user + false => $modulepaths + } + + collectd::plugin {'python': + ensure => $ensure, + interval => $interval, + order => $order, + globals => $globals, + } + + $ensure_modulepath = $ensure ? { + 'absent' => $ensure, + default => 'directory', + } - # This is deprecated file naming ensuring old style file removed, and should be removed in next major relese - file { "${name}.load-deprecated": - ensure => absent, - path => "${conf_dir}/${name}.conf", + ensure_resource('file', $module_dirs, + { + 'ensure' => $ensure_modulepath, + 'mode' => '0750', + 'owner' => 'root', + 'group' => $collectd::params::root_group, + 'require' => Package[$collectd::params::package] + } + ) + + # should be loaded after global plugin configuration + $python_conf = "${collectd::params::plugin_conf_dir}/python-config.conf" + + concat{ $python_conf: + ensure => $ensure, + mode => '0640', + owner => 'root', + group => $collectd::params::root_group, + notify => Service['collectd'], + ensure_newline => true, } - # End deprecation - - file { - "${name}.load": - ensure => $ensure, - path => "${conf_dir}/${order}-${name}.conf", - owner => 'root', - group => $collectd::params::root_group, - mode => '0640', - content => template('collectd/python.conf.erb'), - notify => Service['collectd'], + + concat::fragment{'collectd_plugin_python_conf_header': + order => '00', + content => template('collectd/plugin/python/header.conf.erb'), + target => $python_conf, + } + + concat::fragment{'collectd_plugin_python_conf_footer': + order => '99', + content => '', + target => $python_conf, } - file { - "${name}.script": - ensure => $ensure, - path => "${modulepath}/${module}.py", - owner => 'root', - group => $collectd::params::root_group, - mode => '0640', - source => $script_source, - require => File["${name}.load"], - notify => Service['collectd'], + $defaults = { + 'ensure' => $ensure, + 'modulepath' => $module_dirs[0], } + create_resources(collectd::plugin::python::module, $modules, $defaults) } diff --git a/module-collectd/manifests/plugin/python/module.pp b/module-collectd/manifests/plugin/python/module.pp new file mode 100644 index 000000000..94a92bc2f --- /dev/null +++ b/module-collectd/manifests/plugin/python/module.pp @@ -0,0 +1,39 @@ +# Single module definition +define collectd::plugin::python::module ( + $config, + $modulepath = undef, + $script_source = undef, + $module = $title, + $ensure = 'present', +){ + include collectd::params + include collectd::plugin::python + + validate_hash($config) + + $module_dir = $modulepath ? { + undef => $collectd::params::python_dir, + default => $modulepath + } + validate_absolute_path($module_dir) + + if $script_source { + file { "${module}.script": + ensure => $ensure, + path => "${module_dir}/${module}.py", + owner => 'root', + group => $collectd::params::root_group, + mode => '0640', + source => $script_source, + require => File[$module_dir], + notify => Service['collectd'], + } + } + + concat::fragment{"collectd_plugin_python_conf_${module}": + ensure => $ensure, + order => '50', # somewhere between header and footer + target => $collectd::plugin::python::python_conf, + content => template('collectd/plugin/python/module.conf.erb'), + } +} diff --git a/module-collectd/manifests/plugin/statsd.pp b/module-collectd/manifests/plugin/statsd.pp index 931f52867..e54c5bab7 100644 --- a/module-collectd/manifests/plugin/statsd.pp +++ b/module-collectd/manifests/plugin/statsd.pp @@ -9,6 +9,10 @@ $deletesets = undef, $interval = undef, $timerpercentile = undef, + $timerlower = undef, + $timerupper = undef, + $timersum = undef, + $timercount = undef, ) { collectd::plugin {'statsd': diff --git a/module-collectd/metadata.json b/module-collectd/metadata.json index ad685f727..3c6355fc8 100644 --- a/module-collectd/metadata.json +++ b/module-collectd/metadata.json @@ -71,10 +71,10 @@ } ], "name": "pdxcat-collectd", - "version": "3.2.0", + "version": "3.3.0", "source": "https://github.com/pdxcat/puppet-module-collectd", "author": "Computer Action Team", - "license": "Apache Version 2.0", + "license": "Apache-2.0", "summary": "Puppet module for Collectd", "project_page": "https://github.com/pdxcat/puppet-module-collectd", "dependencies": [ diff --git a/module-collectd/spec/classes/collectd_init_spec.rb b/module-collectd/spec/classes/collectd_init_spec.rb index d266f0252..a3e98291d 100644 --- a/module-collectd/spec/classes/collectd_init_spec.rb +++ b/module-collectd/spec/classes/collectd_init_spec.rb @@ -30,7 +30,7 @@ end it 'should fail' do - expect { subject }.to raise_error(/foo is not supported/) + should compile.and_raise_error(/foo is not supported/) end end diff --git a/module-collectd/spec/classes/collectd_plugin_disk_spec.rb b/module-collectd/spec/classes/collectd_plugin_disk_spec.rb index 876522c64..d9d2089bb 100644 --- a/module-collectd/spec/classes/collectd_plugin_disk_spec.rb +++ b/module-collectd/spec/classes/collectd_plugin_disk_spec.rb @@ -35,7 +35,7 @@ {:disks => 'sda'} end it 'Will raise an error about :disks being a String' do - expect {should}.to raise_error(Puppet::Error,/String/) + should compile.and_raise_error(/String/) end end end diff --git a/module-collectd/spec/classes/collectd_plugin_filecount_spec.rb b/module-collectd/spec/classes/collectd_plugin_filecount_spec.rb index cc8ffe623..e60d27ea7 100644 --- a/module-collectd/spec/classes/collectd_plugin_filecount_spec.rb +++ b/module-collectd/spec/classes/collectd_plugin_filecount_spec.rb @@ -57,7 +57,7 @@ {:directories => '/var/spool/postfix/active'} end it 'Will raise an error about :directories being a String' do - expect {should}.to raise_error(Puppet::Error,/String/) + should compile.and_raise_error(/String/) end end end diff --git a/module-collectd/spec/classes/collectd_plugin_interface_spec.rb b/module-collectd/spec/classes/collectd_plugin_interface_spec.rb index 5cda3cd41..47b4533d5 100644 --- a/module-collectd/spec/classes/collectd_plugin_interface_spec.rb +++ b/module-collectd/spec/classes/collectd_plugin_interface_spec.rb @@ -35,7 +35,7 @@ {:interfaces => 'eth0'} end it 'Will raise an error about :interfaces being a String' do - expect {should}.to raise_error(Puppet::Error,/String/) + should compile.and_raise_error(/String/) end end end diff --git a/module-collectd/spec/classes/collectd_plugin_iptables_spec.rb b/module-collectd/spec/classes/collectd_plugin_iptables_spec.rb index a04b71a33..c6f854f1d 100644 --- a/module-collectd/spec/classes/collectd_plugin_iptables_spec.rb +++ b/module-collectd/spec/classes/collectd_plugin_iptables_spec.rb @@ -35,7 +35,7 @@ {:chains => ['nat','In_SSH']} end it 'Will raise an error about :chains being an Array' do - expect {should}.to raise_error(Puppet::Error,/Array/) + should compile.and_raise_error(/Array/) end end end diff --git a/module-collectd/spec/classes/collectd_plugin_irq_spec.rb b/module-collectd/spec/classes/collectd_plugin_irq_spec.rb index 2efb607f1..1f3f7f517 100644 --- a/module-collectd/spec/classes/collectd_plugin_irq_spec.rb +++ b/module-collectd/spec/classes/collectd_plugin_irq_spec.rb @@ -35,7 +35,7 @@ {:irqs => '90,91,92'} end it 'Will raise an error about :irqs being a String' do - expect {should}.to raise_error(Puppet::Error,/String/) + should compile.and_raise_error(/String/) end end end diff --git a/module-collectd/spec/classes/collectd_plugin_python_spec.rb b/module-collectd/spec/classes/collectd_plugin_python_spec.rb new file mode 100644 index 000000000..aa711030e --- /dev/null +++ b/module-collectd/spec/classes/collectd_plugin_python_spec.rb @@ -0,0 +1,265 @@ +require 'spec_helper' + +describe 'collectd::plugin::python', :type => :class do + + let :facts do + { + :osfamily => 'Debian', + :concat_basedir => tmpfilename('collectd-python'), + :id => 'root', + :kernel => 'Linux', + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + :collectd_version => '5.0' + } + end + + context ':ensure => present' do + context ':ensure => present and default parameters' do + + it 'ensures that $modulepaths exits' do + should contain_file('/usr/share/collectd/python').with({ + :ensure => 'directory' + }) + end + + it 'Will create /etc/collectd/conf.d/10-python.conf to load the plugin' do + should contain_file('python.load').with({ + :ensure => 'present', + :path => '/etc/collectd/conf.d/10-python.conf', + :content => /LoadPlugin python/, + }) + end + + it 'Will create /etc/collectd.d/conf.d/python-config.conf' do + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => //, + :target => '/etc/collectd/conf.d/python-config.conf', + :order => '00' + }) + end + + it 'set default Python module path' do + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /ModulePath "\/usr\/share\/collectd\/python"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'Will create /etc/collectd.d/conf.d/python-config.conf' do + should contain_concat__fragment('collectd_plugin_python_conf_footer').with({ + :content => /<\/Plugin>/, + :target => '/etc/collectd/conf.d/python-config.conf', + :order => '99' + }) + end + end + + context ':ensure => present and multiple $modulepaths' do + let :params do + { + :modulepaths => ['/tmp/', '/data/'] + } + end + it 'will ensure the two directories are here' do + should contain_file('/tmp/') + should contain_file('/data/') + end + it 'will set two modulepath in the module conf' do + should contain_concat__fragment('collectd_plugin_python_conf_header').with( + { + :content => /ModulePath "\/tmp\/"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + should contain_concat__fragment('collectd_plugin_python_conf_header').with( + { + :content => /ModulePath "\/data\/"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + end + + context ':ensure => present and configure elasticsearch module' do + let :params do + { + :modules => { + 'elasticsearch' => { + 'script_source' => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', + 'config' => {'Cluster' => 'ES-clust'} + }, + 'foo' => { + 'config' => {'Verbose' => true, 'Bar' => '"bar"' } + } + } + } + end + + it 'imports elasticsearch module' do + should contain_concat__fragment('collectd_plugin_python_conf_elasticsearch').with({ + :content => /Import "elasticsearch"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'includes elasticsearch module configuration' do + should contain_concat__fragment('collectd_plugin_python_conf_elasticsearch').with({ + :content => //, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'includes elasticsearch Cluster name' do + should contain_concat__fragment('collectd_plugin_python_conf_elasticsearch').with({ + :content => /Cluster ES-clust/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'created collectd plugin file' do + should contain_file('elasticsearch.script').with({ + :ensure => 'present', + :path => '/usr/share/collectd/python/elasticsearch.py', + }) + end + + # test foo module + it 'imports foo module' do + should contain_concat__fragment('collectd_plugin_python_conf_foo').with({ + :content => /Import "foo"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'includes foo module configuration' do + should contain_concat__fragment('collectd_plugin_python_conf_foo').with({ + :content => //, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + should contain_concat__fragment('collectd_plugin_python_conf_foo').with({ + :content => /Verbose true/, + }) + should contain_concat__fragment('collectd_plugin_python_conf_foo').with({ + :content => /Bar "bar"/, + }) + end + end + + context 'allow changing module path' do + let :params do + { + :modulepaths => ['/var/lib/collectd/python', '/usr/collectd'], + :modules => { + 'elasticsearch' => { + 'script_source' => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', + 'config' => {'Cluster' => 'ES-clust'}, + 'modulepath' => '/var/lib/collectd/python', + } + } + } + end + + it 'ensures that each directory on $modulepaths exits' do + should contain_file('/var/lib/collectd/python').with({ + :ensure => 'directory' + }) + + should contain_file('/usr/collectd').with({ + :ensure => 'directory' + }) + end + + it 'set default Python module paths' do + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /ModulePath "\/var\/lib\/collectd\/python"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /ModulePath "\/usr\/collectd"/, + }) + + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /ModulePath "\/var\/lib\/collectd\/python"/, + }) + end + + it 'created collectd plugin file' do + should contain_file('elasticsearch.script').with({ + :ensure => 'present', + :path => '/var/lib/collectd/python/elasticsearch.py', + }) + end + end + end + + context 'change globals parameter' do + let :params do + { + :globals => false + } + end + + it 'will change $globals settings' do + should contain_file('python.load').with({ + :ensure => 'present', + :path => '/etc/collectd/conf.d/10-python.conf', + :content => /Globals false/, + }) + end + end + + context 'allow passing shared options for all modules' do + let :params do + { + :logtraces => true, + :interactive => true, + :encoding => 'utf-8', + } + end + + it 'sets options' do + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /LogTraces true/, + }) + + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /Interactive true/, + }) + + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /Encoding utf-8/, + }) + end + end + + context ':ensure => absent' do + let (:title) {'elasticsearch'} + let :params do + { + :ensure => 'absent', + :modules => { + 'elasticsearch' => { + 'script_source' => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', + 'config' => {'Cluster' => 'ES-clust'} + } + } + } + end + + it 'will remove /etc/collectd/conf.d/10-python.conf' do + should contain_file('python.load').with({ + :ensure => 'absent', + :path => '/etc/collectd/conf.d/10-python.conf', + :content => /LoadPlugin python/, + }) + end + + it 'won\'t create /etc/collectd.d/conf.d/python-config.conf (no modules defined)' do + should_not contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :ensure => 'absent', + :target => '/etc/collectd/conf.d/python-config.conf', + :order => '00' + }) + end + end + +end diff --git a/module-collectd/spec/classes/collectd_plugin_tcpconns_spec.rb b/module-collectd/spec/classes/collectd_plugin_tcpconns_spec.rb index 7b7b4e85d..db38c3052 100644 --- a/module-collectd/spec/classes/collectd_plugin_tcpconns_spec.rb +++ b/module-collectd/spec/classes/collectd_plugin_tcpconns_spec.rb @@ -48,7 +48,7 @@ {:localports => '22'} end it 'Will raise an error about :localports being a String' do - expect {should}.to raise_error(Puppet::Error,/String/) + should compile.and_raise_error(/String/) end end @@ -57,7 +57,7 @@ {:remoteports => '22'} end it 'Will raise an error about :remoteports being a String' do - expect {should}.to raise_error(Puppet::Error,/String/) + should compile.and_raise_error(/String/) end end end diff --git a/module-collectd/spec/classes/collectd_plugin_unixsock_spec.rb b/module-collectd/spec/classes/collectd_plugin_unixsock_spec.rb index 9fab9a231..8b5ff7fa5 100644 --- a/module-collectd/spec/classes/collectd_plugin_unixsock_spec.rb +++ b/module-collectd/spec/classes/collectd_plugin_unixsock_spec.rb @@ -32,7 +32,7 @@ {:socketfile => 'var/run/socket'} end it 'Will raise an error about :socketfile' do - expect {should}.to raise_error(Puppet::Error,/absolute path/) + should compile.and_raise_error(/absolute path/) end end end diff --git a/module-collectd/spec/defines/collectd_plugin_python_module_spec.rb b/module-collectd/spec/defines/collectd_plugin_python_module_spec.rb new file mode 100644 index 000000000..48deac94a --- /dev/null +++ b/module-collectd/spec/defines/collectd_plugin_python_module_spec.rb @@ -0,0 +1,99 @@ +require 'spec_helper' + +describe 'collectd::plugin::python::module', :type => :define do + let :facts do + { + :osfamily => 'Debian', + :id => 'root', + :concat_basedir => tmpfilename('collectd-python'), + :path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + } + end + + context 'spam module' do + let(:title) { 'spam' } + let :params do + { + :config => { 'spam' => '"wonderful" "lovely"' }, + :modulepath => '/var/lib/collectd/python', + } + end + + it 'imports spam module' do + should contain_concat__fragment('collectd_plugin_python_conf_spam').with({ + :content => /Import "spam"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'includes spam module configuration' do + should contain_concat__fragment('collectd_plugin_python_conf_spam').with({ + :content => //, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + + should contain_concat__fragment('collectd_plugin_python_conf_spam').with({ + :content => /spam "wonderful" "lovely"/, + }) + end + + it 'Will create /etc/collectd.d/conf.d/python-config.conf' do + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => //, + :target => '/etc/collectd/conf.d/python-config.conf', + :order => '00' + }) + end + + it 'set default Python module path' do + should contain_concat__fragment('collectd_plugin_python_conf_header').with({ + :content => /ModulePath "\/usr\/share\/collectd\/python"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'Will create /etc/collectd.d/conf.d/python-config.conf' do + should contain_concat__fragment('collectd_plugin_python_conf_footer').with({ + :content => /<\/Plugin>/, + :target => '/etc/collectd/conf.d/python-config.conf', + :order => '99' + }) + end + end + + context 'module without modulepath' do + let(:title) { 'foo' } + let :params do + { + :script_source => 'puppet:///modules/myorg/foo.py', + :config => { 'bar' => 'baz' }, + } + end + + it 'imports foo module' do + should contain_concat__fragment('collectd_plugin_python_conf_foo').with({ + :content => /Import "foo"/, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + end + + it 'includes foo module configuration' do + should contain_concat__fragment('collectd_plugin_python_conf_foo').with({ + :content => //, + :target => '/etc/collectd/conf.d/python-config.conf', + }) + + should contain_concat__fragment('collectd_plugin_python_conf_foo').with({ + :content => /bar baz/, + }) + end + + it 'created collectd plugin file on Debian default path' do + should contain_file('foo.script').with({ + :ensure => 'present', + :path => '/usr/share/collectd/python/foo.py', + }) + end + + end +end diff --git a/module-collectd/spec/defines/collectd_plugin_python_spec.rb b/module-collectd/spec/defines/collectd_plugin_python_spec.rb deleted file mode 100644 index 85951caff..000000000 --- a/module-collectd/spec/defines/collectd_plugin_python_spec.rb +++ /dev/null @@ -1,67 +0,0 @@ -require 'spec_helper' - -describe 'collectd::plugin::python', :type => :define do - - context ':ensure => present' do - let :facts do - { - :osfamily => 'Debian' - } - end - let (:title) {'elasticsearch'} - let :params do - { - :modulepath => '/usr/lib/collectd', - :module => 'elasticsearch', - :script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', - :config => {'Cluster' => 'elasticsearch'}, - } - end - - it 'Will create /etc/collectd/conf.d/10-elasticsearch.conf' do - should contain_file('elasticsearch.load').with({ - :ensure => 'present', - :path => '/etc/collectd/conf.d/10-elasticsearch.conf', - :content => "\n Globals true\n\n\n\n ModulePath \"/usr/lib/collectd\"\n\n Import \"elasticsearch\"\n\n \n Verbose false\n\t\tCluster \"elasticsearch\"\n \n\n", - }) - end - it 'Will create /usr/lib/collectd/elasticsearch.py' do - should contain_file('elasticsearch.script').with({ - :ensure => 'present', - :path => '/usr/lib/collectd/elasticsearch.py', - #:content => "\n \n SecurityLevel \"Encrypt\"\n Username \"foo\"\n Password \"bar\"\n Interface \"eth0\"\n\n \n\n", - }) - end - end - - context ':ensure => absent' do - let :facts do - { - :osfamily => 'Debian' - } - end - let (:title) {'elasticsearch'} - let :params do - { - :ensure => 'absent', - :modulepath => '/usr/lib/collectd', - :module => 'elasticsearch', - :script_source => 'puppet:///modules/myorg/elasticsearch_collectd_python.py', - :config => {'Cluster' => 'elasticsearch'}, - } - end - it 'Will not create /etc/collectd/conf.d/10-elasticsearch.conf' do - should contain_file('elasticsearch.load').with({ - :ensure => 'absent', - :path => '/etc/collectd/conf.d/10-elasticsearch.conf', - }) - end - it 'Will not create /usr/lib/collectd/elasticsearch.py' do - should contain_file('elasticsearch.script').with({ - :ensure => 'absent', - :path => '/usr/lib/collectd/elasticsearch.py', - }) - end - end - -end diff --git a/module-collectd/templates/plugin/python/header.conf.erb b/module-collectd/templates/plugin/python/header.conf.erb new file mode 100644 index 000000000..3dbaad6b6 --- /dev/null +++ b/module-collectd/templates/plugin/python/header.conf.erb @@ -0,0 +1,10 @@ +# Generated by Puppet + +<% @module_dirs.sort.each do |path| -%> + ModulePath "<%= path %>" +<% end -%> +<% if @encoding -%> + Encoding <%= @encoding %> +<% end -%> + LogTraces <%= @logtraces %> + Interactive <%= @interactive %> diff --git a/module-collectd/templates/plugin/python/module.conf.erb b/module-collectd/templates/plugin/python/module.conf.erb new file mode 100644 index 000000000..b34638a33 --- /dev/null +++ b/module-collectd/templates/plugin/python/module.conf.erb @@ -0,0 +1,7 @@ + Import "<%= @module %>" + + "> + <% @config.sort.each do |key,value| -%> + <%= key -%> <%= value %> + <% end -%> + \ No newline at end of file diff --git a/module-collectd/templates/plugin/statsd.conf.erb b/module-collectd/templates/plugin/statsd.conf.erb index c821eff41..b9b5673c8 100644 --- a/module-collectd/templates/plugin/statsd.conf.erb +++ b/module-collectd/templates/plugin/statsd.conf.erb @@ -20,4 +20,16 @@ <% if @timerpercentile -%> TimerPercentile <%= @timerpercentile %> <% end -%> +<% if @timerupper -%> + TimerUpper <%= @timerupper %> +<% end -%> +<% if @timerlower -%> + TimerLower <%= @timerlower %> +<% end -%> +<% if @timersum -%> + TimerSum <%= @timersum %> +<% end -%> +<% if @timercount -%> + TimerCount <%= @timercount %> +<% end -%> diff --git a/module-collectd/templates/python.conf.erb b/module-collectd/templates/python.conf.erb deleted file mode 100644 index a72667001..000000000 --- a/module-collectd/templates/python.conf.erb +++ /dev/null @@ -1,16 +0,0 @@ - - Globals true - - - - ModulePath "<%= @modulepath %>" - - Import "<%= @module %>" - - "> - Verbose false -<% @config.sort.each do |key,value| -%> - <%= key -%> "<%= value -%>" -<% end -%> - -