Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH-701) Stop using scope.lookupvar() in templates #724

Merged
merged 1 commit into from
Jul 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion manifests/client/service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,29 @@
# Bolean. Value of hasrestart attribute for this service.
# Default: true
#
# [*log_level*]
# String. Sensu log level to be used
# Default: $::sensu::log_level
# Valid values: debug, info, warn, error, fatal
#
# [*windows_logrotate*]
# Boolean. Whether or not to use logrotate on Windows OS family.
# Default: $::sensu::windows_logrotate
#
# [*windows_log_size*]
# Integer. The integer value for the size of log files on Windows OS family. sizeThreshold in sensu-client.xml.
# Default: $::sensu::windows_log_size
#
# [*windows_log_number*]
# Integer. The integer value for the number of log files to keep on Windows OS family. keepFiles in sensu-client.xml.
# Default: $::sensu::windows_log_number
#
class sensu::client::service (
$hasrestart = true,
$hasrestart = true,
$log_level = $::sensu::log_level,
$windows_logrotate = $::sensu::windows_logrotate,
$windows_log_size = $::sensu::windows_log_size,
$windows_log_number = $::sensu::windows_log_number,
) {

validate_bool($hasrestart)
Expand Down
3 changes: 1 addition & 2 deletions manifests/extension.pp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@
$notify_services = []
}

$filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>')
$handler = "${install_path}/${filename}"
$handler = "${install_path}/${basename($source)}"

$file_ensure = $ensure ? {
'absent' => 'absent',
Expand Down
3 changes: 1 addition & 2 deletions manifests/handler.pp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@
}

if $source {
$filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>')
$handler = "${install_path}/${filename}"
$handler = "${install_path}/${basename($source)}"

ensure_resource('file', $handler, {
ensure => $file_ensure,
Expand Down
15 changes: 14 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@
#
# [*path*]
# String. Used to set PATH in /etc/default/sensu
# Default: '$PATH'
#
# [*redact*]
# Array of strings. Use to redact passwords from checks on the client side
Expand Down Expand Up @@ -389,6 +390,18 @@
# String. Used to set package_checksum for windows installs
# Default: undef
#
# [*windows_logrotate*]
# Boolean. Whether or not to use logrotate on Windows OS family.
# Default: false
#
# [*windows_log_size*]
# Integer. The integer value for the size of log files on Windows OS family. sizeThreshold in sensu-client.xml.
# Default: '10240'
#
# [*windows_log_number*]
# Integer. The integer value for the number of log files to keep on Windows OS family. keepFiles in sensu-client.xml.
# Default: '10'
#
# [*windows_pkg_url*]
# String. If specified, override the behavior of computing the package source
# URL from windows_repo_prefix and os major release fact. This parameter is
Expand Down Expand Up @@ -517,7 +530,7 @@
$enterprise_dashboard_github = undef,
$enterprise_dashboard_gitlab = undef,
$enterprise_dashboard_ldap = undef,
$path = undef,
$path = '$PATH',
$redact = undef,
$deregister_on_stop = false,
$deregister_handler = undef,
Expand Down
4 changes: 1 addition & 3 deletions manifests/mutator.pp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
}

if $source {

$filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>')
$mutator = "${install_path}/${filename}"
$mutator = "${install_path}/${basename($source)}"

$file_ensure = $ensure ? {
'absent' => 'absent',
Expand Down
65 changes: 62 additions & 3 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,71 @@
#
# Installs the Sensu packages
#
class sensu::package {
# == Parameters
#
# [*deregister_handler*]
# String. The handler to use when deregistering a client on stop.
# Default: $::sensu::deregister_handler
#
# [*deregister_on_stop*]
# Boolean. Whether the sensu client should deregister from the API on service stop
# Default: $::sensu::deregister_on_stop
#
# [*gem_path*]
# String. Paths to add to GEM_PATH if we need to look for different dirs.
# Default: $::sensu::gem_path
#
# [*init_stop_max_wait*]
# Integer. Number of seconds to wait for the init stop script to run
# Default: $::sensu::init_stop_max_wait
#
# [*log_dir*]
# String. Sensu log directory to be used
# Default: $::sensu::log_dir
# Valid values: Any valid log directory path, accessible by the sensu user
#
# [*log_level*]
# String. Sensu log level to be used
# Default: $::sensu::log_level
# Valid values: debug, info, warn, error, fatal
#
# [*path*]
# String. Used to set PATH in /etc/default/sensu
# Default: $::sensu::path
#
# [*rubyopt*]
# String. Ruby opts to be passed to the sensu services
# Default: $::sensu::rubyopt
#
# [*use_embedded_ruby*]
# Boolean. If the embedded ruby should be used, e.g. to install the
# sensu-plugin gem. This value is overridden by a defined
# sensu_plugin_provider. Note, the embedded ruby should always be used to
# provide full compatibility. Using other ruby runtimes, e.g. the system
# ruby, is not recommended.
# Default: $::sensu::use_embedded_ruby
# Valid values: true, false
#
class sensu::package (
$deregister_handler = $::sensu::deregister_handler,
$deregister_on_stop = $::sensu::deregister_on_stop,
$gem_path = $::sensu::gem_path,
$init_stop_max_wait = $::sensu::init_stop_max_wait,
$log_dir = $::sensu::log_dir,
$log_level = $::sensu::log_level,
$path = $::sensu::path,
$rubyopt = $::sensu::rubyopt,
$use_embedded_ruby = $::sensu::use_embedded_ruby,
) {

if $caller_module_name != $module_name {
fail("Use of private class ${name} by ${caller_module_name}")
}

if $path != '$PATH' {
validate_absolute_path($path)
}

case $::osfamily {

'Debian': {
Expand Down Expand Up @@ -49,7 +108,7 @@
# $pkg_version is passed to Package[sensu] { ensure }. The Windows MSI
# provider translates hyphens to dots, e.g. '0.29.0-11' maps to
# '0.29.0.11' on the system. This mapping is necessary to converge.
$pkg_version = template('sensu/sensu-windows-package-version.erb')
$pkg_version = regsubst($::sensu::version, '-', '.')
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same is true for sensu-version.erb. I have created the issue #731 to get it changed later on too.

# The version used to construct the download URL.
$pkg_url_version = $::sensu::version ? {
'installed' => 'latest',
Expand All @@ -69,7 +128,7 @@
# The OS Release specific sub-folder
$os_release = $facts['os']['release']['major']
# e.g. '2012 R2' => '2012r2'
$pkg_url_dir = template('sensu/sensu-version.erb')
$pkg_url_dir = regsubst($os_release, '^(\d+)\s*[rR](\d+)', '\\1r\\2')
Copy link
Collaborator Author

@Phil-Friderici Phil-Friderici Jul 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as for line 111 above ($pkg_version in package.pp)

$pkg_arch = $facts['os']['architecture']
$pkg_url = "${sensu::windows_repo_prefix}/${pkg_url_dir}/sensu-${pkg_url_version}-${pkg_arch}.msi"
}
Expand Down
4 changes: 2 additions & 2 deletions manifests/plugin.pp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

case $type {
'file': {
$filename = inline_template('<%= scope.lookupvar(\'name\').split(\'/\').last %>')
$filename = basename($name)

sensu::plugins_dir { "${name}-${install_path}":
path => $install_path,
Expand All @@ -86,7 +86,7 @@
}
}
'url': {
$filename = inline_template('<%= scope.lookupvar(\'name\').split(\'/\').last %>')
$filename = basename($name)

sensu::plugins_dir { "${name}-${install_path}":
path => $install_path,
Expand Down
Loading