From 8c2ad77e380478ae7da7b76aaacb1d71c881fdf2 Mon Sep 17 00:00:00 2001 From: Tom Throckmorton Date: Mon, 1 Jun 2015 17:36:25 -0400 Subject: [PATCH 1/2] add support for protocols plugin --- README.md | 16 +++++++++++++++- manifests/plugin/protocols.pp | 19 +++++++++++++++++++ templates/plugin/protocols.conf.erb | 16 ++++++++++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 manifests/plugin/protocols.pp create mode 100644 templates/plugin/protocols.conf.erb diff --git a/README.md b/README.md index fd7d44c75..b91c6208e 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ documentation for each plugin for configurable attributes. * `ping` (see [collectd::plugin::ping](#class-collectdpluginping) below) * `postgresql` (see [collectd::plugin::postgresql](#class-collectdpluginpostgresql) below) * `processes` (see [collectd::plugin:processes](#class-collectdpluginprocesses) below) +* `protocols` (see [collectd::plugin:protocols](#class-collectdpluginprotocols) below) * `python` (see [collectd::plugin::python](#class-collectdpluginpython) below) * `redis` (see [collectd::plugin::redis](#class-collectdpluginredis) below) * `rrdcached` (see [collectd::plugin::rrdcached](#class-collectdpluginrrdcached) below) @@ -647,6 +648,19 @@ class { 'collectd::plugin::processes': ], } ``` +####Class: `collectd::plugin::protocols` + + * `values` is an array of `Protocol` names, `Protocol:ValueName` pairs, or a regex + * see `/proc/net/netstat` and `/proc/net/snmp` for a list of `Protocol` targets + + See [collectd.conf documentation] (https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_protocols) for details + +```puppet +class { 'collectd::plugin::protocols': + values => ['/^Tcp:*/', '/^Udp:*/', 'Icmp:InErrors' ], + ignoreselected => false, +} +``` ####Class: `collectd::plugin::python` @@ -977,4 +991,4 @@ This module shall not use unsupported configuration directives. Look at [templat Please make use of the search by branch/tags on the collectd github to see when a function has been first released. -Reading the [collectd.conf.pod](https://github.com/collectd/collectd/blob/master/src/collectd.conf.pod) file is good, validating the presence of the code in the .c files is even better. \ No newline at end of file +Reading the [collectd.conf.pod](https://github.com/collectd/collectd/blob/master/src/collectd.conf.pod) file is good, validating the presence of the code in the .c files is even better. diff --git a/manifests/plugin/protocols.pp b/manifests/plugin/protocols.pp new file mode 100644 index 000000000..81d8fd0bc --- /dev/null +++ b/manifests/plugin/protocols.pp @@ -0,0 +1,19 @@ +# See http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_protocols +class collectd::plugin::protocols ( + $ensure = present, + $ignoreselected = false, + $values = [] +) { + + validate_array( + $values, + ) + validate_bool( + $ignoreselected, + ) + + collectd::plugin {'protocols': + ensure => $ensure, + content => template('collectd/plugin/protocols.conf.erb'), + } +} diff --git a/templates/plugin/protocols.conf.erb b/templates/plugin/protocols.conf.erb new file mode 100644 index 000000000..acdee21ca --- /dev/null +++ b/templates/plugin/protocols.conf.erb @@ -0,0 +1,16 @@ +<% if @values -%> + +<% +if @values + @values.each do |value| +-%> + Value "<%= value %>" +<% + end +end +-%> +<% if @ignore_selected != nil -%> + IgnoreSelected <%= @ignore_selected %> +<% end -%> + +<% end -%> From 67af5f9b6f43389daaf2260720f447a46f36c3c6 Mon Sep 17 00:00:00 2001 From: Tom Throckmorton Date: Fri, 19 Jun 2015 10:02:56 -0400 Subject: [PATCH 2/2] add rspec test --- .../classes/collectd_plugin_protocols_spec.rb | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 spec/classes/collectd_plugin_protocols_spec.rb diff --git a/spec/classes/collectd_plugin_protocols_spec.rb b/spec/classes/collectd_plugin_protocols_spec.rb new file mode 100644 index 000000000..21cb12ae6 --- /dev/null +++ b/spec/classes/collectd_plugin_protocols_spec.rb @@ -0,0 +1,46 @@ +require 'spec_helper' + +describe 'collectd::plugin::protocols', :type => :class do + let :facts do + {:osfamily => 'RedHat'} + end + + context ':ensure => present, default params' do + it 'Will create /etc/collectd.d/10-protocols.conf' do + should contain_file('protocols.load').with({ + :ensure => 'present', + :path => '/etc/collectd.d/10-protocols.conf', + :content => //, + }) + end + end + + context ':ensure => present, specific params' do + let :params do + { :values => [ 'protocol1', 'protocol2' ], + } + end + + it 'Will create /etc/collectd.d/10-protocols.conf' do + should contain_file('protocols.load').with({ + :ensure => 'present', + :path => '/etc/collectd.d/10-protocols.conf', + :content => /\n\s*Value "protocol1"\n\s*Value "protocol2"\n<\/Plugin>/, + }) + end + end + + context ':ensure => absent' do + let :params do + {:ensure => 'absent'} + end + + it 'Will not create /etc/collectd.d/10-protocols.conf' do + should contain_file('protocols.load').with({ + :ensure => 'absent', + :path => '/etc/collectd.d/10-protocols.conf', + }) + end + end +end +