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.
- Loading branch information
Showing
4 changed files
with
142 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# https://collectd.org/wiki/index.php/Plugin:GenericJMX | ||
class collectd::plugin::genericjmx ( | ||
$ensure = present, | ||
$jvmarg = [], | ||
) { | ||
include collectd | ||
include collectd::params | ||
include collectd::plugin::java | ||
|
||
$config_file = "${collectd::params::plugin_conf_dir}/15-genericjmx.conf" | ||
|
||
concat { $config_file: | ||
ensure => $ensure, | ||
mode => '0640', | ||
owner => 'root', | ||
group => $collectd::params::root_group, | ||
notify => Service['collectd'], | ||
ensure_newline => true, | ||
} | ||
concat::fragment { | ||
'collectd_plugin_genericjmx_conf_header': | ||
order => '00', | ||
content => template('collectd/plugin/genericjmx.conf.header.erb'), | ||
target => $config_file; | ||
'collectd_plugin_genericjmx_conf_footer': | ||
order => '99', | ||
content => " </Plugin>\n</Plugin>\n", | ||
target => $config_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,79 @@ | ||
require 'spec_helper' | ||
|
||
describe 'collectd::plugin::genericjmx', :type => :class do | ||
let (:facts) {{ | ||
:osfamily => 'RedHat', | ||
:concat_basedir => tmpfilename('collectd-genericjmx'), | ||
}} | ||
|
||
let (:config_filename) { '/etc/collectd.d/15-genericjmx.conf' } | ||
|
||
context ':ensure => present, defaults' do | ||
it 'will include the java plugin' do | ||
should contain_class('collectd::plugin::java') | ||
end | ||
|
||
it 'will load the genericjmx plugin' do | ||
should contain_concat(config_filename).with({ | ||
:ensure => 'present', | ||
:mode => '0640', | ||
:owner => 'root', | ||
:group => 'root', | ||
:ensure_newline => true | ||
}) | ||
end | ||
|
||
it { should contain_concat(config_filename).that_notifies('Service[collectd]') } | ||
|
||
it do | ||
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').with({ | ||
:order => '00', | ||
:target => config_filename, | ||
:content => /<Plugin "java">\s+LoadPlugin "org\.collectd\.java\.GenericJMX"\s+<Plugin "GenericJMX">/s | ||
}) | ||
end | ||
|
||
it do | ||
should contain_concat__fragment('collectd_plugin_genericjmx_conf_footer').with({ | ||
:order => '99', | ||
:target => config_filename, | ||
:content => %r{</Plugin>\s+</Plugin>}s, | ||
}) | ||
end | ||
|
||
end | ||
|
||
context ':ensure => absent' do | ||
let (:params) {{ :ensure => 'absent' }} | ||
it 'should not load the plugin' do | ||
should contain_concat(config_filename).with({ | ||
:ensure => 'absent', | ||
}) | ||
end | ||
end | ||
|
||
context 'jvmarg parameter array' do | ||
let (:params) {{ :jvmarg => %w{ foo bar baz } }} | ||
it 'should have multiple jvmarg parameters' do | ||
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').with_content(/JVMArg "foo"\s*JVMArg "bar"\s*JVMArg "baz"/s) | ||
end | ||
end | ||
|
||
context 'jvmarg parameter string' do | ||
let (:params) {{ :jvmarg => "bat" }} | ||
it 'should have one jvmarg parameter' do | ||
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').with_content(/JVMArg "bat"/) | ||
end | ||
it 'should have ONLY one jvmarg parameter' do | ||
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').without_content(/(.*JVMArg.*){2,}/s) | ||
end | ||
end | ||
|
||
context 'jvmarg parameter empty' do | ||
let (:params) {{ :jvmarg => [] }} | ||
it 'should not have any jvmarg parameters' do | ||
should contain_concat__fragment('collectd_plugin_genericjmx_conf_header').without_content(/JVMArg/) | ||
end | ||
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,7 @@ | ||
<Plugin "java"> | ||
<% Array(@jvmarg).each do |jvmarg| -%> | ||
JVMArg "<%= jvmarg %>" | ||
<% end -%> | ||
|
||
LoadPlugin "org.collectd.java.GenericJMX" | ||
<Plugin "GenericJMX"> |
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,25 @@ | ||
<MBean "<%= @name %>"> | ||
ObjectName "<%= @object_name %>" | ||
<% if @instance_prefix -%> | ||
InstancePrefix "<%= @instance_prefix %>" | ||
<% end -%> | ||
<% if @instance_from -%> | ||
<% Array(@instance_from).each do |instance_from_item| -%> | ||
InstanceFrom "<%= instance_from_item %>" | ||
<% end -%> | ||
<% end -%> | ||
|
||
<% @values.each do |value| -%> | ||
<Value> | ||
Type "<%= value['type'] %>" | ||
<% if value['instance_prefix'] -%> | ||
InstancePrefix "<%= value['instance_prefix'] %>" | ||
<% end -%> | ||
<% if value['instance_from'] -%> | ||
<% Array(value['instance_from']).each do |instance_from_item| -%> | ||
InstanceFrom "<%= instance_from_item %>" | ||
<% end -%> | ||
<% end -%> | ||
</Value> | ||
<% end -%> | ||
</MBean> |