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.
support definition of multiple exec commands redhat-openstack#286
- Loading branch information
Showing
7 changed files
with
180 additions
and
37 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
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 |
---|---|---|
@@ -1,35 +1,44 @@ | ||
# See http://collectd.org/documentation/manpages/collectd.conf.5.shtml#plugin_exec | ||
define collectd::plugin::exec ( | ||
$user, | ||
$group, | ||
$exec = [], | ||
$notification_exec = [], | ||
$ensure = present, | ||
$order = '10', | ||
class collectd::plugin::exec ( | ||
$commands = {}, | ||
$interval = undef, | ||
$ensure = present, | ||
$globals = false, | ||
) { | ||
include collectd::params | ||
|
||
validate_array($exec) | ||
validate_array($notification_exec) | ||
validate_hash($commands) | ||
validate_bool($globals) | ||
|
||
$conf_dir = $collectd::params::plugin_conf_dir | ||
collectd::plugin {'exec': | ||
ensure => $ensure, | ||
globals => $globals, | ||
interval => $interval, | ||
} | ||
|
||
# should be loaded after global plugin configuration | ||
$exec_conf = "${collectd::params::plugin_conf_dir}/exec-config.conf" | ||
|
||
concat{ $exec_conf: | ||
ensure => $ensure, | ||
mode => '0640', | ||
owner => 'root', | ||
group => $collectd::params::root_group, | ||
notify => Service['collectd'], | ||
ensure_newline => true, | ||
} | ||
|
||
# This is deprecated file naming ensuring old style file removed, and should be removed in next major relese | ||
file { "${name}.load-deprecated": | ||
ensure => absent, | ||
path => "${conf_dir}/${name}.conf", | ||
concat::fragment{'collectd_plugin_exec_conf_header': | ||
order => '00', | ||
content => '<Plugin exec>', | ||
target => $exec_conf, | ||
} | ||
# End deprecation | ||
|
||
file { | ||
"${name}.load": | ||
ensure => $ensure, | ||
path => "${conf_dir}/${order}-${name}.conf", | ||
owner => 'root', | ||
group => $collectd::params::root_group, | ||
mode => '0644', | ||
content => template('collectd/exec.conf.erb'), | ||
notify => Service['collectd'], | ||
concat::fragment{'collectd_plugin_exec_conf_footer': | ||
order => '99', | ||
content => '</Plugin>', | ||
target => $exec_conf, | ||
} | ||
|
||
} | ||
create_resources(collectd::plugin::exec::cmd, $commands) | ||
} |
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,29 @@ | ||
define collectd::plugin::exec::cmd ( | ||
$user, | ||
$group, | ||
$exec = [], | ||
$notification_exec = [], | ||
$ensure = present, | ||
) { | ||
include collectd::params | ||
include collectd::plugin::exec | ||
|
||
validate_array($exec) | ||
validate_array($notification_exec) | ||
|
||
$conf_dir = $collectd::params::plugin_conf_dir | ||
|
||
# This is deprecated file naming ensuring old style file removed, and should be removed in next major relese | ||
file { "${name}.load-deprecated": | ||
ensure => absent, | ||
path => "${conf_dir}/${name}.conf", | ||
} | ||
# End deprecation | ||
|
||
concat::fragment{"collectd_plugin_exec_conf_${title}": | ||
ensure => $ensure, | ||
order => '50', # somewhere between header and footer | ||
target => $collectd::plugin::exec::exec_conf, | ||
content => template('collectd/plugin/exec/cmd.conf.erb'), | ||
} | ||
} |
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,78 @@ | ||
require 'spec_helper' | ||
|
||
describe 'collectd::plugin::exec', :type => :class do | ||
|
||
let :facts do | ||
{ | ||
:osfamily => 'Debian', | ||
:concat_basedir => tmpfilename('collectd-exec'), | ||
:id => 'root', | ||
:kernel => 'Linux', | ||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', | ||
:collectd_version => '5.0' | ||
} | ||
end | ||
|
||
context 'single command' do | ||
let :params do | ||
{ | ||
:commands => { 'hello' => | ||
{'user' => 'nobody', 'group' => 'users', 'exec' => ['/bin/echo', 'hello world']} | ||
}, | ||
} | ||
end | ||
|
||
it 'Will create /etc/collectd.d/conf.d/exec-config.conf' do | ||
should contain_concat__fragment('collectd_plugin_exec_conf_header').with({ | ||
:content => /<Plugin exec>/, | ||
:target => '/etc/collectd/conf.d/exec-config.conf', | ||
:order => '00' | ||
}) | ||
end | ||
|
||
it 'Will create /etc/collectd.d/conf.d/exec-config' do | ||
should contain_concat__fragment('collectd_plugin_exec_conf_footer').with({ | ||
:content => /<\/Plugin>/, | ||
:target => '/etc/collectd/conf.d/exec-config.conf', | ||
:order => '99' | ||
}) | ||
end | ||
|
||
it 'includes exec statement' do | ||
should contain_concat__fragment('collectd_plugin_exec_conf_hello').with({ | ||
:content => /Exec \"nobody:users\" \"\/bin\/echo\" \"hello world\"/, | ||
:target => '/etc/collectd/conf.d/exec-config.conf', | ||
}) | ||
end | ||
end | ||
|
||
context 'multiple commands' do | ||
let :params do | ||
{ | ||
:commands => { | ||
'hello' => { 'user' => 'nobody', 'group' => 'users', | ||
'exec' => ['/bin/echo', 'hello world'] | ||
}, | ||
'my_date' => { 'user' => 'nobody', 'group' => 'users', | ||
'exec' => ['/bin/date'] | ||
} | ||
}, | ||
} | ||
end | ||
|
||
it 'includes echo statement' do | ||
should contain_concat__fragment('collectd_plugin_exec_conf_hello').with({ | ||
:content => /Exec \"nobody:users\" \"\/bin\/echo\" \"hello world\"/, | ||
:target => '/etc/collectd/conf.d/exec-config.conf', | ||
}) | ||
end | ||
|
||
it 'includes date statement' do | ||
should contain_concat__fragment('collectd_plugin_exec_conf_my_date').with({ | ||
:content => /Exec \"nobody:users\" \"\/bin\/date\"/, | ||
:target => '/etc/collectd/conf.d/exec-config.conf', | ||
}) | ||
end | ||
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,31 @@ | ||
require 'spec_helper' | ||
|
||
describe 'collectd::plugin::exec::cmd', :type => :define do | ||
let :facts do | ||
{ | ||
:osfamily => 'Debian', | ||
:id => 'root', | ||
:concat_basedir => tmpfilename('collectd-exec'), | ||
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', | ||
} | ||
end | ||
|
||
context 'define a command' do | ||
let(:title) { 'whoami' } | ||
let :params do | ||
{ | ||
:user => 'www-data', | ||
:group => 'users', | ||
:exec => ['whoami', '--help'] | ||
} | ||
end | ||
|
||
it 'executes whoami command' do | ||
should contain_concat__fragment('collectd_plugin_exec_conf_whoami').with({ | ||
:content => /Exec/, | ||
:target => '/etc/collectd/conf.d/exec-config.conf', | ||
}) | ||
end | ||
end | ||
|
||
end |
This file was deleted.
Oops, something went wrong.
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,7 @@ | ||
<% if @exec %> | ||
Exec "<%= @user %>:<%= @group %>" "<%= @exec.join('" "') %>" | ||
<% end %> | ||
<% if !@notification_exec.empty? %> | ||
NotificationExec "<%= @user %>:<%= @group %>" <% @notification_exec.each do |exec| -%>"<%= exec %>"<% end -%> | ||
<% end %> | ||
|