Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plugin::genericjmx::mbean - Use data types #726

Merged
merged 1 commit into from Nov 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -817,7 +817,7 @@ collectd::plugin::genericjmx::mbean {
'garbage_collector':
object_name => 'java.lang:type=GarbageCollector,*',
instance_prefix => 'gc-',
instance_from => 'name',
instance_from => ['name'],
values => [
{
mbean_type => 'invocations',
Expand Down
6 changes: 3 additions & 3 deletions manifests/plugin/genericjmx/mbean.pp
@@ -1,9 +1,9 @@
# https://collectd.org/wiki/index.php/Plugin:GenericJMX
define collectd::plugin::genericjmx::mbean (
$object_name,
String $object_name,
Array $values,
$instance_prefix = undef,
$instance_from = undef,
Optional[String] $instance_prefix = undef,
Array $instance_from = [],
) {

include ::collectd
Expand Down
12 changes: 6 additions & 6 deletions spec/defines/collectd_plugin_genericjmx_mbean_spec.rb
Expand Up @@ -41,17 +41,17 @@
it { is_expected.to contain_concat__fragment(concat_fragment_name).with_content(%r{InstancePrefix "baz"}) }
end

context 'instance_from array' do
context 'with an instance_from array of multiple values' do
let(:params) do
default_params.merge(instance_from: %w[foo bar baz])
end

it { is_expected.to contain_concat__fragment(concat_fragment_name).with_content(%r{InstanceFrom "foo"\s+InstanceFrom "bar"\s+InstanceFrom "baz"}) }
end

context 'instance_from string' do
context 'with an instance_from array of one value' do
let(:params) do
default_params.merge(instance_from: 'bat')
default_params.merge(instance_from: %w[bat])
end

it { is_expected.to contain_concat__fragment(concat_fragment_name).with_content(%r{InstanceFrom "bat"}) }
Expand Down Expand Up @@ -95,7 +95,7 @@
it { is_expected.to contain_concat__fragment(concat_fragment_name).without_content(%r{InstanceFrom}) }
end

context 'value section instance_from array' do
context 'value section instance_from array, multiple values' do
let(:params) do
default_params.merge(values: [default_values_args.merge('instance_from' => %w[alice bob carol])])
end
Expand All @@ -106,9 +106,9 @@
it { is_expected.to contain_concat__fragment(concat_fragment_name).without_content(%r{InstancePrefix}) }
end

context 'value section instance_from string' do
context 'value section instance_from array, single value' do
let(:params) do
default_params.merge(values: [default_values_args.merge('instance_from' => 'dave')])
default_params.merge(values: [default_values_args.merge('instance_from' => %w[dave])])
end

it { is_expected.to contain_concat__fragment(concat_fragment_name).with_content(%r{InstanceFrom "dave"}) }
Expand Down
6 changes: 2 additions & 4 deletions templates/plugin/genericjmx/mbean.conf.erb
Expand Up @@ -3,10 +3,8 @@
<% if @instance_prefix -%>
InstancePrefix "<%= @instance_prefix %>"
<% end -%>
<% if @instance_from -%>
<% Array(@instance_from).each do |instance_from_item| -%>
<% @instance_from.each do |instance_from_item| -%>
InstanceFrom "<%= instance_from_item %>"
<% end -%>
<% end -%>

<% @values.each do |value| -%>
Expand All @@ -16,7 +14,7 @@
InstancePrefix "<%= value['instance_prefix'] %>"
<% end -%>
<% if value['instance_from'] -%>
<% Array(value['instance_from']).each do |instance_from_item| -%>
<% value['instance_from'].each do |instance_from_item| -%>
InstanceFrom "<%= instance_from_item %>"
<% end -%>
<% end -%>
Expand Down