Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Souter committed Dec 11, 2014
2 parents 1c481f7 + 3fae4b2 commit c3a8aaa
Show file tree
Hide file tree
Showing 16 changed files with 142 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
language: ruby
bundler_args: --without development
bundler_args: --without system_tests
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
matrix:
fast_finish: true
Expand Down
23 changes: 13 additions & 10 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
source ENV['GEM_SOURCE'] || "https://rubygems.org"

group :development, :test do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'serverspec', :require => false
gem 'puppet-lint', :require => false
gem 'beaker', :require => false
gem 'beaker-rspec', :require => false
gem 'pry', :require => false
gem 'simplecov', :require => false
group :development, :unit_tests do
gem 'rake', :require => false
gem 'rspec-puppet', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'puppet-lint', :require => false
gem 'simplecov', :require => false
gem 'puppet_facts', :require => false
gem 'json', :require => false
end

group :system_tests do
gem 'beaker-rspec', :require => false
gem 'serverspec', :require => false
end

if facterversion = ENV['FACTER_GEM_VERSION']
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ documentation for each plugin for configurable attributes.
* `apache` (see [collectd::plugin::apache](#class-collectdpluginapache) below)
* `bind` (see [collectd::plugin::bind](#class-collectdpluginbind) below)
* `cpu` (see [collectd::plugin::cpu](#class-collectdplugincpu) below)
* `cpufreq` (see [collectd::plugin::cpufreq](#class-collectdplugincpufreq) below)
* `csv` (see [collectd::plugin::csv](#class-collectdplugincsv) below)
* `curl` (see [collectd::plugin::curl](#class-collectdplugincurl) below)
* `curl_json` (see [collectd::plugin::curl_json](#class-collectdplugincurl_json) below)
Expand Down Expand Up @@ -146,6 +147,14 @@ class { 'collectd::plugin::bind':
```puppet
class { 'collectd::plugin::cpu':
}
```
####Class: `collectd::plugin::cpufreq`

```puppet
class { 'collectd::plugin::cpufreq':
}
```

####Class: `collectd::plugin::csv`
Expand Down
12 changes: 7 additions & 5 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#
define collectd::plugin (
$ensure = 'present',
$content = undef,
$order = '10',
$plugin = $name
$ensure = 'present',
$content = undef,
$order = '10',
$globals = false,
$interval = undef,
$plugin = $name
) {

include collectd::params
Expand All @@ -16,7 +18,7 @@
owner => root,
group => $root_group,
mode => '0640',
content => "# Generated by Puppet\nLoadPlugin ${plugin}\n\n${content}",
content => template('collectd/loadplugin.conf.erb'),
notify => Service['collectd'],
}

Expand Down
8 changes: 8 additions & 0 deletions manifests/plugin/conntrack.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://collectd.org/wiki/index.php/Plugin:ConnTrack
class collectd::plugin::conntrack (
$ensure = present,
) {
collectd::plugin {'conntrack':
ensure => $ensure
}
}
8 changes: 8 additions & 0 deletions manifests/plugin/cpufreq.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# https://collectd.org/wiki/index.php/Plugin:CPUFreq
class collectd::plugin::cpufreq (
$ensure = present,
) {
collectd::plugin {'cpufreq':
ensure => $ensure
}
}
6 changes: 5 additions & 1 deletion manifests/plugin/curl/page.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$header = undef,
$post = undef,
$measureresponsetime = undef,
$matches = [{ }],
$matches = undef,
$plugininstance = $name, # You can have multiple <Page> with the same name.
) {
include collectd::params
Expand All @@ -20,6 +20,10 @@

validate_string($url)

if $matches != undef {
validate_array($matches)
}

file { "${conf_dir}/curl-${name}.conf":
ensure => $ensure,
mode => '0640',
Expand Down
1 change: 1 addition & 0 deletions manifests/plugin/perl.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

collectd::plugin { 'perl':
ensure => $ensure,
globals => true,
order => $order,
content => template('collectd/plugin/perl.conf.erb')
}
Expand Down
27 changes: 27 additions & 0 deletions spec/classes/collectd_plugin_curl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,33 @@
end
end

context ':ensure => present, verifypeer => false, verifyhost => \'false\', measureresponsetime => true, matches empty' do
let :facts do
{:osfamily => 'Debian'}
end
let :params do
{
:ensure => 'present',
:pages => {
'selfsigned_ssl' => {
'url' => 'https://some.selfsigned.ssl.site/',
'verifypeer' => false,
'verifyhost' => 'false',
'measureresponsetime' => true,
},
}
}
end

it 'Will create /etc/collectd.d/conf.d/curl-selfsigned_ssl.conf' do
should contain_file('/etc/collectd/conf.d/curl-selfsigned_ssl.conf').with({
:ensure => 'present',
:path => '/etc/collectd/conf.d/curl-selfsigned_ssl.conf',
:content => "<Plugin curl>\n <Page \"selfsigned_ssl\">\n URL \"https://some.selfsigned.ssl.site/\"\n VerifyPeer false\n VerifyHost false\n MeasureResponseTime true\n </Page>\n</Plugin>\n",
})
end
end

context ':ensure => absent' do
let :facts do
{:osfamily => 'RedHat'}
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/collectd_plugin_swap_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
should contain_file('swap.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-swap.conf',
:content => "# Generated by Puppet\nLoadPlugin swap\n\n<Plugin swap>\n ReportByDevice false\n</Plugin>\n",
:content => "# Generated by Puppet\n<LoadPlugin swap>\n Globals false\n</LoadPlugin>\n\n<Plugin swap>\n ReportByDevice false\n</Plugin>\n\n",
})
end
end
Expand All @@ -42,7 +42,7 @@
should contain_file('swap.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-swap.conf',
:content => "# Generated by Puppet\nLoadPlugin swap\n\n<Plugin swap>\n ReportByDevice false\n ReportBytes true\n</Plugin>\n",
:content => "# Generated by Puppet\n<LoadPlugin swap>\n Globals false\n</LoadPlugin>\n\n<Plugin swap>\n ReportByDevice false\n ReportBytes true\n</Plugin>\n\n",
})
end
end
Expand Down
34 changes: 34 additions & 0 deletions spec/defines/collectd_plugin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
require 'spec_helper'

describe 'collectd::plugin', :type => :define do

context 'loading a plugin on collectd <= 4.9.4' do
let(:title) { 'test' }
let :facts do
{
:collectd_version => '5.3',
:osfamily => 'Debian',
}
end

it 'Will create /etc/collectd/conf.d/10-test.conf with the LoadPlugin syntax with brackets' do
should contain_file('test.load').with_content(/<LoadPlugin/)
end
end


context 'loading a plugin on collectd => 4.9.3' do
let(:title) { 'test' }
let :facts do
{
:collectd_version => '4.9.3',
:osfamily => 'Debian',
}
end

it 'Will create /etc/collectd/conf.d/10-test.conf with the LoadPlugin syntax without brackets' do
should contain_file('test.load').without_content(/<LoadPlugin/)
end
end

end
13 changes: 13 additions & 0 deletions templates/loadplugin.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by Puppet
<% if @collectd_version and (scope.function_versioncmp([@collectd_version, '4.9.4']) >= 0) -%>
<LoadPlugin <%= @plugin %>>
Globals <%= @globals %>
<% if @interval and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.2']) >= 0) -%>
Interval <%= @interval %>
<% end -%>
</LoadPlugin>
<% else -%>
LoadPlugin <%= @plugin %>
<% end -%>

<%= @content %>
12 changes: 7 additions & 5 deletions templates/plugin/curl-page.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
<% if @password -%>
Password "<%= @password %>"
<% end -%>
<% if @verifypeer -%>
VerifyPeer "<%= @verifypeer %>"
<% unless @verifypeer.nil? -%>
VerifyPeer <%= @verifypeer %>
<% end -%>
<% if @verifyhost %>
VerifyHost "<%= @verifyhost %>"
<% unless @verifyhost.nil? -%>
VerifyHost <%= @verifyhost %>
<% end -%>
<% if @cacert -%>
CACert "<%= @cacert %>"
Expand All @@ -22,9 +22,11 @@
<% if @post and @collectd_version and (scope.function_versioncmp([@collectd_version, '5.3']) >= 0) -%>
Post "<%= @post %>"
<% end -%>
<% if @measureresponsetime -%>
<% unless @measureresponsetime.nil? -%>
MeasureResponseTime <%= @measureresponsetime %>
<% end -%>
<% if @matches -%>
<%= scope.function_template(["collectd/plugin/match.tpl.erb"]) %>
<% end -%>
</Page>
</Plugin>
5 changes: 0 additions & 5 deletions templates/plugin/perl.conf.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
#
<LoadPlugin perl>
Globals true
</LoadPlugin>

Include "<%= @conf_dir %>/perl/*.conf"

12 changes: 6 additions & 6 deletions templates/plugin/statsd.conf.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
Host "<%= @host %>"
<% end -%>
<% if @port -%>
Port <%= port %>
Port <%= @port %>
<% end -%>
<% if @deletecounters -%>
DeleteCounters <%= deletecounters %>
DeleteCounters <%= @deletecounters %>
<% end -%>
<% if @deletetimers -%>
DeleteTimers <%= deletetimers %>
DeleteTimers <%= @deletetimers %>
<% end -%>
<% if @deletegauges -%>
DeleteGauges <%= deletegauges %>
DeleteGauges <%= @deletegauges %>
<% end -%>
<% if @deletesets -%>
Deletesets <%= deletesets %>
Deletesets <%= @deletesets %>
<% end -%>
<% if @timerpercentile -%>
TimerPercentile <%= timerpercentile %>
TimerPercentile <%= @timerpercentile %>
<% end -%>
</Plugin>
2 changes: 1 addition & 1 deletion tests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
collectd::plugin { 'processes': }
collectd::plugin { 'swap': }
collectd::plugin { 'users': }

collects::plugin { 'cpufreq': }

0 comments on commit c3a8aaa

Please sign in to comment.