Skip to content

Commit

Permalink
Merge pull request redhat-openstack#295 from tbielawa/master
Browse files Browse the repository at this point in the history
Begin adding support for multiple openvpn 'statusfile' parameters
  • Loading branch information
blkperl committed Jul 21, 2015
2 parents 85e230c + ffb56ba commit 71a1bdf
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 2 deletions.
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,32 @@ class { 'collectd::plugin::ntpd':

####Class: `collectd::plugin::openvpn`

* `statusfile` (String or Array) Status file(s) to collect data from. (Default `/etc/openvpn/openvpn-status.log`)
* `improvednamingschema` (Bool) When enabled, the filename of the status file will be used as plugin instance and the client's "common name" will be used as type instance. This is required when reading multiple status files. (Default: `false`)
* `collectcompression` Sets whether or not statistics about the compression used by OpenVPN should be collected. This information is only available in single mode. (Default `true`)
* `collectindividualusers` Sets whether or not traffic information is collected for each connected client individually. If set to false, currently no traffic data is collected at all because aggregating this data in a save manner is tricky. (Default `true`)
* `collectusercount` When enabled, the number of currently connected clients or users is collected. This is especially interesting when CollectIndividualUsers is disabled, but can be configured independently from that option. (Default `false`)

Watch multiple `statusfile`s:

```puppet
class { 'collectd::plugin::openvpn':
statusfile => [ '/etc/openvpn/openvpn-status-tcp.log', '/etc/openvpn/openvpn-status-udp.log' ],
collectindividualusers => false,
collectusercount => true,
}
```

Watch the single default `statusfile`:

```puppet
class { 'collectd::plugin::openvpn':
collectindividualusers => false,
collectusercount => true,
}
```


####Class: `collectd::plugin::perl`

This class has no parameters and will load the actual perl plugin.
Expand Down
10 changes: 9 additions & 1 deletion manifests/plugin/openvpn.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,15 @@
$collectusercount = false,
$interval = undef,
) {
validate_absolute_path($statusfile)
if is_string($statusfile) {
validate_absolute_path($statusfile)
$statusfiles = [ $statusfile ]
} elsif is_array($statusfile) {
$statusfiles = $statusfile
} else {
fail("statusfile must be either array or string: ${statusfile}")
}

validate_bool(
$improvednamingschema,
$collectcompression,
Expand Down
171 changes: 171 additions & 0 deletions spec/classes/collectd_plugin_openvpn_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
require 'spec_helper'

describe 'collectd::plugin::openvpn', :type => :class do

######################################################################
# Default param validation, compilation succeeds

context ':ensure => present, default params' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4',
}
end

it 'Will create /etc/collectd.d/10-openvpn.conf' do
should contain_file('openvpn.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-openvpn.conf',
:content => "#\ Generated by Puppet\n<LoadPlugin openvpn>\n Globals false\n</LoadPlugin>\n\n<Plugin openvpn>\n StatusFile \"/etc/openvpn/openvpn-status.log\"\n ImprovedNamingSchema false\n CollectCompression true\n CollectIndividualUsers true\n CollectUserCount false\n</Plugin>\n\n",
})
end
end

context ':statusfile param is an array' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4',
}
end

let :params do
{:statusfile => ['/etc/openvpn/openvpn-tcp.status', '/etc/openvpn/openvpn-udp.status']}
end

it 'Will create /etc/collectd.d/10-openvpn.conf with two :statusfile params' do
should contain_file('openvpn.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-openvpn.conf',
:content => "#\ Generated by Puppet\n<LoadPlugin openvpn>\n Globals false\n</LoadPlugin>\n\n<Plugin openvpn>\n StatusFile \"/etc/openvpn/openvpn-tcp.status\"\n StatusFile \"/etc/openvpn/openvpn-udp.status\"\n ImprovedNamingSchema false\n CollectCompression true\n CollectIndividualUsers true\n CollectUserCount false\n</Plugin>\n\n",
})
end
end

######################################################################
# Remaining parameter validation, compilation fails

context ':statusfile is a string but not an absolute path' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4',
}
end

let :params do
{:statusfile => 'megafrobber'}
end

it 'Will raise an error about :statusfile not being an absolute path' do
should compile.and_raise_error(/"megafrobber" is not an absolute path./)
end
end


context ':statusfile param is not a string or array' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4',
}
end

let :params do
{:statusfile => true}
end

it 'Will raise an error about :statusfile not being a string or array' do
should compile.and_raise_error(/array or string:/)
end
end

context ':improvednamingschema is not a bool' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4'}
end
let :params do
{:improvednamingschema => "true"}
end

it 'Will raise an error about :improvednamingschema not being a boolean' do
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
end
end

context ':collectcompression is not a bool' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4'}
end
let :params do
{:collectcompression => "true"}
end

it 'Will raise an error about :collectcompression not being a boolean' do
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
end
end

context ':collectindividualusers is not a bool' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4'}
end
let :params do
{:collectindividualusers => "true"}
end

it 'Will raise an error about :collectindividualusers not being a boolean' do
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
end
end

context ':collectusercount is not a bool' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4'}
end
let :params do
{:collectusercount => "true"}
end

it 'Will raise an error about :collectusercount not being a boolean' do
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
end
end

context ':interval is not default and is an integer' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4'}
end
let :params do
{:interval => 15}
end

it 'Will create /etc/collectd.d/10-openvpn.conf' do
should contain_file('openvpn.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-openvpn.conf',
:content => /^ Interval 15/,
})
end
end

context ':ensure => absent' do
let :facts do
{ :osfamily => 'RedHat',
:collectd_version => '5.4',
}
end
let :params do
{:ensure => 'absent'}
end

it 'Will not create /etc/collectd.d/10-openvpn.conf' do
should contain_file('openvpn.load').with({
:ensure => 'absent',
:path => '/etc/collectd.d/10-openvpn.conf',
})
end
end
end
4 changes: 3 additions & 1 deletion templates/plugin/openvpn.conf.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<Plugin openvpn>
StatusFile "<%= @statusfile %>"
<% @statusfiles.each do |sf| -%>
StatusFile "<%= sf %>"
<% end -%>
ImprovedNamingSchema <%= @improvednamingschema %>
CollectCompression <%= @collectcompression %>
CollectIndividualUsers <%= @collectindividualusers %>
Expand Down

0 comments on commit 71a1bdf

Please sign in to comment.