diff --git a/manifests/plugin/ovs_stats.pp b/manifests/plugin/ovs_stats.pp new file mode 100644 index 000000000..29bc60bae --- /dev/null +++ b/manifests/plugin/ovs_stats.pp @@ -0,0 +1,59 @@ +#== Class: collectd::plugin::ovs_stats +# +# Class to manage ovs_stats plugin for collectd +# +# Documentation: +# https://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_ovs_stats +# +# === Parameters +# +# [* address *] +# The address of the OVS DB server JSON-RPC interface used by the plugin. +# +# [* bridges *] +# List of OVS bridge names to be monitored by this plugin. If this option +# is omitted or is empty then all OVS bridges will be monitored +# +# [*ensure*] +# ensure param for collectd::plugin type. +# Defaults to 'ensure' +# +# [*manage_package*] +# If enabled, manages separate package for plugin +# Defaults to true +# +# [*package_name*] +# If manage_package is true, this gives the name of the package to manage. +# Defaults to 'collectd-ovs_stats' +# +# [*port*] +# TCP-port to connect to. Either a service name or a port number may be given. +# +# [*socket*] +# The UNIX domain socket path of OVS DB server JSON-RPC interface used +# by the plugin +# +class collectd::plugin::ovs_stats ( + Optional[String] $address = undef, + Optional[Array] $bridges = undef, + String $ensure = 'present', + Boolean $manage_package = true, + String $package_name = 'collectd-ovs-stats', + Optional[Integer] $port = undef, + Optional[String] $socket = undef, +) { + + include ::collectd + + if $manage_package { + package { 'collectd-ovs-stats': + ensure => $ensure, + name => $package_name, + } + } + + collectd::plugin { 'ovs_stats': + ensure => $ensure, + content => template('collectd/plugin/ovs_stats.conf.erb'), + } +} diff --git a/spec/classes/collectd_plugin_ovs_stats_spec.rb b/spec/classes/collectd_plugin_ovs_stats_spec.rb new file mode 100644 index 000000000..6506c0b7b --- /dev/null +++ b/spec/classes/collectd_plugin_ovs_stats_spec.rb @@ -0,0 +1,66 @@ +require 'spec_helper' + +describe 'collectd::plugin::ovs_stats', type: :class do + on_supported_os(test_on).each do |os, facts| + context "on #{os} " do + let :facts do + facts + end + + options = os_specific_options(facts) + + context ':ensure => present' do + let :params do + { address: 'foo.bar.baz', + bridges: ['bar', 'baz'], + port: 666, + socket: '/foo/bar/baz' } + end + + it "will create #{options[:plugin_conf_dir]}/10-ovs_stats.conf" do + is_expected.to contain_file('ovs_stats.load').with( + ensure: 'present', + path: "#{options[:plugin_conf_dir]}/10-ovs_stats.conf" + ) + end + + it 'will create config which will contain port configuration' do + is_expected.to contain_file('ovs_stats.load').with( + :content => %r{Port 666} + ) + end + + it 'will create config which will contain address configuration' do + is_expected.to contain_file('ovs_stats.load').with( + :content => %r{Address "foo.bar.baz"} + ) + end + + it 'will create config which will contain socket configuration' do + is_expected.to contain_file('ovs_stats.load').with( + :content => %r{Socket "/foo/bar/baz"} + ) + end + + it 'will create config which will contain bridges configuration' do + is_expected.to contain_file('ovs_stats.load').with( + :content => %r{Bridges "bar" "baz"} + ) + end + end + + context ':ensure => absent' do + let :params do + { ensure: 'absent' } + end + + it "will not create #{options[:plugin_conf_dir]}/10-ovs_stats.conf" do + is_expected.to contain_file('ovs_stats.load').with( + ensure: 'absent', + path: "#{options[:plugin_conf_dir]}/10-ovs_stats.conf" + ) + end + end + end + end +end diff --git a/templates/plugin/ovs_stats.conf.erb b/templates/plugin/ovs_stats.conf.erb new file mode 100644 index 000000000..399021dbf --- /dev/null +++ b/templates/plugin/ovs_stats.conf.erb @@ -0,0 +1,14 @@ + +<%- if @port %> + Port <%= @port %> +<%- end -%> +<%- if @address %> + Address "<%= @address %>" +<%- end -%> +<%- if @socket %> + Socket "<%= @socket %>" +<%- end -%> +<%- if @bridges %> + Bridges "<%= @bridges.join('" "') %>" +<%- end -%> +