diff --git a/README.md b/README.md index 7bb37bdb4..008f184aa 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) @@ -656,6 +657,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` 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/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 + 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 -%>