Skip to content

Commit

Permalink
java plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kitchen committed Jan 15, 2015
1 parent 1990227 commit 8031829
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
12 changes: 12 additions & 0 deletions manifests/plugin/java.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# https://collectd.org/wiki/index.php/Plugin:Java
class collectd::plugin::java (
$ensure = present,
$jvmarg = [],
$interval = undef,
) {
collectd::plugin { 'java':
ensure => $ensure,
content => template('collectd/plugin/java.conf.erb'),
interval => $interval,
}
}
57 changes: 57 additions & 0 deletions spec/classes/collectd_plugin_java_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'spec_helper'

describe 'collectd::plugin::java', :type => :class do
let :facts do
{:osfamily => 'RedHat'}
end

context ':ensure => present, defaults' do
it 'Will load the plugin' do
should contain_file('java.load').with({
:ensure => 'present',
:path => '/etc/collectd.d/10-java.conf',
})

should contain_file('java.load').with_content(/<Plugin java>/)
should contain_file('java.load').without_content(/JVMArg/)
end
end

context ':ensure => absent' do
let (:params) {{
:ensure => 'absent',
}}

it 'will not load the plugin' do
should contain_file('java.load').with({
:ensure => 'absent',
:path => '/etc/collectd.d/10-java.conf',
})
end
end

context 'jvmarg parameter array' do
let (:params) {{
:jvmarg => %w{ foo bar baz }
}}

it 'will have multiple JVMArg bits' do
should contain_file('java.load').with_content(/JVMArg "foo"[\s\n]+JVMArg "bar"[\s\n]+JVMArg "baz"/)
end
end

context 'jvmarg parameter string' do
let (:params) {{
:jvmarg => 'bat'
}}

it 'will have a JVMArg bit' do
should contain_file('java.load').with_content(/JVMArg "bat"/)
end

it 'will only have one JVMArg bit' do
should contain_file('java.load').without_content(/(.*JVMArg.*){2,}/)
end
end
end

7 changes: 7 additions & 0 deletions templates/plugin/java.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Plugin java>
<% if @jvmarg -%>
<% Array(@jvmarg).each do |arg| -%>
JVMArg "<%= arg %>"
<% end -%>
<% end -%>
</Plugin>

0 comments on commit 8031829

Please sign in to comment.