From 46f109e441f9dd00d18ac67f292af1bb89958035 Mon Sep 17 00:00:00 2001 From: Alessandro Franceschi Date: Thu, 20 Jul 2017 19:25:28 +0200 Subject: [PATCH] Remove anchor pattern #709 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 #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 --- manifests/api.pp | 68 ++++++++++++++ manifests/api/config.pp | 36 -------- manifests/api/service.pp | 42 --------- manifests/check.pp | 17 +--- manifests/{client/service.pp => client.pp} | 57 +++++++++--- manifests/client/config.pp | 43 --------- manifests/config.pp | 2 +- .../{enterprise/package.pp => enterprise.pp} | 39 ++++++-- manifests/enterprise/dashboard.pp | 91 +++++++++++++++++-- manifests/enterprise/dashboard/api.pp | 2 +- manifests/enterprise/dashboard/config.pp | 53 ----------- manifests/enterprise/dashboard/package.pp | 16 ---- manifests/enterprise/dashboard/service.pp | 39 -------- manifests/enterprise/service.pp | 42 --------- manifests/extension.pp | 4 +- manifests/init.pp | 87 ++++++++++-------- manifests/package.pp | 12 +-- manifests/rabbitmq/config.pp | 4 - manifests/redis/config.pp | 4 - manifests/repo/apt.pp | 4 - manifests/repo/yum.pp | 4 - manifests/server/service.pp | 8 +- manifests/subscription.pp | 2 +- manifests/transport.pp | 4 - manifests/write_json.pp | 2 +- spec/classes/sensu_init_spec.rb | 24 ++--- spec/classes/sensu_service_spec.rb | 8 +- spec/defines/sensu_check_spec.rb | 16 ++-- spec/defines/sensu_subscription_spec.rb | 2 +- 29 files changed, 318 insertions(+), 414 deletions(-) create mode 100644 manifests/api.pp delete mode 100644 manifests/api/config.pp delete mode 100644 manifests/api/service.pp rename manifests/{client/service.pp => client.pp} (56%) delete mode 100644 manifests/client/config.pp rename manifests/{enterprise/package.pp => enterprise.pp} (74%) delete mode 100644 manifests/enterprise/dashboard/config.pp delete mode 100644 manifests/enterprise/dashboard/package.pp delete mode 100644 manifests/enterprise/dashboard/service.pp delete mode 100644 manifests/enterprise/service.pp diff --git a/manifests/api.pp b/manifests/api.pp new file mode 100644 index 0000000000..a5c92f51b3 --- /dev/null +++ b/manifests/api.pp @@ -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, + } +} diff --git a/manifests/api/config.pp b/manifests/api/config.pp deleted file mode 100644 index ab714812c2..0000000000 --- a/manifests/api/config.pp +++ /dev/null @@ -1,36 +0,0 @@ -# @summary Sets the Sensu API config -# -# Sets the Sensu API config -# -class sensu::api::config { - - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - - if $::sensu::_purge_config and !$::sensu::server and !$::sensu::api and !$::sensu::enterprise { - $ensure = 'absent' - } else { - $ensure = 'present' - } - - file { "${sensu::etc_dir}/conf.d/api.json": - ensure => $ensure, - owner => $::sensu::user, - group => $::sensu::group, - mode => $::sensu::file_mode, - } - - sensu_api_config { $::fqdn: - ensure => $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, - } -} diff --git a/manifests/api/service.pp b/manifests/api/service.pp deleted file mode 100644 index 9eecac22dc..0000000000 --- a/manifests/api/service.pp +++ /dev/null @@ -1,42 +0,0 @@ -# @summary Manages the Sensu api service -# -# Manages the Sensu api service -# -# @param hasrestart Value of hasrestart attribute for this service. -# -class sensu::api::service ( - Boolean $hasrestart = true, -) { - - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - - if $::sensu::manage_services { - - case $::sensu::api { - true: { - $ensure = 'running' - $enable = true - } - default: { - $ensure = 'stopped' - $enable = false - } - } - - if $::osfamily != 'windows' { - service { 'sensu-api': - ensure => $ensure, - enable => $enable, - hasrestart => $hasrestart, - subscribe => [ - Class['sensu::package'], - Class['sensu::api::config'], - Class['sensu::redis::config'], - Class['sensu::rabbitmq::config'], - ], - } - } - } -} diff --git a/manifests/check.pp b/manifests/check.pp index 2270feade2..d5f9272596 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -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, } } diff --git a/manifests/client/service.pp b/manifests/client.pp similarity index 56% rename from manifests/client/service.pp rename to manifests/client.pp index 34d567ad22..3714511758 100644 --- a/manifests/client/service.pp +++ b/manifests/client.pp @@ -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 } } @@ -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, + } } diff --git a/manifests/client/config.pp b/manifests/client/config.pp deleted file mode 100644 index 9f2e09ea0d..0000000000 --- a/manifests/client/config.pp +++ /dev/null @@ -1,43 +0,0 @@ -# @summary Sets the Sensu client config -# -# Sets the Sensu client config -# -class sensu::client::config { - - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - - if $::sensu::_purge_config and !$::sensu::client { - $ensure = 'absent' - } else { - $ensure = 'present' - } - - file { "${sensu::conf_dir}/client.json": - ensure => $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 => $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, - } -} diff --git a/manifests/config.pp b/manifests/config.pp index 71bf4aea8f..7d4f595c2d 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -27,7 +27,7 @@ ensure => $ensure, config => $config, event => $event, - notify => Class['sensu::client::service'], + notify => $::sensu::client_service, } } diff --git a/manifests/enterprise/package.pp b/manifests/enterprise.pp similarity index 74% rename from manifests/enterprise/package.pp rename to manifests/enterprise.pp index e2eb785e85..79888f2a57 100644 --- a/manifests/enterprise/package.pp +++ b/manifests/enterprise.pp @@ -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. # @@ -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, @@ -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': @@ -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'], + ], + } + } + } } diff --git a/manifests/enterprise/dashboard.pp b/manifests/enterprise/dashboard.pp index bc7f23edf2..4873a90167 100644 --- a/manifests/enterprise/dashboard.pp +++ b/manifests/enterprise/dashboard.pp @@ -2,15 +2,92 @@ # # Installs the Sensu Enterprise Dashboard class sensu::enterprise::dashboard ( - Boolean $hasrestart = true, + Boolean $hasrestart = $::sensu::hasrestart, ) { - anchor { 'sensu::enterprise::dashboard::begin': } - -> class { '::sensu::enterprise::dashboard::package': } - -> class { '::sensu::enterprise::dashboard::config': } - -> class { '::sensu::enterprise::dashboard::service': - hasrestart => $hasrestart, + # Package + if $::sensu::enterprise_dashboard { + package { 'sensu-enterprise-dashboard': + ensure => $::sensu::enterprise_dashboard_version, + } } - -> anchor { 'sensu::enterprise::dashboard::end': } + # Config + if $::sensu::enterprise_dashboard { + $ensure = 'present' + } elsif $::sensu::purge =~ Hash { + if $::sensu::purge['config'] { + $ensure = 'absent' + } else { + $ensure = undef + } + } elsif $::sensu::purge { + $ensure = 'absent' + } else { + $ensure = undef + } + + if $ensure != undef { + if $ensure == 'present' { + $file_ensure = 'file' + } else { + $file_ensure = $ensure + } + + $file_notify = $::sensu::manage_services ? { + true => $::sensu::enterprise_dashboard ? { + true => $::osfamily ? { + 'windows' => undef, + default => Service['sensu-enterprise-dashboard'], + }, + false => undef, + }, + false => undef, + } + + file { "${sensu::etc_dir}/dashboard.json": + ensure => $file_ensure, + owner => 'sensu', + group => 'sensu', + mode => '0440', + notify => $file_notify, + } + + sensu_enterprise_dashboard_config { $::fqdn: + ensure => $ensure, + base_path => $::sensu::enterprise_dashboard_base_path, + host => $::sensu::enterprise_dashboard_host, + port => $::sensu::enterprise_dashboard_port, + refresh => $::sensu::enterprise_dashboard_refresh, + user => $::sensu::enterprise_dashboard_user, + pass => $::sensu::enterprise_dashboard_pass, + ssl => $::sensu::enterprise_dashboard_ssl, + audit => $::sensu::enterprise_dashboard_audit, + github => $::sensu::enterprise_dashboard_github, + gitlab => $::sensu::enterprise_dashboard_gitlab, + ldap => $::sensu::enterprise_dashboard_ldap, + notify => $file_notify, + } + } + + # Service + if $::sensu::manage_services and $::sensu::enterprise_dashboard { + + $service_ensure = $::sensu::enterprise_dashboard ? { + true => 'running', + false => 'stopped', + } + + if $::osfamily != 'windows' { + service { 'sensu-enterprise-dashboard': + ensure => $service_ensure, + enable => $::sensu::enterprise_dashboard, + hasrestart => $hasrestart, + subscribe => [ + Package['sensu-enterprise-dashboard'], + Class['sensu::redis::config'], + ], + } + } + } } diff --git a/manifests/enterprise/dashboard/api.pp b/manifests/enterprise/dashboard/api.pp index 06914d68cc..9c56d409e1 100644 --- a/manifests/enterprise/dashboard/api.pp +++ b/manifests/enterprise/dashboard/api.pp @@ -39,7 +39,7 @@ Optional[String] $pass = undef, ) { - require ::sensu::enterprise::dashboard::config + require ::sensu::enterprise::dashboard sensu_enterprise_dashboard_api_config { $title: ensure => $ensure, diff --git a/manifests/enterprise/dashboard/config.pp b/manifests/enterprise/dashboard/config.pp deleted file mode 100644 index 352566fcb8..0000000000 --- a/manifests/enterprise/dashboard/config.pp +++ /dev/null @@ -1,53 +0,0 @@ -# @summary Manages the Sensu Enterprise Dashboard configuration -# -# Manages the Sensu Enterprise Dashboard configuration -# -class sensu::enterprise::dashboard::config { - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - - if $::sensu::enterprise_dashboard { - $ensure = 'present' - } elsif $::sensu::purge =~ Hash { - if $::sensu::purge['config'] { - $ensure = 'absent' - } else { - $ensure = undef - } - } elsif $::sensu::purge { - $ensure = 'absent' - } else { - $ensure = undef - } - - if $ensure != undef { - if $ensure == 'present' { - $_ensure = 'file' - } else { - $_ensure = $ensure - } - - file { "${sensu::etc_dir}/dashboard.json": - ensure => $_ensure, - owner => 'sensu', - group => 'sensu', - mode => '0440', - } - - sensu_enterprise_dashboard_config { $::fqdn: - ensure => $ensure, - base_path => $::sensu::enterprise_dashboard_base_path, - host => $::sensu::enterprise_dashboard_host, - port => $::sensu::enterprise_dashboard_port, - refresh => $::sensu::enterprise_dashboard_refresh, - user => $::sensu::enterprise_dashboard_user, - pass => $::sensu::enterprise_dashboard_pass, - ssl => $::sensu::enterprise_dashboard_ssl, - audit => $::sensu::enterprise_dashboard_audit, - github => $::sensu::enterprise_dashboard_github, - gitlab => $::sensu::enterprise_dashboard_gitlab, - ldap => $::sensu::enterprise_dashboard_ldap, - } - } -} diff --git a/manifests/enterprise/dashboard/package.pp b/manifests/enterprise/dashboard/package.pp deleted file mode 100644 index 0aa64434e3..0000000000 --- a/manifests/enterprise/dashboard/package.pp +++ /dev/null @@ -1,16 +0,0 @@ -# @summary Manages the sensu-enterprise-dashboard package -# -# Manages the sensu-enterprise-dashboard package -# -class sensu::enterprise::dashboard::package { - - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - - if $::sensu::enterprise_dashboard { - package { 'sensu-enterprise-dashboard': - ensure => $::sensu::enterprise_dashboard_version, - } - } -} diff --git a/manifests/enterprise/dashboard/service.pp b/manifests/enterprise/dashboard/service.pp deleted file mode 100644 index 66e437aba3..0000000000 --- a/manifests/enterprise/dashboard/service.pp +++ /dev/null @@ -1,39 +0,0 @@ -# @summary Installs the Sensu Enterprise Dashboard -# -# Installs the Sensu Enterprise Dashboard -# -class sensu::enterprise::dashboard::service ( - Boolean $hasrestart = true, -) { - - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - - if $::sensu::manage_services and $::sensu::enterprise_dashboard { - - case $::sensu::enterprise_dashboard { - true: { - $ensure = 'running' - $enable = true - } - default: { - $ensure = 'stopped' - $enable = false - } - } - - if $::osfamily != 'windows' { - service { 'sensu-enterprise-dashboard': - ensure => $ensure, - enable => $enable, - hasrestart => $hasrestart, - subscribe => [ - Class['sensu::enterprise::dashboard::package'], - Class['sensu::enterprise::dashboard::config'], - Class['sensu::redis::config'], - ], - } - } - } -} diff --git a/manifests/enterprise/service.pp b/manifests/enterprise/service.pp deleted file mode 100644 index 6c65125e7d..0000000000 --- a/manifests/enterprise/service.pp +++ /dev/null @@ -1,42 +0,0 @@ -# @summary Manages the Sensu Enterprise server service -# -# Manages the Sensu Enterprise server service -# -# @param hasrestart Value of hasrestart attribute for this service. -# -class sensu::enterprise::service ( - Boolean $hasrestart = true, -) { - - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - - 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 => [ - Class['sensu::enterprise::package'], - Class['sensu::api::config'], - Class['sensu::redis::config'], - Class['sensu::rabbitmq::config'], - ], - } - } - } -} diff --git a/manifests/extension.pp b/manifests/extension.pp index 0076f60f00..5f9b144931 100644 --- a/manifests/extension.pp +++ b/manifests/extension.pp @@ -19,8 +19,8 @@ Hash $config = {}, ) { - if $::sensu::client { - $notify_services = Class['sensu::client::service'] + if $::sensu::client and $::sensu::manage_services { + $notify_services = Service['sensu-client'] } else { $notify_services = [] } diff --git a/manifests/init.pp b/manifests/init.pp index 6abadcf2b4..7eefcf9ed3 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -415,10 +415,10 @@ } # Put here to avoid computing the conditionals for every check - if $client { - $client_service_class = Class['sensu::client::service'] + if $client and $manage_services { + $client_service = Service['sensu-client'] } else { - $client_service_class = undef + $client_service = undef } if $server { @@ -427,13 +427,13 @@ $server_service_class = undef } - if $api { - $api_service_class = Class['sensu::api::service'] + if $api and $manage_services and $::osfamily != 'windows' { + $api_service = Service['sensu-api'] } else { - $api_service_class = undef + $api_service = undef } - $check_notify = delete_undef_values([ $client_service_class, $server_service_class, $api_service_class ]) + $check_notify = delete_undef_values([ $client_service, $server_service_class, $api_service ]) # Because you can't reassign a variable in puppet and we need to set to # false if you specify a directory, we have to use another variable. @@ -472,12 +472,31 @@ # managed after all plugins. It must always exist in the catalog. anchor { 'plugins_before_checks': } - # Create resources from hiera lookups - create_resources('::sensu::extension', $extensions) - create_resources('::sensu::handler', $handlers, $handler_defaults) - create_resources('::sensu::check', $checks, $check_defaults) - create_resources('::sensu::filter', $filters, $filter_defaults) - create_resources('::sensu::mutator', $mutators) + $extensions.each |$k,$v| { + ::sensu::extension { $k: + * => $v, + } + } + $handlers.each |$k,$v| { + ::sensu::handler { $k: + * => $handler_defaults + $v, + } + } + $checks.each |$k,$v| { + ::sensu::check { $k: + * => $check_defaults + $v, + } + } + $filters.each |$k,$v| { + ::sensu::filter { $k: + * => $filter_defaults + $v, + } + } + $mutators.each |$k,$v| { + ::sensu::mutator { $k: + * => $v, + } + } case $::osfamily { 'Debian','RedHat': { @@ -507,30 +526,24 @@ # Include everything and let each module determine its state. This allows # transitioning to purged config and stopping/disabling services - anchor { 'sensu::begin': } - -> class { '::sensu::package': } - -> class { '::sensu::enterprise::package': } - -> class { '::sensu::transport': } - -> class { '::sensu::rabbitmq::config': } - -> class { '::sensu::api::config': } - -> class { '::sensu::redis::config': } - -> class { '::sensu::client::config': } - -> class { '::sensu::client::service': - hasrestart => $hasrestart, - } - -> class { '::sensu::api::service': - hasrestart => $hasrestart, - } - -> class { '::sensu::server::service': - hasrestart => $hasrestart, - } - -> class { '::sensu::enterprise::service': - hasrestart => $hasrestart, - } - -> class { '::sensu::enterprise::dashboard': - hasrestart => $hasrestart, - } - -> anchor {'sensu::end': } + contain ::sensu::package + contain ::sensu::enterprise + contain ::sensu::transport + contain ::sensu::rabbitmq::config + contain ::sensu::api + contain ::sensu::redis::config + contain ::sensu::client + contain ::sensu::server::service + contain ::sensu::enterprise::dashboard + + Class['::sensu::package'] + -> Class['::sensu::transport'] + -> Class['::sensu::rabbitmq::config'] + -> Sensu_api_config[$::fqdn] + -> Class['::sensu::redis::config'] + -> Sensu_client_config[$::fqdn] + -> Class['::sensu::server::service'] + -> Class['::sensu::enterprise::dashboard'] if $plugins_dir { sensu::plugin { $plugins_dir: type => 'directory' } diff --git a/manifests/package.pp b/manifests/package.pp index 4951ce80f9..62bc677242 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -49,10 +49,6 @@ Optional[Boolean] $use_embedded_ruby = $::sensu::use_embedded_ruby, ) { - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - case $::osfamily { 'Debian': { @@ -255,13 +251,15 @@ $spawn_template = '<%= require "json"; JSON.pretty_generate(@spawn_config) + $/ %>' $spawn_ensure = 'file' $spawn_content = inline_template($spawn_template) - if $::sensu::client { + if $::sensu::client and $::sensu::manage_services { $spawn_notify = [ - Class['sensu::client::service'], + Service['sensu-client'], Class['sensu::server::service'], ] - } else { + } elsif $::sensu::manage_services { $spawn_notify = [ Class['sensu::server::service'] ] + } else { + $spawn_notify = undef } } else { $spawn_ensure = undef diff --git a/manifests/rabbitmq/config.pp b/manifests/rabbitmq/config.pp index 58ba9bbda4..0a33632b02 100644 --- a/manifests/rabbitmq/config.pp +++ b/manifests/rabbitmq/config.pp @@ -4,10 +4,6 @@ # class sensu::rabbitmq::config { - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - if $::sensu::_purge_config and !$::sensu::server and !$::sensu::client and !$::sensu::enterprise and $::sensu::transport_type != 'rabbitmq' { $ensure = 'absent' } else { diff --git a/manifests/redis/config.pp b/manifests/redis/config.pp index d58027779a..d1978335a0 100644 --- a/manifests/redis/config.pp +++ b/manifests/redis/config.pp @@ -4,10 +4,6 @@ # class sensu::redis::config { - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - if $::sensu::_purge_config and !$::sensu::server and !$::sensu::api and !$::sensu::enterprise and $::sensu::transport_type != 'redis' { $ensure = 'absent' } else { diff --git a/manifests/repo/apt.pp b/manifests/repo/apt.pp index ce1547dc04..2bd88aad57 100644 --- a/manifests/repo/apt.pp +++ b/manifests/repo/apt.pp @@ -4,10 +4,6 @@ # class sensu::repo::apt { - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - if defined(apt::source) { $ensure = $::sensu::install_repo ? { diff --git a/manifests/repo/yum.pp b/manifests/repo/yum.pp index 424b2970cf..4f4f6da790 100644 --- a/manifests/repo/yum.pp +++ b/manifests/repo/yum.pp @@ -4,10 +4,6 @@ # class sensu::repo::yum { - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - if $::sensu::install_repo { if $::sensu::repo_source { $url = $::sensu::repo_source diff --git a/manifests/server/service.pp b/manifests/server/service.pp index aeec772a71..5a915fc316 100644 --- a/manifests/server/service.pp +++ b/manifests/server/service.pp @@ -5,13 +5,9 @@ # @param hasrestart Value of hasrestart attribute for this service. # class sensu::server::service ( - Boolean $hasrestart = true, + Boolean $hasrestart = $::sensu::hasrestart, ) { - if $caller_module_name != $module_name { - fail("Use of private class ${name} by ${caller_module_name}") - } - if $::sensu::manage_services { case $::sensu::server { @@ -32,7 +28,7 @@ hasrestart => $hasrestart, subscribe => [ Class['sensu::package'], - Class['sensu::api::config'], + Sensu_api_config[$::fqdn], Class['sensu::redis::config'], Class['sensu::rabbitmq::config'], ], diff --git a/manifests/subscription.pp b/manifests/subscription.pp index e56ccb2a39..f6928c0b6e 100644 --- a/manifests/subscription.pp +++ b/manifests/subscription.pp @@ -25,6 +25,6 @@ ensure => $ensure, base_path => $::sensu::conf_dir, custom => $custom, - notify => Class['sensu::client::service'], + notify => $::sensu::client_service, } } diff --git a/manifests/transport.pp b/manifests/transport.pp index 86be350faa..576997c350 100644 --- a/manifests/transport.pp +++ b/manifests/transport.pp @@ -4,10 +4,6 @@ # class sensu::transport { - if $caller_module_name != $module_name { - fail("Use of private function ${name} by ${caller_module_name}") - } - if $::sensu::transport_type != 'redis' { $ensure = 'absent' } else { diff --git a/manifests/write_json.pp b/manifests/write_json.pp index 7cbff4132b..2ff08028e4 100644 --- a/manifests/write_json.pp +++ b/manifests/write_json.pp @@ -36,7 +36,7 @@ String $mode = '0755', Boolean $pretty = true, Hash $content = {}, - Array $notify_list = [], + Array[Variant[Data,Type]] $notify_list = [], ) { # ensure we have a properly formatted file path for our target OS diff --git a/spec/classes/sensu_init_spec.rb b/spec/classes/sensu_init_spec.rb index eab393c2eb..bbd2aae793 100644 --- a/spec/classes/sensu_init_spec.rb +++ b/spec/classes/sensu_init_spec.rb @@ -43,17 +43,17 @@ # resources from sensu::redis::config it { should contain_file('/etc/sensu/conf.d/redis.json') } it { should contain_sensu_redis_config('testfqdn.example.com').with_base_path('/etc/sensu/conf.d') } - # resources from sensu::api::config + # resources from sensu::api it { should contain_file('/etc/sensu/conf.d/api.json') } it { should contain_sensu_api_config('testfqdn.example.com').with_base_path('/etc/sensu/conf.d') } - # resources from sensu::enterprise::dashboard::config + # resources from sensu::enterprise::dashboard it { should_not contain_file('/etc/sensu/dashboard.json') } # resources from sensu::subscription (positive tests are included in test for sensu::subscription itself) it { should_not contain_file('/etc/sensu/conf.d/subscriptiond.json') } it { should_not contain_sensu_client_subscription('mysubscription').with_base_path('/etc/sensu/conf.d') } # resources from sensu::transport it { should contain_file('/etc/sensu/conf.d/transport.json') } - # resources from sensu::client::config + # resources from sensu::client it { should contain_file('/etc/sensu/conf.d/client.json') } it { should contain_sensu_client_config('testfqdn.example.com').with_base_path('/etc/sensu/conf.d') } end @@ -84,17 +84,17 @@ # resources from sensu::redis::config it { should contain_file('/opt/etc/sensu/conf.d/redis.json') } it { should contain_sensu_redis_config('testfqdn.example.com').with_base_path('/opt/etc/sensu/conf.d') } - # resources from sensu::api::config + # resources from sensu::api it { should contain_file('/opt/etc/sensu/conf.d/api.json') } it { should contain_sensu_api_config('testfqdn.example.com').with_base_path('/opt/etc/sensu/conf.d') } - # resources from sensu::enterprise::dashboard::config + # resources from sensu::enterprise::dashboard it { should_not contain_file('/opt/etc/sensu/dashboard.json') } # resources from sensu::subscription (positive tests are included in test for sensu::subscription itself) it { should_not contain_file('/opt/etc/sensu/conf.d/subscriptiond.json') } it { should_not contain_sensu_client_subscription('mysubscription').with_base_path('/opt/etc/sensu/conf.d') } # resources from sensu::transport it { should contain_file('/opt/etc/sensu/conf.d/transport.json') } - # resources from sensu::client::config + # resources from sensu::client it { should contain_file('/opt/etc/sensu/conf.d/client.json') } it { should contain_sensu_client_config('testfqdn.example.com').with_base_path('/opt/etc/sensu/conf.d') } @@ -162,14 +162,14 @@ # resources from sensu::redis::config it { should contain_file('C:/opt/sensu/conf.d/redis.json') } it { should contain_sensu_redis_config('testfqdn.example.com').with_base_path('C:/opt/sensu/conf.d') } - # resources from sensu::api::config + # resources from sensu::api it { should contain_file('C:/opt/sensu/conf.d/api.json') } it { should contain_sensu_api_config('testfqdn.example.com').with_base_path('C:/opt/sensu/conf.d') } - # resources from sensu::enterprise::dashboard::config + # resources from sensu::enterprise::dashboard it { should_not contain_file('C:/opt/sensu/dashboard.json') } # resources from sensu::transport it { should contain_file('C:/opt/sensu/conf.d/transport.json') } - # resources from sensu::client::config + # resources from sensu::client it { should contain_file('C:/opt/sensu/conf.d/client.json') } it { should contain_sensu_client_config('testfqdn.example.com').with_base_path('C:/opt/sensu/conf.d') } @@ -207,14 +207,14 @@ # resources from sensu::redis::config it { should contain_file('C:/etc/sensu/conf.d/redis.json') } it { should contain_sensu_redis_config('testfqdn.example.com').with_base_path('C:/etc/sensu/conf.d') } - # resources from sensu::api::config + # resources from sensu::api it { should contain_file('C:/etc/sensu/conf.d/api.json') } it { should contain_sensu_api_config('testfqdn.example.com').with_base_path('C:/etc/sensu/conf.d') } - # resources from sensu::enterprise::dashboard::config + # resources from sensu::enterprise::dashboard it { should_not contain_file('C:/etc/sensu/dashboard.json') } # resources from sensu::transport it { should contain_file('C:/etc/sensu/conf.d/transport.json') } - # resources from sensu::client::config + # resources from sensu::client it { should contain_file('C:/etc/sensu/conf.d/client.json') } it { should contain_sensu_client_config('testfqdn.example.com').with_base_path('C:/etc/sensu/conf.d') } diff --git a/spec/classes/sensu_service_spec.rb b/spec/classes/sensu_service_spec.rb index 6be9fdde8a..fc8cb1be15 100644 --- a/spec/classes/sensu_service_spec.rb +++ b/spec/classes/sensu_service_spec.rb @@ -5,7 +5,7 @@ context 'service' do context 'running on Linux' do context 'with defaults for all parameters' do - it { should contain_class('sensu::client::service') } + it { should contain_class('sensu::client') } it { should compile.with_all_deps } it do @@ -15,7 +15,7 @@ 'hasrestart' => 'true', 'subscribe' => [ 'Class[Sensu::Package]', - 'Class[Sensu::Client::Config]', + 'Sensu_client_config[testfqdn.example.com]', 'Class[Sensu::Rabbitmq::Config]', ], }) @@ -40,7 +40,7 @@ end context 'with defaults for all parameters' do - it { should contain_class('sensu::client::service') } + it { should contain_class('sensu::client') } # FIXME: test causes issues in sensu::package # it { should compile.with_all_deps } @@ -80,7 +80,7 @@ 'hasrestart' => 'true', 'subscribe' => [ 'Class[Sensu::Package]', - 'Class[Sensu::Client::Config]', + 'Sensu_client_config[testfqdn.example.com]', 'Class[Sensu::Rabbitmq::Config]', ], }) diff --git a/spec/defines/sensu_check_spec.rb b/spec/defines/sensu_check_spec.rb index 9fd70e66ba..620fe7bbe9 100644 --- a/spec/defines/sensu_check_spec.rb +++ b/spec/defines/sensu_check_spec.rb @@ -201,42 +201,42 @@ context 'notifications' do context 'no client, sever, or api' do let(:pre_condition) { 'class {"sensu": client => false, api => false, server => false}' } - it { should contain_file(fpath).with(:notify => []) } + it { should contain_sensu__write_json(fpath).with(:notify_list => []) } end context 'only client' do let(:pre_condition) { 'class {"sensu": client => true, api => false, server => false}' } - it { should contain_file(fpath).with(:notify => ['Class[Sensu::Client::Service]'] ) } + it { should contain_sensu__write_json(fpath).with(:notify_list => ['Service[sensu-client]'] ) } end context 'only server' do let(:pre_condition) { 'class {"sensu": client => false, api => false, server => true}' } - it { should contain_file(fpath).with(:notify => ['Class[Sensu::Server::Service]'] ) } + it { should contain_sensu__write_json(fpath).with(:notify_list => ['Class[Sensu::Server::Service]'] ) } end context 'only api' do let(:pre_condition) { 'class {"sensu": client => false, api => true, server => false}' } - it { should contain_file(fpath).with(:notify => ['Class[Sensu::Api::Service]'] ) } + it { should contain_sensu__write_json(fpath).with(:notify_list => ['Service[sensu-api]'] ) } end context 'client and api' do let(:pre_condition) { 'class {"sensu": client => true, api => true, server => false}' } - it { should contain_file(fpath).with(:notify => ['Class[Sensu::Client::Service]', 'Class[Sensu::Api::Service]']) } + it { should contain_sensu__write_json(fpath).with(:notify_list => ['Service[sensu-client]', 'Service[sensu-api]']) } end context 'client and server' do let(:pre_condition) { 'class {"sensu": client => true, api => false, server => true}' } - it { should contain_file(fpath).with(:notify => ['Class[Sensu::Client::Service]', 'Class[Sensu::Server::Service]']) } + it { should contain_sensu__write_json(fpath).with(:notify_list => ['Service[sensu-client]', 'Class[Sensu::Server::Service]']) } end context 'api and server' do let(:pre_condition) { 'class {"sensu": client => false, api => true, server => true}' } - it { should contain_file(fpath).with(:notify => ['Class[Sensu::Server::Service]', 'Class[Sensu::Api::Service]']) } + it { should contain_sensu__write_json(fpath).with(:notify_list => ['Class[Sensu::Server::Service]', 'Service[sensu-api]']) } end context 'client, api, and server' do let(:pre_condition) { 'class {"sensu": client => true, api => true, server => true}' } - it { should contain_file(fpath).with(:notify => ['Class[Sensu::Client::Service]', 'Class[Sensu::Server::Service]', 'Class[Sensu::Api::Service]']) } + it { should contain_sensu__write_json(fpath).with(:notify_list => ['Service[sensu-client]', 'Class[Sensu::Server::Service]', 'Service[sensu-api]']) } end end diff --git a/spec/defines/sensu_subscription_spec.rb b/spec/defines/sensu_subscription_spec.rb index 53b542f0ad..ec1106c8c2 100644 --- a/spec/defines/sensu_subscription_spec.rb +++ b/spec/defines/sensu_subscription_spec.rb @@ -35,7 +35,7 @@ context 'notifications' do let(:title) { 'mysubscription' } - it { should contain_sensu_client_subscription('mysubscription').with(:notify => 'Class[Sensu::Client::Service]' ) } + it { should contain_sensu_client_subscription('mysubscription').with(:notify => 'Service[sensu-client]' ) } end describe 'when sensu::sensu_etc_dir => /opt/etc/sensu' do