Skip to content

Commit

Permalink
Remove anchor pattern sensu#709
Browse files Browse the repository at this point in the history
Removed anchors and create_resources

Syntax fix

Added forgotten defaults var in init.pp resource hashes

Fixed order in hash merging

Remove check for private classes usage

sensu::enterpise::dashboard class consolidation sensu#709

Removed subclasses incorporated in sensu::enterprise::dashboard

Fixed sensu::check notify tests

Removed manifests readded by merge

Workaround for Puppet 4.x compatibilty
  - Evaluation Error: Error while evaluating a Resource Statement, Sensu::Write_json[/etc/sensu/conf.d/checks/mycheck.json]: parameter 'notify_list' index 0 expects a Data value, got Type at /home/travis/build/sensu/sensu-puppet/spec/fixtures/modules/sensu/manifests/check.pp:226 on node testing-docker-0c136c1e-7d4c-4d32-9c4c-37325d83735a.ec2.internal
  • Loading branch information
alvagante committed Aug 21, 2017
1 parent da1571b commit 46f109e
Show file tree
Hide file tree
Showing 29 changed files with 318 additions and 414 deletions.
68 changes: 68 additions & 0 deletions manifests/api.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# = Class: sensu::api
#
# Manages the Sensu api
#
# == Parameters
#
# [*hasrestart*]
# Boolean. Value of hasrestart attribute for this service.
# Default: true
#
class sensu::api (
Boolean $hasrestart = $::sensu::hasrestart,
) {

if $::sensu::manage_services {

case $::sensu::api {
true: {
$service_ensure = 'running'
$service_enable = true
}
default: {
$service_ensure = 'stopped'
$service_enable = false
}
}

if $::osfamily != 'windows' {
service { 'sensu-api':
ensure => $service_ensure,
enable => $service_enable,
hasrestart => $hasrestart,
subscribe => [
Class['sensu::package'],
Sensu_api_config[$::fqdn],
Class['sensu::redis::config'],
Class['sensu::rabbitmq::config'],
],
}
}
}

if $::sensu::_purge_config and !$::sensu::server and !$::sensu::api and !$::sensu::enterprise {
$file_ensure = 'absent'
} else {
$file_ensure = 'present'
}

file { "${sensu::etc_dir}/conf.d/api.json":
ensure => $file_ensure,
owner => $::sensu::user,
group => $::sensu::group,
mode => $::sensu::file_mode,
}

sensu_api_config { $::fqdn:
ensure => $file_ensure,
base_path => "${sensu::etc_dir}/conf.d",
bind => $::sensu::api_bind,
host => $::sensu::api_host,
port => $::sensu::api_port,
user => $::sensu::api_user,
password => $::sensu::api_password,
ssl_port => $::sensu::api_ssl_port,
ssl_keystore_file => $::sensu::api_ssl_keystore_file,
ssl_keystore_password => $::sensu::api_ssl_keystore_password,
}
}
36 changes: 0 additions & 36 deletions manifests/api/config.pp

This file was deleted.

42 changes: 0 additions & 42 deletions manifests/api/service.pp

This file was deleted.

17 changes: 1 addition & 16 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -223,27 +223,12 @@
# on top of any arbitrary plugin and extension configuration in $content.
$content_real = $content + $checks_scope

# Compute the services to notify
$notification_map = {
'Class[Sensu::Client::Service]' => $::sensu::client,
'Class[Sensu::Server::Service]' => $::sensu::server,
'Class[Sensu::Api::Service]' => $::sensu::api,
}

$notification_ary = $notification_map.reduce([]) |$memo, $kv| {
if $kv[1] {
$memo + [$kv[0]]
} else {
$memo
}
}

