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
3 changed files
with
135 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,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
103
spec/defines/collectd_plugin_genericjmx_connection_spec.rb
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,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 |
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,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> |