Skip to content

Commit

Permalink
Merge pull request #207 from Mylezeem/allow_url_plugins
Browse files Browse the repository at this point in the history
plugin: Allow to retrieve plugin from URL
  • Loading branch information
jamtur01 committed Aug 8, 2014
2 parents 56398bb + d9765e6 commit 0f547b1
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ fixtures:
repositories:
apt: git://github.com/puppetlabs/puppetlabs-apt.git
stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git
wget: git://github.com/maestrodev/puppet-wget.git
symlinks:
sensu: "#{source_dir}"

1 change: 1 addition & 0 deletions Modulefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ license 'MIT'
summary 'A module to intall the Sensu monitoring framework'
project_page 'https://github.com/sensu/sensu-puppet'

dependency 'maestrodev/wget', '>= 1.4.5'
dependency 'puppetlabs/apt', '>= 0.0.1'
dependency 'puppetlabs/stdlib', '>= 0.0.1'

17 changes: 16 additions & 1 deletion manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# [*type*]
# String. Plugin source
# Default: file
# Valid values: file, directory, package
# Valid values: file, directory, package, url
#
# [*install_path*]
# String. The path to install the plugin
Expand Down Expand Up @@ -44,6 +44,7 @@

validate_bool($purge, $recurse, $force)
validate_re($pkg_version, ['^absent$', '^installed$', '^latest$', '^present$', '^[\d\.\-]+$'], "Invalid package version: ${pkg_version}")
validate_re($type, ['^file$', '^url$', '^package$', '^directory$'], "Invalid plugin type: ${type}")

case $type {
'file': {
Expand All @@ -55,6 +56,20 @@
source => $name,
}
}
'url' : {
$filename = inline_template('<%= scope.lookupvar(\'name\').split(\'/\').last %>')

wget::fetch { $name :
destination => "${install_path}/${filename}",
timeout => 0,
verbose => false,
require => File[$install_path],
} ->
file { "${install_path}/${filename}":
ensure => file,
mode => '0555',
}
}
'directory': {
file { $install_path:
ensure => directory,
Expand Down
32 changes: 32 additions & 0 deletions spec/defines/sensu_plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,38 @@
end
end #file

context 'url' do
let(:title) { 'https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh' }

context 'defaults' do
let(:params) { {
:type => 'url',
} }

it { should contain_wget__fetch('https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh').with(
'destination' => '/etc/sensu/plugins/check-mem.sh',
'verbose' => 'false',
'timeout' => '0'
) }

end

context 'setting params' do
let(:params) { {
:type => 'url',
:install_path => '/var/sensu/plugins'
} }

it { should contain_wget__fetch('https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/plugins/system/check-mem.sh').with(
'destination' => '/var/sensu/plugins/check-mem.sh',
'verbose' => 'false',
'timeout' => '0'
) }

end

end #url

context 'directory' do
let(:title) { 'puppet:///data/sensu/plugins' }

Expand Down

0 comments on commit 0f547b1

Please sign in to comment.