forked from voxpupuli/puppet-collectd
-
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.
- Loading branch information
Fabien Wernli
committed
Jul 24, 2014
1 parent
c545678
commit 2cf3b6d
Showing
7 changed files
with
274 additions
and
0 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
Empty file.
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,21 @@ | ||
# See http://collectd.org/documentation/manpages/collectd-perl.5.shtml | ||
class collectd::plugin::perl () | ||
{ | ||
include collectd::params | ||
$conf_dir = $collectd::params::plugin_conf_dir | ||
$filename = "${conf_dir}/perl.conf" | ||
file { $filename: | ||
mode => '0644', | ||
owner => $collectd::params::root_user, | ||
group => $collectd::params::root_group, | ||
notify => Service['collectd'], | ||
content => template('collectd/plugin/perl.conf.erb'), | ||
} | ||
file { "${conf_dir}/perl": | ||
ensure => directory, | ||
mode => '0755', | ||
owner => $collectd::params::root_user, | ||
group => $collectd::params::root_group, | ||
} | ||
} | ||
|
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,77 @@ | ||
# | ||
define collectd::plugin::perl::plugin ( | ||
$module, | ||
$enable_debugger = false, | ||
$include_dir = false, | ||
$provider = false, | ||
$source = false, | ||
$destination = false, | ||
$order = '01', | ||
$config = {}, | ||
) { | ||
include collectd::params | ||
if ! defined(Class['Collectd::Plugin::Perl']) { | ||
include collectd::plugin::perl | ||
} | ||
|
||
validate_hash($config) | ||
validate_re($order, '\d+') | ||
if $enable_debugger { | ||
validate_string($enable_debugger) | ||
} | ||
if $include_dir { | ||
if is_string($include_dir) { | ||
$include_dirs = [ $include_dir ] | ||
} elsif is_array($include_dir) { | ||
$include_dirs = $include_dir | ||
} else { | ||
fail("include_dir must be either array or string: ${include_dir}") | ||
} | ||
} else { | ||
$include_dirs = [] | ||
} | ||
|
||
$conf_dir = $collectd::params::plugin_conf_dir | ||
$base_filename = $collectd::plugin::perl::filename | ||
$filename = "${conf_dir}/perl/plugin-${order}_${name}.conf" | ||
|
||
file { $filename: | ||
owner => $collectd::params::root_user, | ||
group => $collectd::params::root_group, | ||
mode => '0644', | ||
content => template('collectd/plugin/perl/plugin.erb'), | ||
} | ||
|
||
case $provider { | ||
'package': { | ||
validate_string($source) | ||
package { $source: | ||
require => File[$base_filename], | ||
} | ||
} | ||
'cpan': { | ||
validate_string($source) | ||
include cpan | ||
cpan { $source: | ||
require => File[$base_filename], | ||
} | ||
} | ||
'file': { | ||
validate_string($source) | ||
validate_string($destination) | ||
file { "collectd_plugin_perl_${name}.pm": | ||
path => "${destination}/${module}.pm", | ||
mode => '0644', | ||
source => $source, | ||
require => File[$base_filename], | ||
} | ||
} | ||
false: { | ||
# this will fail if perl collectd plugin module is not installed | ||
exec { "perl -M${module} -e 1": path => $::path } | ||
} | ||
default: { | ||
fail("Unsupported provider: ${provider}. Use 'package', 'cpan', 'file' or false.") | ||
} | ||
} | ||
} |
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,7 @@ | ||
# | ||
<LoadPlugin perl> | ||
Globals true | ||
</LoadPlugin> | ||
|
||
Include "<%= @conf_dir %>/perl/*.conf" | ||
|
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,48 @@ | ||
<Plugin perl> | ||
<% if @enable_debugger -%> | ||
EnableDebugger "<% @enable_debugger %>" | ||
<% end -%> | ||
<% if @include_dir -%> | ||
<% @include_dirs.each do |dir| -%> | ||
IncludeDir "<%= dir %>" | ||
<% end -%> | ||
<% end -%> | ||
LoadPlugin "<%= @module %>" | ||
<% if ! @config.empty? -%> | ||
<Plugin "<%= @name %>"> | ||
<% @config.each do |key,value| -%> | ||
<% if value.is_a?(Array) -%> | ||
<% value.each do |v| -%> | ||
<%= key %> "<%= v %>" | ||
<% end -%> | ||
<% elsif value.is_a?(Hash) -%> | ||
<<%=key%>> | ||
<% value.each do |k,v| -%> | ||
<% if v.is_a?(String) -%> | ||
<%=k%> "<%=v%>" | ||
<% elsif v.is_a?(Array) -%> | ||
<% v.each do |l| -%> | ||
<%= k %> "<%= l %>" | ||
<% end -%> | ||
<% elsif v.is_a?(Hash) -%> | ||
<<%=k%>> | ||
<% v.each do |i,j| -%> | ||
<% if j.is_a?(Array) -%> | ||
<% j.each do |k| -%> | ||
<%=i%> "<%=k%>" | ||
<% end -%> | ||
<% else -%> | ||
<%=i%> "<%=j%>" | ||
<% end -%> | ||
<% end -%> | ||
</<%=k%>> | ||
<% end -%> | ||
<% end -%> | ||
</<%=key%>> | ||
<% else -%> | ||
<%= key -%> "<%= value -%>" | ||
<% end -%> | ||
<% end -%> | ||
</Plugin> | ||
<% end -%> | ||
</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,52 @@ | ||
class { collectd: | ||
purge_config => true, | ||
purge => true, | ||
recurse => true, | ||
} | ||
|
||
include collectd::plugin::perl | ||
|
||
collectd::plugin::perl::plugin { 'foo': | ||
include_dir => '/tmp', | ||
module => 'Collectd::Plugins::Foo', | ||
provider => 'file', | ||
source => 'puppet:///modules/collectd/tests/Foo.pm', | ||
destination => '/tmp', | ||
order => 99, | ||
config => { | ||
'foo' => 'bar', | ||
'key' => [ 'val1', 'val2' ], | ||
} | ||
} | ||
|
||
collectd::plugin::perl::plugin { 'bar': | ||
module => 'B', | ||
enable_debugger => "DProf", | ||
include_dir => ['/tmp', '/tmp/lib' ] | ||
} | ||
|
||
#collectd::plugin::perl { | ||
# 'openafs_vos': | ||
# module => 'Collectd::Plugins::OpenAFS::VOS', | ||
# provider => 'cpan', | ||
# source => 'Collectd::Plugins::OpenAFS', | ||
# config => {'VosBin' => '/usr/afsws/etc/vos'}, | ||
#} | ||
|
||
collectd::plugin::perl::plugin { | ||
'baar': | ||
module => 'Collectd::Plugins::Bar', | ||
provider => 'package', | ||
source => 'perl-Collectd-Plugins-Bar', | ||
config => { | ||
'foo' => 'bar', | ||
'more' => { | ||
'complex' => 'structure', | ||
'no' => [ "a", "b" ], | ||
'yes' => { | ||
'last' => 'level', | ||
'and' => [ "array" , "thing" ] | ||
}, | ||
}, | ||
}, | ||
} |