Skip to content

Commit

Permalink
Convert prometheus::mongodb_exporter to use native Puppet 4 data type…
Browse files Browse the repository at this point in the history
…s and add requested test
  • Loading branch information
salekseev committed Oct 12, 2017
1 parent 86f298c commit 3f1b6ce
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
53 changes: 25 additions & 28 deletions manifests/mongodb_exporter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,36 +72,33 @@
# [*version*]
# The binary release version
class prometheus::mongodb_exporter (
$arch = $::prometheus::params::arch,
$bin_dir = $::prometheus::params::bin_dir,
$cnf_uri = $::prometheus::params::mongodb_exporter_cnf_uri,
$download_extension = $::prometheus::params::mongodb_exporter_download_extension,
$download_url = undef,
$download_url_base = $::prometheus::params::mongodb_exporter_download_url_base,
$extra_groups = $::prometheus::params::mongodb_exporter_extra_groups,
$extra_options = '',
$group = $::prometheus::params::mongodb_exporter_group,
$init_style = $::prometheus::params::init_style,
$install_method = $::prometheus::params::install_method,
$manage_group = true,
$manage_service = true,
$manage_user = true,
$os = $::prometheus::params::os,
$package_ensure = $::prometheus::params::mongodb_exporter_package_ensure,
$package_name = $::prometheus::params::mongodb_exporter_package_name,
$purge_config_dir = true,
$restart_on_change = true,
$service_enable = true,
$service_ensure = 'running',
$user = $::prometheus::params::mongodb_exporter_user,
$version = $::prometheus::params::mongodb_exporter_version,
String $arch = $::prometheus::params::arch,
String $bin_dir = $::prometheus::params::bin_dir,
String $cnf_uri = $::prometheus::params::mongodb_exporter_cnf_uri,
String $download_extension = $::prometheus::params::mongodb_exporter_download_extension,
Variant[Undef,String] $download_url = undef,
String $download_url_base = $::prometheus::params::mongodb_exporter_download_url_base,
Array $extra_groups = $::prometheus::params::mongodb_exporter_extra_groups,
String $extra_options = '',
String $group = $::prometheus::params::mongodb_exporter_group,
String $init_style = $::prometheus::params::init_style,
String $install_method = $::prometheus::params::install_method,
Boolean $manage_group = true,
Boolean $manage_service = true,
Boolean $manage_user = true,
String $os = $::prometheus::params::os,
String $package_ensure = $::prometheus::params::mongodb_exporter_package_ensure,
String $package_name = $::prometheus::params::mongodb_exporter_package_name,
Boolean $purge_config_dir = true,
Boolean $restart_on_change = true,
Boolean $service_enable = true,
String $service_ensure = 'running',
String $user = $::prometheus::params::mongodb_exporter_user,
String $version = $::prometheus::params::mongodb_exporter_version,
) inherits prometheus::params {
#Please provide the download_url for versions < 0.9.0
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")
validate_bool($purge_config_dir)
validate_bool($manage_user)
validate_bool($manage_service)
validate_bool($restart_on_change)
$real_download_url = pick($download_url,"${download_url_base}/download/v${version}/${package_name}-${version}.${os}-${arch}.${download_extension}")

$notify_service = $restart_on_change ? {
true => Service['mongodb_exporter'],
default => undef,
Expand Down
2 changes: 1 addition & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
$mongodb_exporter_package_ensure = 'latest'
$mongodb_exporter_package_name = 'mongodb_exporter'
$mongodb_exporter_user = 'mongodb-exporter'
$mongodb_exporter_version = '0.3.0'
$mongodb_exporter_version = '0.3.1'
$node_exporter_collectors = ['diskstats','filesystem','loadavg','meminfo','netdev','stat','time']
$node_exporter_download_extension = 'tar.gz'
$node_exporter_download_url_base = 'https://github.com/prometheus/node_exporter/releases'
Expand Down
4 changes: 4 additions & 0 deletions spec/classes/mongodb_exporter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
}
end

describe 'compile manifest' do
it { is_expected.to compile.with_all_deps }
end

describe 'install correct binary' do
it { is_expected.to contain_file('/usr/local/bin/mongodb_exporter').with('target' => '/opt/mongodb_exporter-0.3.0.linux-amd64/mongodb_exporter') }
end
Expand Down

0 comments on commit 3f1b6ce

Please sign in to comment.