Skip to content

Commit

Permalink
genericjmx connection stanza
Browse files Browse the repository at this point in the history
  • Loading branch information
kitchen committed Jan 19, 2015
1 parent 6737a8d commit f68c147
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 0 deletions.
16 changes: 16 additions & 0 deletions manifests/plugin/genericjmx/connection.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# https://collectd.org/wiki/index.php/Plugin:GenericJMX
define collectd::plugin::genericjmx::connection (
$host = $name,
$service_url,
$user = undef,
$password = undef,
$instance_prefix = undef,
$collect,
) {
include collectd::plugin::genericjmx
concat::fragment { "collectd_plugin_genericjmx_conf_${name}":
order => 20,
content => template('collectd/plugin/genericjmx/connection.conf.erb'),
target => $collectd::plugin::genericjmx::config_file;
}
}
103 changes: 103 additions & 0 deletions spec/defines/collectd_plugin_genericjmx_connection_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
require 'spec_helper'
describe 'collectd::plugin::genericjmx::connection', :type => :define do

let (:facts) {{
:osfamily => 'Debian',
:concat_basedir => tmpfilename('collectd-genericjmx-connection'),
}}

let (:config_filename) { '/etc/collectd/conf.d/15-genericjmx.conf' }

let (:default_params) {{
:service_url => 'foo:bar:baz',
}}

let (:title) { 'foo.example.com' }
let (:concat_fragment_name) { 'collectd_plugin_genericjmx_conf_foo.example.com' }

context 'required params' do
let (:params) {
default_params.merge({
:collect => [],
})
}

it 'provides a Connection concat fragment' do
should contain_concat__fragment(concat_fragment_name).with({
:target => config_filename,
:order => '20',
})
end

it { should contain_concat__fragment(concat_fragment_name).with_content(%r{<Connection>.*</Connection>}m) }
it { should contain_concat__fragment(concat_fragment_name).with_content(/Host "foo\.example\.com"/) }
it { should contain_concat__fragment(concat_fragment_name).with_content(/ServiceURL "foo:bar:baz"/) }
it { should contain_concat__fragment(concat_fragment_name).without_content(/User/) }
it { should contain_concat__fragment(concat_fragment_name).without_content(/Password/) }
it { should contain_concat__fragment(concat_fragment_name).without_content(/InstancePrefix/) }
end

context 'hostname override' do
let (:params) {
default_params.merge({
:host => 'bar.example.com',
:collect => [],
})
}

it 'provides a Connection concat fragment' do
should contain_concat__fragment(concat_fragment_name).with({
:target => config_filename,
:order => '20',
})
end

it { should contain_concat__fragment(concat_fragment_name).with_content(/Host "bar\.example\.com"/) }
end

context 'collect array' do
let (:params) {
default_params.merge({
:collect => %w{ foo bar baz }
})
}

it { should contain_concat__fragment(concat_fragment_name).with_content(/Collect "foo".*Collect "bar".*Collect "baz"/m) }
end

context 'collect string' do
let (:params) {
default_params.merge({
:collect => 'bat'
})
}

it { should contain_concat__fragment(concat_fragment_name).with_content(/Collect "bat"/) }
it { should contain_concat__fragment(concat_fragment_name).without_content(/(.*Collect.*){2,}/m) }
end

context 'username and password' do
let (:params) {
default_params.merge({
:user => 'alice',
:password => 'aoeuhtns',
:collect => [],
})
}

it { should contain_concat__fragment(concat_fragment_name).with_content(/User "alice"/) }
it { should contain_concat__fragment(concat_fragment_name).with_content(/Password "aoeuhtns"/) }
end

context 'instance_prefix 'do
let (:params) {
default_params.merge({
:instance_prefix => 'bat',
:collect => [],
})
}

it { should contain_concat__fragment(concat_fragment_name).with_content(/InstancePrefix "bat"/) }
end

end
16 changes: 16 additions & 0 deletions templates/plugin/genericjmx/connection.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Connection>
Host "<%= @host %>"
ServiceURL "<%= @service_url %>"
<% Array(@collect).each do |collect| -%>
Collect "<%= collect %>"
<% end -%>
<% if @user -%>
User "<%= @user %>"
<% end -%>
<% if @password -%>
Password "<%= @password %>"
<% end -%>
<% if @instance_prefix -%>
InstancePrefix "<%= @instance_prefix %>"
<% end -%>
</Connection>

0 comments on commit f68c147

Please sign in to comment.