Skip to content

Commit 71a1bdf

Browse files
committed
Merge pull request redhat-openstack#295 from tbielawa/master
Begin adding support for multiple openvpn 'statusfile' parameters
2 parents 85e230c + ffb56ba commit 71a1bdf

4 files changed

Lines changed: 202 additions & 2 deletions

File tree

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,13 +513,32 @@ class { 'collectd::plugin::ntpd':
513513

514514
####Class: `collectd::plugin::openvpn`
515515

516+
* `statusfile` (String or Array) Status file(s) to collect data from. (Default `/etc/openvpn/openvpn-status.log`)
517+
* `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`)
518+
* `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`)
519+
* `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`)
520+
* `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`)
521+
522+
Watch multiple `statusfile`s:
523+
516524
```puppet
517525
class { 'collectd::plugin::openvpn':
526+
statusfile => [ '/etc/openvpn/openvpn-status-tcp.log', '/etc/openvpn/openvpn-status-udp.log' ],
518527
collectindividualusers => false,
519528
collectusercount => true,
520529
}
521530
```
522531

532+
Watch the single default `statusfile`:
533+
534+
```puppet
535+
class { 'collectd::plugin::openvpn':
536+
collectindividualusers => false,
537+
collectusercount => true,
538+
}
539+
```
540+
541+
523542
####Class: `collectd::plugin::perl`
524543

525544
This class has no parameters and will load the actual perl plugin.

manifests/plugin/openvpn.pp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,15 @@
88
$collectusercount = false,
99
$interval = undef,
1010
) {
11-
validate_absolute_path($statusfile)
11+
if is_string($statusfile) {
12+
validate_absolute_path($statusfile)
13+
$statusfiles = [ $statusfile ]
14+
} elsif is_array($statusfile) {
15+
$statusfiles = $statusfile
16+
} else {
17+
fail("statusfile must be either array or string: ${statusfile}")
18+
}
19+
1220
validate_bool(
1321
$improvednamingschema,
1422
$collectcompression,
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
require 'spec_helper'
2+
3+
describe 'collectd::plugin::openvpn', :type => :class do
4+
5+
######################################################################
6+
# Default param validation, compilation succeeds
7+
8+
context ':ensure => present, default params' do
9+
let :facts do
10+
{ :osfamily => 'RedHat',
11+
:collectd_version => '5.4',
12+
}
13+
end
14+
15+
it 'Will create /etc/collectd.d/10-openvpn.conf' do
16+
should contain_file('openvpn.load').with({
17+
:ensure => 'present',
18+
:path => '/etc/collectd.d/10-openvpn.conf',
19+
: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",
20+
})
21+
end
22+
end
23+
24+
context ':statusfile param is an array' do
25+
let :facts do
26+
{ :osfamily => 'RedHat',
27+
:collectd_version => '5.4',
28+
}
29+
end
30+
31+
let :params do
32+
{:statusfile => ['/etc/openvpn/openvpn-tcp.status', '/etc/openvpn/openvpn-udp.status']}
33+
end
34+
35+
it 'Will create /etc/collectd.d/10-openvpn.conf with two :statusfile params' do
36+
should contain_file('openvpn.load').with({
37+
:ensure => 'present',
38+
:path => '/etc/collectd.d/10-openvpn.conf',
39+
: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",
40+
})
41+
end
42+
end
43+
44+
######################################################################
45+
# Remaining parameter validation, compilation fails
46+
47+
context ':statusfile is a string but not an absolute path' do
48+
let :facts do
49+
{ :osfamily => 'RedHat',
50+
:collectd_version => '5.4',
51+
}
52+
end
53+
54+
let :params do
55+
{:statusfile => 'megafrobber'}
56+
end
57+
58+
it 'Will raise an error about :statusfile not being an absolute path' do
59+
should compile.and_raise_error(/"megafrobber" is not an absolute path./)
60+
end
61+
end
62+
63+
64+
context ':statusfile param is not a string or array' do
65+
let :facts do
66+
{ :osfamily => 'RedHat',
67+
:collectd_version => '5.4',
68+
}
69+
end
70+
71+
let :params do
72+
{:statusfile => true}
73+
end
74+
75+
it 'Will raise an error about :statusfile not being a string or array' do
76+
should compile.and_raise_error(/array or string:/)
77+
end
78+
end
79+
80+
context ':improvednamingschema is not a bool' do
81+
let :facts do
82+
{ :osfamily => 'RedHat',
83+
:collectd_version => '5.4'}
84+
end
85+
let :params do
86+
{:improvednamingschema => "true"}
87+
end
88+
89+
it 'Will raise an error about :improvednamingschema not being a boolean' do
90+
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
91+
end
92+
end
93+
94+
context ':collectcompression is not a bool' do
95+
let :facts do
96+
{ :osfamily => 'RedHat',
97+
:collectd_version => '5.4'}
98+
end
99+
let :params do
100+
{:collectcompression => "true"}
101+
end
102+
103+
it 'Will raise an error about :collectcompression not being a boolean' do
104+
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
105+
end
106+
end
107+
108+
context ':collectindividualusers is not a bool' do
109+
let :facts do
110+
{ :osfamily => 'RedHat',
111+
:collectd_version => '5.4'}
112+
end
113+
let :params do
114+
{:collectindividualusers => "true"}
115+
end
116+
117+
it 'Will raise an error about :collectindividualusers not being a boolean' do
118+
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
119+
end
120+
end
121+
122+
context ':collectusercount is not a bool' do
123+
let :facts do
124+
{ :osfamily => 'RedHat',
125+
:collectd_version => '5.4'}
126+
end
127+
let :params do
128+
{:collectusercount => "true"}
129+
end
130+
131+
it 'Will raise an error about :collectusercount not being a boolean' do
132+
should compile.and_raise_error(/"true" is not a boolean. It looks to be a String/)
133+
end
134+
end
135+
136+
context ':interval is not default and is an integer' do
137+
let :facts do
138+
{ :osfamily => 'RedHat',
139+
:collectd_version => '5.4'}
140+
end
141+
let :params do
142+
{:interval => 15}
143+
end
144+
145+
it 'Will create /etc/collectd.d/10-openvpn.conf' do
146+
should contain_file('openvpn.load').with({
147+
:ensure => 'present',
148+
:path => '/etc/collectd.d/10-openvpn.conf',
149+
:content => /^ Interval 15/,
150+
})
151+
end
152+
end
153+
154+
context ':ensure => absent' do
155+
let :facts do
156+
{ :osfamily => 'RedHat',
157+
:collectd_version => '5.4',
158+
}
159+
end
160+
let :params do
161+
{:ensure => 'absent'}
162+
end
163+
164+
it 'Will not create /etc/collectd.d/10-openvpn.conf' do
165+
should contain_file('openvpn.load').with({
166+
:ensure => 'absent',
167+
:path => '/etc/collectd.d/10-openvpn.conf',
168+
})
169+
end
170+
end
171+
end

templates/plugin/openvpn.conf.erb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<Plugin openvpn>
2-
StatusFile "<%= @statusfile %>"
2+
<% @statusfiles.each do |sf| -%>
3+
StatusFile "<%= sf %>"
4+
<% end -%>
35
ImprovedNamingSchema <%= @improvednamingschema %>
46
CollectCompression <%= @collectcompression %>
57
CollectIndividualUsers <%= @collectindividualusers %>

0 commit comments

Comments
 (0)