sensu::write_json { "${conf_dir}/checks/${check_name}.json":
ensure => $ensure,
content => $content_real,
owner => $user,
group => $group,
mode => $file_mode,
notify_list => $notification_ary,
notify_list => $::sensu::check_notify,
}
}
57 changes: 44 additions & 13 deletions manifests/client/service.pp → manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,25 @@
#
# @param windows_log_number The integer value for the number of log files to keep on Windows OS family. keepFiles in sensu-client.xml.
#
class sensu::client::service (
Boolean $hasrestart = true,
class sensu::client (
Boolean $hasrestart = $::sensu::hasrestart,
$log_level = $::sensu::log_level,
$windows_logrotate = $::sensu::windows_logrotate,
$windows_log_size = $::sensu::windows_log_size,
$windows_log_number = $::sensu::windows_log_number,
) {

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

# Service
if $::sensu::manage_services {

case $::sensu::client {
true: {
$ensure = 'running'
$enable = true
$service_ensure = 'running'
$service_enable = true
}
default: {
$ensure = 'stopped'
$enable = false
$service_ensure = 'stopped'
$service_enable = false
}
}

Expand All @@ -53,14 +50,48 @@
}

service { 'sensu-client':
ensure => $ensure,
enable => $enable,
ensure => $service_ensure,
enable => $service_enable,
hasrestart => $hasrestart,
subscribe => [
Class['sensu::package'],
Class['sensu::client::config'],
Sensu_client_config[$::fqdn],
Class['sensu::rabbitmq::config'],
],
}
}

# Config
if $::sensu::_purge_config and !$::sensu::client {
$file_ensure = 'absent'
} else {
$file_ensure = 'present'
}

file { "${sensu::conf_dir}/client.json":
ensure => $file_ensure,
owner => $::sensu::user,
group => $::sensu::group,
mode => $::sensu::file_mode,
}

$socket_config = {
bind => $::sensu::client_bind,
port => $::sensu::client_port,
}

sensu_client_config { $::fqdn:
ensure => $file_ensure,
base_path => $::sensu::conf_dir,
client_name => $::sensu::client_name,
address => $::sensu::client_address,
socket => $socket_config,
subscriptions => $::sensu::subscriptions,
safe_mode => $::sensu::safe_mode,
custom => $::sensu::client_custom,
keepalive => $::sensu::client_keepalive,
redact => $::sensu::redact,
deregister => $::sensu::client_deregister,
deregistration => $::sensu::client_deregistration,
}
}
43 changes: 0 additions & 43 deletions manifests/client/config.pp

This file was deleted.

2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
ensure => $ensure,
config => $config,
event => $event,
notify => Class['sensu::client::service'],
notify => $::sensu::client_service,
}

}
39 changes: 33 additions & 6 deletions manifests/enterprise/package.pp → manifests/enterprise.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @summary Installs the Sensu packages
#
# Installs the Sensu packages
# Installs Sensu enterprise
#
# @param deregister_handler The handler to use when deregistering a client on stop.
#
Expand Down Expand Up @@ -28,7 +28,7 @@
#
# @param heap_size Value of the HEAP_SIZE environment variable.
#
class sensu::enterprise::package (
class sensu::enterprise (
Optional[String] $deregister_handler = $::sensu::deregister_handler,
Optional[Boolean] $deregister_on_stop = $::sensu::deregister_on_stop,
Optional[String] $gem_path = $::sensu::gem_path,
Expand All @@ -39,12 +39,10 @@
Optional[String] $rubyopt = $::sensu::rubyopt,
Optional[Boolean] $use_embedded_ruby = $::sensu::use_embedded_ruby,
Variant[Undef,Integer,Pattern[/^(\d+)/]] $heap_size = $::sensu::heap_size,
Boolean $hasrestart = $::sensu::hasrestart,
){

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

# Package
if $::sensu::enterprise {

package { 'sensu-enterprise':
Expand All @@ -60,4 +58,33 @@
require => Package['sensu-enterprise'],
}
}

# Service
if $::sensu::manage_services and $::sensu::enterprise {

case $::sensu::enterprise {
true: {
$ensure = 'running'
$enable = true
}
default: {
$ensure = 'stopped'
$enable = false
}
}

if $::osfamily != 'windows' {
service { 'sensu-enterprise':
ensure => $ensure,
enable => $enable,
hasrestart => $hasrestart,
subscribe => [
File['/etc/default/sensu-enterprise'],
Sensu_api_config[$::fqdn],
Class['sensu::redis::config'],
Class['sensu::rabbitmq::config'],
],
}
}
}
}
Loading

0 comments on commit 46f109e

Please sign in to comment.