forked from redhat-openstack/openstack-puppet-modules
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
split out the snmp data and hosts into defines
this will make it a lot easier to have a "centralized" collectd snmp collector that will gather information from network devices and such which are puppetized but don't run their own collectd :)
- Loading branch information
Showing
8 changed files
with
198 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# https://collectd.org/wiki/index.php/Plugin:SNMP | ||
define collectd::plugin::snmp::data ( | ||
$ensure = present, | ||
$type, | ||
$table = false, | ||
$instance, | ||
$values, | ||
) { | ||
include collectd | ||
include collectd::plugin::snmp | ||
|
||
$table_bool = str2bool($table) | ||
|
||
$conf_dir = $collectd::params::plugin_conf_dir | ||
$root_group = $collectd::params::root_group | ||
|
||
file { "snmp-data-${name}.conf": | ||
ensure => $ensure, | ||
path => "${conf_dir}/15-snmp-data-${name}.conf", | ||
owner => 'root', | ||
group => $root_group, | ||
mode => '0640', | ||
content => template('collectd/plugin/snmp/data.conf.erb'), | ||
notify => Service['collectd']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# https://collectd.org/wiki/index.php/Plugin:SNMP | ||
define collectd::plugin::snmp::host ( | ||
$ensure = present, | ||
$address = $name, | ||
$version = 1, | ||
$community = 'public', | ||
$collect, | ||
$interval = undef, | ||
) { | ||
include collectd | ||
include collectd::plugin::snmp | ||
|
||
validate_re($version, '^[12]$', 'only snmp versions 1 and 2 are supported') | ||
|
||
$conf_dir = $collectd::params::plugin_conf_dir | ||
$root_group = $collectd::params::root_group | ||
|
||
file { "snmp-host-${name}.conf": | ||
ensure => $ensure, | ||
path => "${conf_dir}/25-snmp-host-${name}.conf", | ||
owner => 'root', | ||
group => $root_group, | ||
mode => '0640', | ||
content => template('collectd/plugin/snmp/host.conf.erb'), | ||
notify => Service['collectd']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
require 'spec_helper' | ||
|
||
describe 'collectd::plugin::snmp::data', :type => :define do | ||
let :facts do | ||
{:osfamily => 'Debian'} | ||
end | ||
|
||
let (:title) { 'foo' } | ||
let (:required_params) {{ | ||
:type => 'bar', | ||
:instance => 'baz', | ||
:values => 'bat', | ||
}} | ||
|
||
let (:filename) { 'snmp-data-foo.conf' } | ||
|
||
context 'required params' do | ||
let (:params) { required_params } | ||
|
||
it { should contain_file(filename).with( | ||
:ensure => 'present', | ||
:path => '/etc/collectd/conf.d/15-snmp-data-foo.conf' | ||
) } | ||
|
||
it { should contain_file('snmp-data-foo.conf').that_notifies('Service[collectd]') } | ||
it { should contain_file('snmp-data-foo.conf').with_content(/<Plugin snmp>/) } | ||
it { should contain_file('snmp-data-foo.conf').with_content(/<Data "foo">/) } | ||
it { should contain_file('snmp-data-foo.conf').with_content(/Type "bar"/) } | ||
it { should contain_file('snmp-data-foo.conf').with_content(/Instance "baz"/) } | ||
end | ||
|
||
context 'values is an array' do | ||
let (:params) { | ||
required_params.merge({ | ||
:values => %w{ foo bar baz } | ||
}) | ||
} | ||
it { should contain_file('snmp-data-foo.conf').with_content(/Values foo bar baz/) } | ||
end | ||
|
||
context 'values is just a string' do | ||
let (:params) { | ||
required_params.merge({ | ||
:values => 'bat' | ||
}) | ||
} | ||
it { should contain_file('snmp-data-foo.conf').with_content(/Values bat/) } | ||
end | ||
|
||
context 'table is true' do | ||
let (:params) {{ | ||
:table => true | ||
}.merge(required_params)} | ||
|
||
it { should contain_file('snmp-data-foo.conf').with_content(/Table true/) } | ||
end | ||
|
||
context 'table is false' do | ||
let (:params) {{ | ||
:table => false | ||
}.merge(required_params)} | ||
|
||
it { should contain_file('snmp-data-foo.conf').with_content(/Table false/) } | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require 'spec_helper' | ||
|
||
describe 'collectd::plugin::snmp::host', :type => :define do | ||
let :facts do | ||
{:osfamily => 'Debian'} | ||
end | ||
|
||
let (:title) { 'foo.example.com' } | ||
let (:required_params) {{ | ||
:collect => 'foo' | ||
}} | ||
|
||
let (:filename) { 'snmp-host-foo.example.com.conf' } | ||
|
||
context 'default params' do | ||
let (:params) { required_params } | ||
|
||
it { should contain_file(filename).with( | ||
:ensure => 'present', | ||
:path => '/etc/collectd/conf.d/25-snmp-host-foo.example.com.conf' | ||
) } | ||
|
||
it { should contain_file(filename).that_notifies('Service[collectd]') } | ||
it { should contain_file(filename).with_content(/<Plugin snmp>/) } | ||
it { should contain_file(filename).with_content(/<Host "foo\.example\.com">/) } | ||
it { should contain_file(filename).with_content(/Address "foo\.example\.com"/) } | ||
it { should contain_file(filename).with_content(/Version 1/) } | ||
it { should contain_file(filename).with_content(/Community "public"/) } | ||
it { should contain_file(filename).without_content(/Interval \d+/) } | ||
end | ||
|
||
context 'all params set' do | ||
let (:params) { | ||
required_params.merge({ | ||
:address => 'bar.example.com', | ||
:version => '2', | ||
:community => 'opensesame', | ||
:interval => '30', | ||
}) | ||
} | ||
it { should contain_file(filename).with_content(/Address "bar\.example\.com"/) } | ||
it { should contain_file(filename).with_content(/Version 2/) } | ||
it { should contain_file(filename).with_content(/Community "opensesame"/) } | ||
it { should contain_file(filename).with_content(/Interval 30/) } | ||
end | ||
|
||
context 'collect is an array' do | ||
let (:params) {{ | ||
:collect => %w{ foo bar baz } | ||
}} | ||
it { should contain_file(filename).with_content(/Collect foo bar baz/) } | ||
end | ||
|
||
context 'collect is just a string' do | ||
let (:params) {{ | ||
:collect => 'bat' | ||
}} | ||
it { should contain_file(filename).with_content(/Collect bat/) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Plugin snmp> | ||
<Data "<%= @name %>"> | ||
Type "<%= @type %>" | ||
Table <%= @table_bool ? 'true' : 'false' %> | ||
Instance "<%= @instance %>" | ||
Values <%= Array(@values).join(' ') %> | ||
</Data> | ||
</Plugin> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Plugin snmp> | ||
<Host "<%= @name %>"> | ||
Address "<%= @address %>" | ||
Version <%= @version %> | ||
Community "<%= @community %>" | ||
Collect <%= Array(@collect).join(" ") %> | ||
<%- if !@interval.nil? -%> | ||
Interval <%= @interval %> | ||
<%- end -%> | ||
</Host> | ||
</Plugin> |