diff --git a/manifests/plugin/genericjmx/connection.pp b/manifests/plugin/genericjmx/connection.pp
index e69de29bb..23d475acb 100644
--- a/manifests/plugin/genericjmx/connection.pp
+++ b/manifests/plugin/genericjmx/connection.pp
@@ -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;
+ }
+}
diff --git a/spec/defines/collectd_plugin_genericjmx_connection_spec.rb b/spec/defines/collectd_plugin_genericjmx_connection_spec.rb
new file mode 100644
index 000000000..f93427de8
--- /dev/null
+++ b/spec/defines/collectd_plugin_genericjmx_connection_spec.rb
@@ -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{.*}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
diff --git a/templates/plugin/genericjmx/connection.conf.erb b/templates/plugin/genericjmx/connection.conf.erb
new file mode 100644
index 000000000..ea32ce9df
--- /dev/null
+++ b/templates/plugin/genericjmx/connection.conf.erb
@@ -0,0 +1,16 @@
+
+ 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 -%>
+