diff --git a/README.md b/README.md index e19cb14eb..9fcc4e57b 100644 --- a/README.md +++ b/README.md @@ -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', diff --git a/manifests/plugin/genericjmx/mbean.pp b/manifests/plugin/genericjmx/mbean.pp index d600bcdf7..52297987a 100644 --- a/manifests/plugin/genericjmx/mbean.pp +++ b/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 diff --git a/spec/defines/collectd_plugin_genericjmx_mbean_spec.rb b/spec/defines/collectd_plugin_genericjmx_mbean_spec.rb index 0e4876541..308e1286a 100644 --- a/spec/defines/collectd_plugin_genericjmx_mbean_spec.rb +++ b/spec/defines/collectd_plugin_genericjmx_mbean_spec.rb @@ -41,7 +41,7 @@ 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 @@ -49,9 +49,9 @@ 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"}) } @@ -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 @@ -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"}) } diff --git a/templates/plugin/genericjmx/mbean.conf.erb b/templates/plugin/genericjmx/mbean.conf.erb index 976b8318f..4336ffa58 100644 --- a/templates/plugin/genericjmx/mbean.conf.erb +++ b/templates/plugin/genericjmx/mbean.conf.erb @@ -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| -%> @@ -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 -%>