From 95ef05e2d3d2e2a568f229b9dc2f533e2d2cecb6 Mon Sep 17 00:00:00 2001 From: Justin Lambert Date: Mon, 6 Jan 2014 13:37:09 -0700 Subject: [PATCH] module rewrite --- manifests/api/config.pp | 30 +++ manifests/api/service.pp | 30 +++ manifests/check.pp | 59 ++++- manifests/client.pp | 38 --- manifests/client/config.pp | 33 +++ manifests/client/service.pp | 31 +++ manifests/config.pp | 23 +- manifests/dashboard/config.pp | 34 +++ manifests/dashboard/service.pp | 30 +++ manifests/handler.pp | 84 ++++++- manifests/init.pp | 280 +++++++++++++++------- manifests/package.pp | 59 ++--- manifests/plugin.pp | 33 ++- manifests/rabbitmq.pp | 86 ------- manifests/rabbitmq/config.pp | 81 +++++++ manifests/redis/config.pp | 30 +++ manifests/repo.pp | 28 --- manifests/repo/apt.pp | 21 +- manifests/repo/yum.pp | 35 +-- manifests/server.pp | 77 ------ manifests/server/service.pp | 30 +++ manifests/service/client.pp | 25 -- manifests/service/server.pp | 31 --- manifests/subscription.pp | 13 +- spec/classes/sensu_api_spec.rb | 107 +++++++++ spec/classes/sensu_client_spec.rb | 143 +++++++---- spec/classes/sensu_dashboard_spec.rb | 96 ++++++++ spec/classes/sensu_init_spec.rb | 133 +--------- spec/classes/sensu_package_spec.rb | 137 ++++++++--- spec/classes/sensu_rabbitmq_spec.rb | 140 +++++------ spec/classes/sensu_redis_spec.rb | 55 +++++ spec/classes/sensu_repo_apt_spec.rb | 51 ---- spec/classes/sensu_repo_spec.rb | 53 ---- spec/classes/sensu_repo_yum_spec.rb | 30 --- spec/classes/sensu_server_spec.rb | 87 +------ spec/classes/sensu_service_client_spec.rb | 27 --- spec/classes/sensu_service_server_spec.rb | 50 ---- spec/defines/sensu_check_spec.rb | 52 ++-- spec/defines/sensu_handler_spec.rb | 43 ++-- 39 files changed, 1371 insertions(+), 1054 deletions(-) create mode 100644 manifests/api/config.pp create mode 100644 manifests/api/service.pp delete mode 100644 manifests/client.pp create mode 100644 manifests/client/config.pp create mode 100644 manifests/client/service.pp create mode 100644 manifests/dashboard/config.pp create mode 100644 manifests/dashboard/service.pp delete mode 100644 manifests/rabbitmq.pp create mode 100644 manifests/rabbitmq/config.pp create mode 100644 manifests/redis/config.pp delete mode 100644 manifests/repo.pp delete mode 100644 manifests/server.pp create mode 100644 manifests/server/service.pp delete mode 100644 manifests/service/client.pp delete mode 100644 manifests/service/server.pp create mode 100644 spec/classes/sensu_api_spec.rb create mode 100644 spec/classes/sensu_dashboard_spec.rb create mode 100644 spec/classes/sensu_redis_spec.rb delete mode 100644 spec/classes/sensu_repo_apt_spec.rb delete mode 100644 spec/classes/sensu_repo_spec.rb delete mode 100644 spec/classes/sensu_repo_yum_spec.rb delete mode 100644 spec/classes/sensu_service_client_spec.rb delete mode 100644 spec/classes/sensu_service_server_spec.rb diff --git a/manifests/api/config.pp b/manifests/api/config.pp new file mode 100644 index 0000000000..2324042020 --- /dev/null +++ b/manifests/api/config.pp @@ -0,0 +1,30 @@ +# = Class: 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_real and !$sensu::server_real and !$sensu::api_real and !$sensu::dashboard_real { + $ensure = 'absent' + } else { + $ensure = 'present' + } + + file { '/etc/sensu/conf.d/api.json': + ensure => $ensure, + owner => 'sensu', + group => 'sensu', + mode => '0444', + } + + sensu_api_config { $::fqdn: + ensure => $ensure, + host => $sensu::api_host, + port => $sensu::api_port, + } + +} diff --git a/manifests/api/service.pp b/manifests/api/service.pp new file mode 100644 index 0000000000..81bbe17958 --- /dev/null +++ b/manifests/api/service.pp @@ -0,0 +1,30 @@ +# = Class: sensu::api::service +# +# Manages the Sensu api service +# +class sensu::api::service { + + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } + + if $sensu::manage_services_real { + + case $sensu::api_real { + true: { + $ensure = 'running' + $enable = true + } + default: { + $ensure = 'stopped' + $enable = false + } + } + + service { 'sensu-api': + ensure => $ensure, + enable => $enable, + subscribe => [ Class['sensu::package'], Class['sensu::api::config'], Class['sensu::redis::config'] ] + } + } +} diff --git a/manifests/check.pp b/manifests/check.pp index 6d06715b1b..63c234e37f 100644 --- a/manifests/check.pp +++ b/manifests/check.pp @@ -4,21 +4,69 @@ # # == Parameters # - +# [*command*] +# String. The check command to run +# +# [*ensure*] +# String. Whether the check should be present or not +# Default: present +# Valid values: present, absent +# +# [*type*] +# String. Type of check +# Default: undef +# +# [*handlers*] +# String, Array of Strings. Handlers to use for this check +# Default: undef +# +# [*standalone*] +# Boolean. When true, scheduled by the client. When false, listen for published check request +# Default: true +# +# [*interval*] +# Integer. How frequently (in seconds) the check will be executed +# Default: 60 +# +# [*subscribers*] +# Array of Strings. Which subscriptions must execute this check +# Default: [] +# +# [*low_flap_threshold*] +# Integer. Flap detection - see Nagios Flap Detection: http://nagios.sourceforge.net/docs/3_0/flapping.html +# Default: undef +# +# [*high_flap_threshold*] +# Integer. Flap detection - see Nagios Flap Detection: http://nagios.sourceforge.net/docs/3_0/flapping.html +# Default: undef +# define sensu::check( $command, $ensure = 'present', $type = undef, $handlers = undef, $standalone = true, - $interval = '60', - $subscribers = undef, + $interval = 60, + $subscribers = [], $low_flap_threshold = undef, $high_flap_threshold = undef, $custom = undef, ) { - $check_name = regsubst(regsubst($name, ' ', '_', 'G'), '[\(\)]', '', 'G') + validate_re($ensure, ['^present$', '^absent$'] ) + validate_bool($standalone) + $handlers_real = any2array($handlers) + if !is_integer($interval) { + fail("sensu::check{${name}}: interval must be an integer (got: ${interval})") + } + if $low_flap_threshold and !is_integer($low_flap_threshold) { + fail("sensu::check{${name}}: low_flap_threshold must be an integer (got: ${low_flap_threshold})") + } + if $high_flap_threshold and !is_integer($high_flap_threshold) { + fail("sensu::check{${name}}: high_flap_threshold must be an integer (got: ${high_flap_threshold})") + } + + $check_name = regsubst($name, ' ', '_', 'G') file { "/etc/sensu/conf.d/checks/${check_name}.json": ensure => $ensure, @@ -33,13 +81,14 @@ type => $type, standalone => $standalone, command => $command, - handlers => $handlers, + handlers => $handlers_real, interval => $interval, subscribers => $subscribers, low_flap_threshold => $low_flap_threshold, high_flap_threshold => $high_flap_threshold, custom => $custom, require => File['/etc/sensu/conf.d/checks'], + notify => [ Class['sensu::client::service'], Class['sensu::server::service'] ], } } diff --git a/manifests/client.pp b/manifests/client.pp deleted file mode 100644 index 8dc1720129..0000000000 --- a/manifests/client.pp +++ /dev/null @@ -1,38 +0,0 @@ -# = Class: sensu::client -# -# Configures Sensu clients -# -# == Parameters -# -class sensu::client( - $address = $::ipaddress, - $subscriptions = [], - $client_name = $::fqdn, - $enabled = 'true', - $safe_mode = false, - $custom = {} -) { - - $ensure = $enabled ? { - 'true' => 'present', - true => 'present', - default => 'absent' - } - - file { '/etc/sensu/conf.d/client.json': - ensure => $ensure, - owner => 'sensu', - group => 'sensu', - mode => '0444', - } - - sensu_client_config { $::fqdn: - ensure => $ensure, - client_name => $client_name, - address => $address, - subscriptions => $subscriptions, - safe_mode => $safe_mode, - custom => $custom, - } - -} diff --git a/manifests/client/config.pp b/manifests/client/config.pp new file mode 100644 index 0000000000..63ab4a7e07 --- /dev/null +++ b/manifests/client/config.pp @@ -0,0 +1,33 @@ +# = Class: 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_real and !$sensu::client_real { + $ensure = 'absent' + } else { + $ensure = 'present' + } + + file { '/etc/sensu/conf.d/client.json': + ensure => $ensure, + owner => 'sensu', + group => 'sensu', + mode => '0444', + } + + sensu_client_config { $::fqdn: + ensure => $ensure, + client_name => $sensu::client_name, + address => $sensu::client_address, + subscriptions => $sensu::subscriptions_real, + safe_mode => $sensu::safe_mode, + custom => $sensu::client_custom, + } + +} diff --git a/manifests/client/service.pp b/manifests/client/service.pp new file mode 100644 index 0000000000..8923925a21 --- /dev/null +++ b/manifests/client/service.pp @@ -0,0 +1,31 @@ +# = Class: sensu::client::service +# +# Manages the Sensu client service +# +class sensu::client::service { + + + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } + + if $sensu::manage_services_real { + + case $sensu::client_real { + true: { + $ensure = 'running' + $enable = true + } + default: { + $ensure = 'stopped' + $enable = false + } + } + + service { 'sensu-client': + ensure => $ensure, + enable => $enable, + subscribe => [Class['sensu::package'], Class['sensu::client::config'], Class['sensu::rabbitmq::config'] ], + } + } +} diff --git a/manifests/config.pp b/manifests/config.pp index e4087d9e2f..ddea8b40b7 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,13 +4,27 @@ # # == Parameters # - +# [*ensure*] +# String. Whether the check should be present or not +# Default: present +# Valid values: present, absent +# +# [*config*] +# Hash. Check configuration for the client to use +# Default: undef +# +# [*event*] +# Hash. Configuration to send with the event to handlers +# Default: undef +# define sensu::config ( $ensure = 'present', $config = undef, $event = undef, ) { + validate_re($ensure, ['^present$', '^absent$'] ) + file { "/etc/sensu/conf.d/checks/config_${name}.json": ensure => $ensure, owner => 'sensu', @@ -20,9 +34,10 @@ } sensu_check_config { $name: - ensure => $ensure, - config => $config, - event => $event, + ensure => $ensure, + config => $config, + event => $event, + notify => Class['sensu::client::service'], } } diff --git a/manifests/dashboard/config.pp b/manifests/dashboard/config.pp new file mode 100644 index 0000000000..10d9d5083e --- /dev/null +++ b/manifests/dashboard/config.pp @@ -0,0 +1,34 @@ +# = Class: sensu::dashboard::config +# +# Sets the Sensu dashboard config +# +class sensu::dashboard::config { + + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } + + if $sensu::purge_config_real and !$sensu::dashboard_real { + $ensure = 'absent' + } else { + $ensure = 'present' + } + + file { '/etc/sensu/conf.d/dashboard.json': + ensure => $ensure, + owner => 'sensu', + group => 'sensu', + mode => '0440', + } + + sensu_dashboard_config { $::fqdn: + ensure => $ensure, + host => $sensu::dashboard_host, + port => $sensu::dashboard_port, + user => $sensu::dashboard_user, + password => $sensu::dashboard_password, + notify => Class['sensu::dashboard::service'], + + } + +} diff --git a/manifests/dashboard/service.pp b/manifests/dashboard/service.pp new file mode 100644 index 0000000000..78950b89d2 --- /dev/null +++ b/manifests/dashboard/service.pp @@ -0,0 +1,30 @@ +# = Class: sensu::dashboard::service +# +# Manages the Sensu dashboard service +# +class sensu::dashboard::service { + + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } + + if $sensu::manage_services_real { + + case $sensu::dashboard_real { + true: { + $ensure = 'running' + $enable = true + } + default: { + $ensure = 'stopped' + $enable = false + } + } + + service { 'sensu-dashboard': + ensure => $ensure, + enable => $enable, + subscribe => [ Class['sensu::package'], Class['sensu::dashboard::config'], Class['sensu::api::config'], Class['sensu::redis::config'] ] + } + } +} diff --git a/manifests/handler.pp b/manifests/handler.pp index 05f089ebba..b40b609f25 100644 --- a/manifests/handler.pp +++ b/manifests/handler.pp @@ -4,30 +4,98 @@ # # == Parameters # - +# [*ensure*] +# String. Whether the check should be present or not +# Default: present +# Valid values: present, absent +# +# [*type*] +# String. Type of handler +# Default: pipe +# Valid values: pipe, tcp, udp, amqp, set +# +# [*command*] +# String. Command to run as the handler when type=pipe +# Default: undef +# +# [*handlers*] +# String, Array of Strings. Handlers to use when type=set +# Default: undef +# +# [*severities*] +# String, Array of Strings. Severities handler is valid for +# Default: ['ok', 'warning', 'critical', 'unknown'] +# Valid values: ok, warning, critical, unknown +# +# [*exchange*] +# Hash. Exchange information used when type=amqp +# Keys: host, port +# Default: undef +# +# [*socket*] +# Hash. Socket information when type=tcp or type=udp +# Keys: host, port +# Default: undef +# +# [*source*] +# String. Source of the puppet handler +# Default: undef +# +# [*install_path*] +# String. Path to install the handler +# Default: /etc/sensu/handlers +# +# [*config*] +# Hash. Handler specific config +# Default: undef +# +# define sensu::handler( + $ensure = 'present', $type = 'pipe', $command = undef, $handlers = undef, - $ensure = 'present', $severities = ['ok', 'warning', 'critical', 'unknown'], $exchange = undef, $mutator = undef, $socket = undef, # Used to install the handler - $source = '', + $source = undef, $install_path = '/etc/sensu/handlers', # Handler specific config $config = undef, ) { - if defined(Class['sensu::service::server']) { - $notify_services = Class['sensu::service::server'] + validate_re($ensure, ['^present$', '^absent$'] ) + validate_re($type, [ '^pipe$', '^tcp$', '^udp$', '^amqp$', '^set$' ] ) + if $exchange { validate_hash($exchange) } + if $socket { validate_hash($socket) } + $handlers_real = any2array($handlers) + $severities_real = any2array($severities) + if $source { validate_re($source, ['^puppet://'] ) } + + if $type == 'pipe' and $ensure != 'absent' and !$command and !$source and !$mutator { + fail('command must be set with type pipe') + } + if ($type == 'tcp' or $type == 'udp') and !$socket { + fail("socket must be set with type ${type}") + } + + if $type == 'amqp' and !$exchange { + fail('exchange must be set with type amqp') + } + + if $type == 'set' and !$handlers { + fail('handlers must be set with type set') + } + + if $sensu::server { + $notify_services = Class['sensu::server::service'] } else { $notify_services = [] } - if $source != '' { + if $source { $filename = inline_template("<%= scope.lookupvar('source').split('/').last %>") $command_real = "${install_path}/${filename}" @@ -60,8 +128,8 @@ ensure => $ensure, type => $type, command => $command_real, - handlers => $handlers, - severities => $severities, + handlers => $handlers_real, + severities => $severities_real, exchange => $exchange, socket => $socket, mutator => $mutator, diff --git a/manifests/init.pp b/manifests/init.pp index 9b28729038..1fedd5b923 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,120 +4,220 @@ # # == Parameters # -# None. +# [*version*] +# String. Version of sensu to install +# Default: latest +# Valid values: absent, installed, latest, present, [\d\.\-]+ +# +# [*install_repo*] +# Boolean. Whether or not to install the sensu repo +# Default: true +# Valid values: true, false +# +# [*repo*] +# String. Which sensu repo to install +# Default: main +# Valid values: main, unstable +# +# [*client*] +# Boolean. Include the sensu client +# Default: true +# Valid values: true, false +# +# [*server*] +# Boolean. Include the sensu server +# Default: false +# Valid values: true, false +# +# [*api*] +# Boolean. Include the sensu api service +# Default: false +# Valid values: true, false +# +# [*dashboard*] +# Boolean. Include the sensu dashboard service +# Default: false +# Valid values: true, false +# +# [*manage_services*] +# Boolean. Manage the sensu services with puppet +# Default: true +# Valid values: true, false +# +# [*rabbitmq_port*] +# Integer. Rabbitmq port to be used by sensu +# Default: 5671 +# +# [*rabbitmq_host*] +# String. Host running rabbitmq for sensu +# Default: 'localhost' +# +# [*rabbitmq_user*] +# String. Username to connect to rabbitmq with for sensu +# Default: 'sensu' +# +# [*rabbitmq_password*] +# String. Password to connect to rabbitmq with for sensu +# Default: '' +# +# [*rabbitmq_vhost*] +# String. Rabbitmq vhost to be used by sensu +# Default: '/sensu' +# +# [*rabbitmq_ssl_private_key*] +# String. Private key to be used by sensu to connect to rabbitmq +# If the value starts with 'puppet://' the file will be copied and used. Absolute paths will just be used +# Default: undef +# +# [*rabbitmq_ssl_cert_chain*] +# String. Private SSL cert chain to be used by sensu to connect to rabbitmq +# If the value starts with 'puppet://' the file will be copied and used. Absolute paths will just be used +# Default: undef +# +# [*redis_host*] +# String. Hostname of redis to be used by sensu +# Default: localhost +# +# [*redis_port*] +# Integer. Redis port to be used by sensu +# Default: 6379 +# +# [*api_host*] +# String. Hostname of the sensu api service +# Default: localhost +# +# [*api_port*] +# Integer. Port of the sensu api service +# Default: 4567 +# +# [*dashboard_host*] +# String. Hostname of the dahsboard host +# Default: $::ipaddress +# +# [*dashboard_port*] +# Integer. Port for the sensu dashboard +# Default: 8080 +# +# [*dashboard_user*] +# String. Username to access the dashboard service +# Default: admin +# +# [*dashboard_password*] +# String. Password for dashboard_user +# Default: secret +# +# [*subscriptions*] +# String, Array of strings. Default suscriptions used by the client +# Default: [] +# +# [*client_address*] +# String. Address of the client to report with checks +# Default: $::ipaddress +# +# [*client_name*] +# String. Name of the client to report with checks +# Default: $::fqdn +# +# [*client_custom*] +# Hash. Custom client variables +# Default: {} +# +# [*safe_mode*] +# Boolean. Force safe mode for checks +# Default: false +# Valid values: true, false +# +# [*plugins*] +# String, Array of Strings. Plugins to install on the node +# Default: [] +# +# [*purge_config*] +# Boolean. If unused configs should be removed from the system +# Default: false +# Valid values: true, false +# +# [*use_embedded_ruby*] +# Boolean. If the embedded ruby should be used +# Default: false +# Valid values: true, false +# +# [*rubyopt*] +# String. Ruby opts to be passed to the sensu services +# Default: '' +# +# [*log_level*] +# String. Sensu log level to be used +# Default: 'info' +# Valid values: debug, info, warn, error, fatal # - class sensu ( - $rabbitmq_password = '', - $server = 'false', - $client = 'true', $version = 'latest', - $install_repo = 'true', - $rabbitmq_port = '5671', + $install_repo = true, + $repo = 'main', + $client = true, + $server = false, + $api = false, + $dashboard = false, + $manage_services = true, + $rabbitmq_port = 5671, $rabbitmq_host = 'localhost', $rabbitmq_user = 'sensu', + $rabbitmq_password = '', $rabbitmq_vhost = '/sensu', - $rabbitmq_ssl_private_key = '', - $rabbitmq_ssl_cert_chain = '', + $rabbitmq_ssl_private_key = undef, + $rabbitmq_ssl_cert_chain = undef, $redis_host = 'localhost', - $redis_port = '6379', + $redis_port = 6379, $api_host = 'localhost', - $api_port = '4567', + $api_port = 4567, $dashboard_host = $::ipaddress, - $dashboard_port = '8080', + $dashboard_port = 8080, $dashboard_user = 'admin', $dashboard_password = 'secret', $subscriptions = [], $client_address = $::ipaddress, $client_name = $::fqdn, $client_custom = {}, + $safe_mode = false, $plugins = [], $purge_config = false, $use_embedded_ruby = false, $rubyopt = '', - $safe_mode = false, - $manage_services = true, $log_level = 'info', ){ - anchor {'sensu::begin': } - anchor {'sensu::end': } - - Anchor['sensu::begin'] -> - Class['sensu::package'] -> - Class['sensu::rabbitmq'] - - Class['sensu::rabbitmq'] -> - Class['sensu::server'] ~> - Class['sensu::service::server'] -> - Anchor['sensu::end'] - - Class['sensu::rabbitmq'] -> - Class['sensu::client'] ~> - Class['sensu::service::client'] -> - Anchor['sensu::end'] + $client_real = str2bool($client) + $server_real = str2bool($server) + $api_real = str2bool($api) + $dashboard_real = str2bool($dashboard) + $install_repo_real = str2bool($install_repo) + $purge_config_real = str2bool($purge_config) + $safe_mode_real = str2bool($safe_mode) + $manage_services_real = str2bool($manage_services) + $subscriptions_real = any2array($subscriptions) + validate_re($repo, ['^main$', '^unstable$'], "Repo must be 'main' or 'unstable'. Found: ${repo}") + validate_re($version, ['^absent$', '^installed$', '^latest$', '^present$', '^[\d\.\-]+$'], "Invalid package version: ${version}") + validate_re($log_level, ['^debug$', '^info$', '^warn$', '^error$', '^fatal$'] ) + if !is_integer($rabbitmq_port) { fail('rabbitmq_port must be an integer') } + if !is_integer($redis_port) { fail('redis_port must be an integer') } + if !is_integer($api_port) { fail('api_port must be an integer') } + if !is_integer($dashboard_port) { fail('dashboard_port must be an integer') } - if $manage_services != 'true' and $manage_services != true { - $notify_services = [] - } elsif $server == 'true' or $server == true { - if $client == 'true' or $client == true { - Class['sensu::service::server'] ~> Class['sensu::service::client'] - $notify_services = [ Class['sensu::service::client'], Class['sensu::service::server'] ] - } else { - $notify_services = Class['sensu::service::server'] - } - } elsif $client == 'true' or $client == true { - $notify_services = Class['sensu::service::client'] - } else { - $notify_services = [] - } - class { 'sensu::package': - version => $version, - install_repo => $install_repo, - notify_services => $notify_services, - purge_config => $purge_config, - use_embedded_ruby => $use_embedded_ruby, - rubyopt => $rubyopt, - log_level => $log_level, - } - - class { 'sensu::rabbitmq': - ssl_cert_chain => $rabbitmq_ssl_cert_chain, - ssl_private_key => $rabbitmq_ssl_private_key, - port => $rabbitmq_port, - host => $rabbitmq_host, - user => $rabbitmq_user, - password => $rabbitmq_password, - vhost => $rabbitmq_vhost, - notify_services => $notify_services, - } - - class { 'sensu::server': - redis_host => $redis_host, - redis_port => $redis_port, - api_host => $api_host, - api_port => $api_port, - dashboard_host => $dashboard_host, - dashboard_port => $dashboard_port, - dashboard_user => $dashboard_user, - dashboard_password => $dashboard_password, - enabled => $server, - purge_config => $purge_config, - } - - class { 'sensu::service::server': enabled => $server } - - class { 'sensu::client': - address => $client_address, - subscriptions => $subscriptions, - client_name => $client_name, - enabled => $client, - safe_mode => $safe_mode, - custom => $client_custom, - } - - class { 'sensu::service::client': enabled => $client } + # 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::rabbitmq::config': } -> + class { 'sensu::api::config': } -> + class { 'sensu::redis::config': } -> + class { 'sensu::client::config': } -> + class { 'sensu::dashboard::config': } -> + class { 'sensu::client::service': } -> + class { 'sensu::api::service': } -> + class { 'sensu::server::service': } -> + class { 'sensu::dashboard::service': } -> + anchor {'sensu::end': } sensu::plugin { $plugins: install_path => '/etc/sensu/plugins'} diff --git a/manifests/package.pp b/manifests/package.pp index 9afc2bf4dc..0a0aeb2b04 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -2,47 +2,48 @@ # # Installs the Sensu packages # -# == Parameters -# - -class sensu::package( - $version = 'latest', - $notify_services = [], - $install_repo = 'true', - $purge_config = 'false', - $use_embedded_ruby = 'true', - $rubyopt = '', - $log_level = 'info', -) { +class sensu::package { - if $install_repo == 'true' or $install_repo == true { - include sensu::repo + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") } - package { 'sensu': - ensure => $version, - notify => $notify_services - } + case $::operatingsystem { - if $purge_config { - file { '/etc/sensu/conf.d': - ensure => directory, - purge => true, - recurse => true, - force => true, - require => Package['sensu'] + 'Debian','Ubuntu': { + class { 'sensu::repo::apt': } } + + 'Fedora','RedHat','Centos': { + class { 'sensu::repo::yum': } + } + + default: { alert("${::operatingsystem} not supported yet") } + + } + + package { 'sensu': + ensure => $sensu::version, } - file { 'sensu': + file { '/etc/default/sensu': ensure => file, - path => '/etc/default/sensu', content => template("${module_name}/sensu.erb"), owner => '0', group => '0', - mode => '0644', + mode => '0444', + require => Package['sensu'], + } + + file { [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks' ]: + ensure => directory, + owner => 'sensu', + group => 'sensu', + mode => '0555', + purge => $sensu::purge_config_real, + recurse => true, + force => true, require => Package['sensu'], - notify => $notify_services, } file { ['/etc/sensu/plugins', '/etc/sensu/handlers']: diff --git a/manifests/plugin.pp b/manifests/plugin.pp index 904d997f4e..bd798ef2b9 100644 --- a/manifests/plugin.pp +++ b/manifests/plugin.pp @@ -4,7 +4,35 @@ # # == Parameters # - +# [*type*] +# String. Plugin source +# Default: file +# Valid values: file, directory, package +# +# [*install_path*] +# String. The path to install the plugin +# Default: /etc/sensu/plugins +# +# [*purge*] +# Boolean. When using a directory source, purge setting +# Default: true +# Valid values: true, false +# +# [*recurse*] +# Boolean. When using a directory source, recurse setting +# Default: true +# Valid values: true, false +# +# [*force*] +# Boolean. When using a directory source, force setting +# Default: true +# Valid values: true, false +# +# [*pkg_version*] +# String. When using package source, version to install +# Default: latest +# Valid values: absent, installed, latest, present, [\d\.\-]+ +# define sensu::plugin( $type = 'file', $install_path = '/etc/sensu/plugins', @@ -14,6 +42,9 @@ $pkg_version = 'latest', ){ + validate_bool($purge, $recurse, $force) + validate_re($pkg_version, ['^absent$', '^installed$', '^latest$', '^present$', '^[\d\.\-]+$'], "Invalid package version: ${pkg_version}") + case $type { 'file': { $filename = inline_template("<%= scope.lookupvar('name').split('/').last %>") diff --git a/manifests/rabbitmq.pp b/manifests/rabbitmq.pp deleted file mode 100644 index 5011b6a060..0000000000 --- a/manifests/rabbitmq.pp +++ /dev/null @@ -1,86 +0,0 @@ -# = Class: sensu::rabbitmq -# -# Configures Sensu for RabbitMQ -# -# == Parameters -# - -class sensu::rabbitmq( - $ssl_cert_chain = '', - $ssl_private_key = '', - $port = '5671', - $host = 'localhost', - $user = 'sensu', - $password = '', - $vhost = '/sensu', - $notify_services = '', - ) { - - if !defined(Sensu_rabbitmq_config[$::fqdn]) { - if $ssl_cert_chain != '' { - file { '/etc/sensu/ssl': - ensure => directory, - owner => 'sensu', - group => 'sensu', - mode => '0755', - require => Package['sensu'], - } - - if $ssl_cert_chain =~ /^puppet:\/\// { - file { '/etc/sensu/ssl/cert.pem': - ensure => present, - source => $ssl_cert_chain, - owner => 'sensu', - group => 'sensu', - mode => '0444', - require => File['/etc/sensu/ssl'], - before => Sensu_rabbitmq_config[$::fqdn], - } - - Sensu_rabbitmq_config { - ssl_cert_chain => '/etc/sensu/ssl/cert.pem', - } - } else { - Sensu_rabbitmq_config { - ssl_cert_chain => $ssl_cert_chain, - } - } - - if $ssl_private_key =~ /^puppet:\/\// { - file { '/etc/sensu/ssl/key.pem': - ensure => present, - source => $ssl_private_key, - owner => 'sensu', - group => 'sensu', - mode => '0440', - require => File['/etc/sensu/ssl'], - before => Sensu_rabbitmq_config[$::fqdn], - } - Sensu_rabbitmq_config { - ssl_private_key => '/etc/sensu/ssl/key.pem', - } - } else { - Sensu_rabbitmq_config { - ssl_private_key => $ssl_private_key, - } - } - } - - file { '/etc/sensu/conf.d/rabbitmq.json': - ensure => 'file', - owner => 'sensu', - group => 'sensu', - mode => '0440', - before => Sensu_rabbitmq_config[$::fqdn], - } - - sensu_rabbitmq_config { $::fqdn: - port => $port, - host => $host, - user => $user, - password => $password, - vhost => $vhost, - notify => $notify_services - } - } -} diff --git a/manifests/rabbitmq/config.pp b/manifests/rabbitmq/config.pp new file mode 100644 index 0000000000..c0498f24ea --- /dev/null +++ b/manifests/rabbitmq/config.pp @@ -0,0 +1,81 @@ +# = Class: sensu::rabbitmq::config +# +# Sets the Sensu rabbitmq config +# +class sensu::rabbitmq::config { + + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } + + if $sensu::purge_config_real and !$sensu::server_real and !$sensu::client_real { + $ensure = 'absent' + } else { + $ensure = 'present' + } + + if $sensu::rabbitmq_ssl_cert_chain { + file { '/etc/sensu/ssl': + ensure => directory, + owner => 'sensu', + group => 'sensu', + mode => '0755', + require => Package['sensu'], + } + + if $sensu::rabbitmq_ssl_cert_chain =~ /^puppet:\/\// { + file { '/etc/sensu/ssl/cert.pem': + ensure => present, + source => $sensu::rabbitmq_ssl_cert_chain, + owner => 'sensu', + group => 'sensu', + mode => '0444', + require => File['/etc/sensu/ssl'], + before => Sensu_rabbitmq_config[$::fqdn], + } + + $ssl_cert_chain = '/etc/sensu/ssl/cert.pem' + } else { + $ssl_cert_chain = $sensu::rabbitmq_ssl_cert_chain + } + + if $sensu::rabbitmq_ssl_private_key =~ /^puppet:\/\// { + file { '/etc/sensu/ssl/key.pem': + ensure => present, + source => $sensu::rabbitmq_ssl_private_key, + owner => 'sensu', + group => 'sensu', + mode => '0440', + require => File['/etc/sensu/ssl'], + before => Sensu_rabbitmq_config[$::fqdn], + } + + $ssl_private_key = '/etc/sensu/ssl/key.pem' + } else { + $ssl_private_key = $sensu::rabbitmq_ssl_private_key + } + } else { + $ssl_cert_chain = undef + $ssl_private_key = undef + } + + file { '/etc/sensu/conf.d/rabbitmq.json': + ensure => $ensure, + owner => 'sensu', + group => 'sensu', + mode => '0440', + before => Sensu_rabbitmq_config[$::fqdn], + } + + sensu_rabbitmq_config { $::fqdn: + ensure => $ensure, + port => $sensu::rabbitmq_port, + host => $sensu::rabbitmq_host, + user => $sensu::rabbitmq_user, + password => $sensu::rabbitmq_password, + vhost => $sensu::rabbitmq_vhost, + ssl_cert_chain => $ssl_cert_chain, + ssl_private_key => $ssl_private_key, + } + +} diff --git a/manifests/redis/config.pp b/manifests/redis/config.pp new file mode 100644 index 0000000000..09f7164919 --- /dev/null +++ b/manifests/redis/config.pp @@ -0,0 +1,30 @@ +# = Class: sensu::redis::config +# +# Sets the Sensu redis config +# +class sensu::redis::config { + + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } + + if $sensu::purge_config_real and !$sensu::server_real and !$sensu::api_real and !$sensu::dashboard_real { + $ensure = 'absent' + } else { + $ensure = 'present' + } + + file { '/etc/sensu/conf.d/redis.json': + ensure => $ensure, + owner => 'sensu', + group => 'sensu', + mode => '0444', + } + + sensu_redis_config { $::fqdn: + ensure => $ensure, + host => $sensu::redis_host, + port => $sensu::redis_port, + } + +} diff --git a/manifests/repo.pp b/manifests/repo.pp deleted file mode 100644 index 7a63ba1d66..0000000000 --- a/manifests/repo.pp +++ /dev/null @@ -1,28 +0,0 @@ -# -# Add APT/YUM key and repository based on OS -# -# == Parameters: -# -# $ensure:: 'present' or 'absent' -# $repo:: 'main' or 'unstable' -# -class sensu::repo ( - $ensure = 'present', - $repo = 'main' - ) { - - case $::operatingsystem { - - 'Debian','Ubuntu': { - class { 'sensu::repo::apt': ensure => $ensure, repo => $repo } - } - - 'Fedora','RedHat','Centos': { - class { 'sensu::repo::yum': ensure => $ensure } - } - - default: { alert("${::operatingsystem} not supported yet") } - - } - -} diff --git a/manifests/repo/apt.pp b/manifests/repo/apt.pp index f4e9089601..59dd1a38d4 100644 --- a/manifests/repo/apt.pp +++ b/manifests/repo/apt.pp @@ -1,22 +1,27 @@ # = Class: sensu::repo::apt # -# Adds Sensu repo to Apt +# Adds the Sensu repo to Apt # # == Parameters # +class sensu::repo::apt { -class sensu::repo::apt ( - $ensure = 'present', - $repo = 'main' - ) { + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } if defined(apt::source) and defined(apt::key) { + $ensure = $sensu::install_repo_real ? { + true => 'present', + default => 'absent' + } + apt::source { 'sensu': ensure => $ensure, location => 'http://repos.sensuapp.org/apt', release => 'sensu', - repos => $repo, + repos => $sensu::repo, include_src => false, before => Package['sensu'], } @@ -26,6 +31,8 @@ key_source => 'http://repos.sensuapp.org/apt/pubkey.gpg', } - } else { fail('This class requires puppet-apt module') } + } else { + fail('This class requires puppet-apt module') + } } diff --git a/manifests/repo/yum.pp b/manifests/repo/yum.pp index 457bc841bb..fa8b65863d 100644 --- a/manifests/repo/yum.pp +++ b/manifests/repo/yum.pp @@ -1,26 +1,27 @@ # = Class: sensu::repo::yum # -# Adds Sensu YUM repo support +# Adds the Sensu YUM repo support # -# == Parameters -# - -class sensu::repo::yum ( - $ensure = 'present' - ) { +class sensu::repo::yum { - $enabled = $ensure ? { - 'present' => 1, - default => 'absent' + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") } - yumrepo { 'sensu': - enabled => $enabled, - baseurl => 'http://repos.sensuapp.org/yum/el/$releasever/$basearch/', - gpgcheck => 0, - name => 'sensu', - descr => 'sensu', - before => Package['sensu'], + if $sensu::install_repo_real { + $url = $sensu::repo ? { + 'unstable' => 'http://repos.sensuapp.org/yum-unstable/el/$releasever/$basearch/', + default => 'http://repos.sensuapp.org/yum/el/$releasever/$basearch/' + } + + yumrepo { 'sensu': + enabled => 1, + baseurl => $url, + gpgcheck => 0, + name => 'sensu', + descr => 'sensu', + before => Package['sensu'], + } } } diff --git a/manifests/server.pp b/manifests/server.pp deleted file mode 100644 index 3097088425..0000000000 --- a/manifests/server.pp +++ /dev/null @@ -1,77 +0,0 @@ -# = Class: sensu::server -# -# Builds Sensu servers -# -# == Parameters -# - -class sensu::server( - $redis_host = 'localhost', - $redis_port = '6379', - $api_host = 'localhost', - $api_port = '4567', - $dashboard_host = $::ipaddress, - $dashboard_port = '8080', - $dashboard_user = 'admin', - $dashboard_password = 'secret', - $enabled = 'false', - $purge_config = 'false', -) { - - $ensure = $enabled ? { - 'true' => 'present', - true => 'present', - default => 'absent' - } - - file { '/etc/sensu/conf.d/redis.json': - ensure => $ensure, - owner => 'sensu', - group => 'sensu', - mode => '0444', - } - - file { '/etc/sensu/conf.d/api.json': - ensure => $ensure, - owner => 'sensu', - group => 'sensu', - mode => '0444', - } - - file { '/etc/sensu/conf.d/dashboard.json': - ensure => $ensure, - owner => 'sensu', - group => 'sensu', - mode => '0440', - } - - file { ['/etc/sensu/conf.d/checks', '/etc/sensu/conf.d/handlers']: - ensure => directory, - mode => '0555', - owner => 'sensu', - group => 'sensu', - purge => $purge_config, - recurse => true, - require => Package['sensu'], - } - - sensu_redis_config { $::fqdn: - ensure => $ensure, - host => $redis_host, - port => $redis_port, - } - - sensu_api_config { $::fqdn: - ensure => $ensure, - host => $api_host, - port => $api_port, - } - - sensu_dashboard_config { $::fqdn: - ensure => $ensure, - host => $dashboard_host, - port => $dashboard_port, - user => $dashboard_user, - password => $dashboard_password, - } -} diff --git a/manifests/server/service.pp b/manifests/server/service.pp new file mode 100644 index 0000000000..5286c2005a --- /dev/null +++ b/manifests/server/service.pp @@ -0,0 +1,30 @@ +# = Class: sensu::server::service +# +# Manages the Sensu server service +# +class sensu::server::service { + + if $caller_module_name != $module_name { + fail("Use of private class ${name} by ${caller_module_name}") + } + + if $sensu::manage_services_real { + + case $sensu::server_real { + true: { + $ensure = 'running' + $enable = true + } + default: { + $ensure = 'stopped' + $enable = false + } + } + + service { 'sensu-server': + ensure => $ensure, + enable => $enable, + subscribe => [ Class['sensu::package'], Class['sensu::api::config'], Class['sensu::redis::config'], Class['sensu::rabbitmq::config'] ], + } + } +} diff --git a/manifests/service/client.pp b/manifests/service/client.pp deleted file mode 100644 index fffd83e73c..0000000000 --- a/manifests/service/client.pp +++ /dev/null @@ -1,25 +0,0 @@ -# = Class: sensu::service::client -# -# Manages Sensu client service -# -# == Parameters -# -class sensu::service::client ( - $enabled = 'stopped' -) { - - $real_ensure = $enabled ? { - 'true' => 'running', - true => 'running', - default => 'stopped', - } - - if $sensu::manage_services == 'true' or $sensu::manage_services == true or $sensu::manage_services == undef { - service { 'sensu-client': - ensure => $real_ensure, - enable => $enabled, - hasrestart => true, - } - } - -} diff --git a/manifests/service/server.pp b/manifests/service/server.pp deleted file mode 100644 index a47455f1f4..0000000000 --- a/manifests/service/server.pp +++ /dev/null @@ -1,31 +0,0 @@ -# = Class: sensu::service::server -# -# Manages Sensu server service -# -# == Parameters -# -class sensu::service::server( - $enabled = 'stopped' -) { - - $real_ensure = $enabled ? { - 'true' => 'running', - true => 'running', - default => 'stopped', - } - -if $sensu::manage_services == 'true' or $sensu::manage_services == true or $sensu::manage_services == undef { - - Service { - ensure => $real_ensure, - enable => $enabled, - hasrestart => true, - } - - service { 'sensu-server': } - service { 'sensu-api': } - service { 'sensu-dashboard': } - - } - -} diff --git a/manifests/subscription.pp b/manifests/subscription.pp index bdbd156417..62c7fd03a2 100644 --- a/manifests/subscription.pp +++ b/manifests/subscription.pp @@ -4,11 +4,17 @@ # # == Parameters # - +# [*ensure*] +# String. Whether the check should be present or not +# Default: present +# Valid values: present, absent +# define sensu::subscription ( $ensure = 'present', ) { + validate_re($ensure, ['^present$', '^absent$'] ) + file { "/etc/sensu/conf.d/subscription_${name}.json": ensure => $ensure, owner => 'sensu', @@ -17,6 +23,9 @@ before => Sensu_client_subscription[$name], } - sensu_client_subscription { $name: ensure => $ensure } + sensu_client_subscription { $name: + ensure => $ensure, + notify => Class['sensu::client::service'], + } } diff --git a/spec/classes/sensu_api_spec.rb b/spec/classes/sensu_api_spec.rb new file mode 100644 index 0000000000..8baef5de1b --- /dev/null +++ b/spec/classes/sensu_api_spec.rb @@ -0,0 +1,107 @@ +require 'spec_helper' + +describe 'sensu', :type => :class do + let(:facts) { { :fqdn => 'testhost.domain.com' } } + + context 'without api (default)' do + + context 'config' do + + context 'with server' do + let(:params) { { :server => true } } + it { should contain_file('/etc/sensu/conf.d/api.json').with_ensure('present') } + end + + context 'wtih dashboard' do + let(:params) { { :dashboard => true } } + it { should contain_file('/etc/sensu/conf.d/api.json').with_ensure('present') } + end + + context 'purge config' do + let(:params) { { + :purge_config => true, + :server => false, + :dashboard => false + } } + + it { should contain_file('/etc/sensu/conf.d/api.json').with_ensure('absent') } + + end # purge config + + end # config + + context 'managing services' do + it { should contain_service('sensu-api').with( + :ensure => 'stopped', + :enable => false + )} + end # managing services + + context 'not managing services' do + let(:params) { { :manage_services => false } } + it { should_not contain_service('sensu-api') } + end # not managing services + + end # without api + + context 'with api' do + + context 'config' do + + context 'defaults' do + let(:params) { { :api => true } } + it { should contain_file('/etc/sensu/conf.d/api.json').with_ensure('present') } + it { should contain_sensu_api_config('testhost.domain.com').with( + :ensure => 'present', + :host => 'localhost', + :port => 4567 + ) } + end # defaults + + context 'set config params' do + let(:params) { { + :api => true, + :api_host => 'sensuapi.domain.com', + :api_port => 5678 + } } + it { should contain_sensu_api_config('testhost.domain.com').with( + :ensure => 'present', + :host => 'sensuapi.domain.com', + :port => 5678 + ) } + end # set config params + + context 'purge config' do + let(:params) { { + :purge_config => true, + :api => false, + :server => false, + :dashboard => false, + } } + + it { should contain_file('/etc/sensu/conf.d/api.json').with_ensure('absent') } + + end # purge config + + end # config + + context 'service' do + + context 'managing services' do + let(:params) { { :api => true } } + it { should contain_service('sensu-api').with( + :ensure => 'running', + :enable => true + )} + end # managing services + + context 'not managing services' do + let(:params) { { :api => true, :manage_services => false } } + it { should_not contain_service('sensu-api') } + end # not managing services + + end # service + + end # with api + +end diff --git a/spec/classes/sensu_client_spec.rb b/spec/classes/sensu_client_spec.rb index 544900ae84..f2b979305a 100644 --- a/spec/classes/sensu_client_spec.rb +++ b/spec/classes/sensu_client_spec.rb @@ -1,46 +1,105 @@ require 'spec_helper' -describe 'sensu::client', :type => :class do - let(:title) { 'myclient' } - - context 'defaults' do - let(:facts) { { :ipaddress => '2.3.4.5', :fqdn => 'host.domain.com' } } - - it { should contain_sensu_client_config('host.domain.com').with( - 'client_name' => 'host.domain.com', - 'address' => '2.3.4.5', - 'subscriptions' => [], - 'ensure' => 'present', - 'custom' => {} - ) } - - end - - context 'setting params (enabled)' do - let(:facts) { { :fqdn => 'host.domain.com' } } - let(:params) { { - :address => '1.2.3.4', - :subscriptions => ['all'], - :client_name => 'myclient', - :safe_mode => true, - :custom => { 'bool' => true, 'foo' => 'bar' } - } } - - it { should contain_sensu_client_config('host.domain.com').with( - 'client_name' => 'myclient', - 'address' => '1.2.3.4', - 'subscriptions' => ['all'], - 'ensure' => 'present', - 'safe_mode' => true, - 'custom' => { 'bool' => true, 'foo' => 'bar' } - ) } - - end - - context 'disabled' do - let(:facts) { { :fqdn => 'host.domain.com' } } - let(:params) { { :enabled => false } } - it { should contain_sensu_client_config('host.domain.com').with_ensure('absent') } - end +describe 'sensu', :type => :class do + let(:facts) { { :ipaddress => '2.3.4.5', :fqdn => 'host.domain.com' } } + + context 'with client (default)' do + + context 'config' do + + context 'defaults' do + let(:params) { { :client => true } } + it { should contain_sensu_client_config('host.domain.com').with( + :ensure => 'present', + :client_name => 'host.domain.com', + :address => '2.3.4.5', + :subscriptions => [], + :ensure => 'present', + :custom => {} + ) } + end # defaults + + context 'setting config params' do + let(:params) { { + :client => true, + :client_address => '1.2.3.4', + :subscriptions => ['all'], + :client_name => 'myclient', + :safe_mode => true, + :client_custom => { 'bool' => true, 'foo' => 'bar' } + } } + + it { should contain_sensu_client_config('host.domain.com').with( { + :ensure => 'present', + :client_name => 'myclient', + :address => '1.2.3.4', + :subscriptions => ['all'], + :ensure => 'present', + :safe_mode => true, + :custom => { 'bool' => true, 'foo' => 'bar' } + } ) } + + end # setting config params + + context 'purge config' do + let(:params) { { :purge_config => true } } + it { should contain_file('/etc/sensu/conf.d/client.json').with_ensure('present') } + end # purge config + + end # config + + context 'service' do + + context 'default' do + let(:params) { { :client => true } } + it { should contain_service('sensu-client').with( + :ensure => 'running', + :enable => true, + ) } + end # default + + context 'not managing services' do + let(:params) { { + :client => true, + :manage_services => false, + } } + it { should_not contain_service('sensu-client') } + end # not managing service + + end #service + + end #with client + + context 'without client' do + + context 'config' do + + context 'purge config' do + let(:params) { { :purge_config => true, :client => false } } + it { should contain_file('/etc/sensu/conf.d/client.json').with_ensure('absent') } + end # purge config + + end # config + + context 'service' do + context 'managing services' do + let(:params) { { :client => false } } + it { should contain_service('sensu-client').with( + :ensure => 'stopped', + :enable => false, + ) } + end # managing services + + context 'no client, not managing services' do + let(:params) { { + :client => false, + :manage_services => false, + } } + it { should_not contain_service('sensu-client') } + end #no client, not managing services + + end # service + + end # without client end diff --git a/spec/classes/sensu_dashboard_spec.rb b/spec/classes/sensu_dashboard_spec.rb new file mode 100644 index 0000000000..914751fef0 --- /dev/null +++ b/spec/classes/sensu_dashboard_spec.rb @@ -0,0 +1,96 @@ +require 'spec_helper' + +describe 'sensu', :type => :class do + + context 'without dashboard (default)' do + + context 'managing services' do + it { should contain_service('sensu-dashboard').with( + :ensure => 'stopped', + :enable => false + )} + end # managing services + + context 'not managing services' do + let(:params) { { :manage_services => false } } + it { should_not contain_service('sensu-dashboard') } + end # not managing services + + context 'purge config' do + let(:params) { { + :purge_config => true, + :server => false, + :api => false, + :dashboard => false + } } + + it { should contain_file('/etc/sensu/conf.d/dashboard.json').with_ensure('absent') } + + end # purge config + + end # without dashboard + + context 'with dashboard' do + let(:facts) { { :fqdn => 'test.domain.com', :ipaddress => '1.2.3.4' } } + + context 'config' do + + context 'defaults' do + let(:params) { { :dashboard => true } } + it { should contain_sensu_dashboard_config('test.domain.com').with( + :ensure => 'present', + :host => '1.2.3.4', + :port => 8080, + :user => 'admin', + :password => 'secret' + ) } + end # defaults + + context 'set config params' do + let(:params) { { + :dashboard => true, + :dashboard_host => 'sensu.domain.com', + :dashboard_port => 2345, + :dashboard_user => 'user', + :dashboard_password => 'pass', + } } + it { should contain_sensu_dashboard_config('test.domain.com').with( + :ensure => 'present', + :host => 'sensu.domain.com', + :port => 2345, + :user => 'user', + :password => 'pass' + ) } + end # set config params + + context 'purge config' do + let(:params) { { + :dashboard => true + } } + + it { should contain_file('/etc/sensu/conf.d/dashboard.json').with_ensure('present') } + + end # purge config + + end # config + + context 'service' do + + context 'managing services' do + let(:params) { { :dashboard => true } } + it { should contain_service('sensu-dashboard').with( + :ensure => 'running', + :enable => true + )} + end # managing services + + context 'not managing services' do + let(:params) { { :dashboard => true, :manage_services => false } } + it { should_not contain_service('sensu-dashboard') } + end # not managing services + + end # service + + end # with dashboard + +end diff --git a/spec/classes/sensu_init_spec.rb b/spec/classes/sensu_init_spec.rb index 6e0f55af33..1eb95494fc 100644 --- a/spec/classes/sensu_init_spec.rb +++ b/spec/classes/sensu_init_spec.rb @@ -2,138 +2,7 @@ describe 'sensu', :type => :class do - context 'defaults' do - let(:params) { { :rabbitmq_password => 'asdfjkl' } } - let(:facts) { { :fqdn => 'myhost.domain.com', :ipaddress => '1.2.3.4' } } - - it { should contain_class('sensu::package').with( - 'version' => 'latest', - 'install_repo' => true, - 'notify_services' => 'Class[Sensu::Service::Client]' - )} - - it { should contain_class('sensu::rabbitmq').with( - 'ssl_cert_chain' => '', - 'ssl_private_key' => '', - 'port' => '5671', - 'host' => 'localhost', - 'user' => 'sensu', - 'password' => 'asdfjkl', - 'vhost' => '/sensu', - 'notify_services' => 'Class[Sensu::Service::Client]' - )} - - it { should contain_class('sensu::server').with( - 'redis_host' => 'localhost', - 'redis_port' => '6379', - 'api_host' => 'localhost', - 'api_port' => '4567', - 'dashboard_host' => '1.2.3.4', - 'dashboard_port' => '8080', - 'dashboard_user' => 'admin', - 'dashboard_password' => 'secret', - 'enabled' => 'false' - )} - - it { should contain_class('sensu::client').with( - 'address' => '1.2.3.4', - 'subscriptions' => [], - 'client_name' => 'myhost.domain.com', - 'enabled' => 'true' - )} - - it { should contain_class('sensu::service::server').with_enabled('false') } - it { should contain_class('sensu::service::client').with_enabled('true') } - end - - - context 'setting all params' do - let(:params) { { - :rabbitmq_password => 'asdfjkl', - :server => true, - :client => false, - :version => '0.9.10', - :install_repo => false, - :rabbitmq_port => '1234', - :rabbitmq_host => 'rabbithost', - :rabbitmq_user => 'sensuuser', - :rabbitmq_vhost => '/vhost', - :rabbitmq_ssl_private_key => '/etc/sensu/ssl/key.pem', - :rabbitmq_ssl_cert_chain => '/etc/sensu/ssl/cert.pem', - :redis_host => 'redishost', - :redis_port => '2345', - :api_host => 'apihost', - :api_port => '3456', - :dashboard_host => 'dashhost', - :dashboard_port => '5678', - :dashboard_user => 'dashuser', - :dashboard_password => 'dashpass', - :subscriptions => ['all'], - :client_address => '127.0.0.1', - :client_name => 'myhost', - :plugins => [ 'puppet:///data/plug1', 'puppet:///data/plug2' ] - } } - - it { should contain_class('sensu::package').with( - 'version' => '0.9.10', - 'install_repo' => false, - 'notify_services' => 'Class[Sensu::Service::Server]' - )} - - it { should contain_class('sensu::rabbitmq').with( - 'ssl_cert_chain' => '/etc/sensu/ssl/cert.pem', - 'ssl_private_key' => '/etc/sensu/ssl/key.pem', - 'port' => '1234', - 'host' => 'rabbithost', - 'user' => 'sensuuser', - 'password' => 'asdfjkl', - 'vhost' => '/vhost', - 'notify_services' => 'Class[Sensu::Service::Server]' - )} - - it { should contain_class('sensu::server').with( - 'redis_host' => 'redishost', - 'redis_port' => '2345', - 'api_host' => 'apihost', - 'api_port' => '3456', - 'dashboard_host' => 'dashhost', - 'dashboard_port' => '5678', - 'dashboard_user' => 'dashuser', - 'dashboard_password' => 'dashpass', - 'enabled' => 'true' - )} - - it { should contain_class('sensu::client').with( - 'address' => '127.0.0.1', - 'subscriptions' => ['all'], - 'client_name' => 'myhost', - 'enabled' => 'false' - )} - - it { should contain_class('sensu::service::server').with_enabled('true') } - it { should contain_class('sensu::service::client').with_enabled('false') } - - it { should contain_sensu__plugin('puppet:///data/plug1') } - it { should contain_sensu__plugin('puppet:///data/plug2') } - end - - context 'server and client' do - let(:params) { { :rabbitmq_password => 'asdfjkl', :server => 'true', :client => 'true' } } - let(:facts) { { :fqdn => 'myhost.domain.com', :ipaddress => '1.2.3.4' } } - - it { should contain_class('sensu::rabbitmq').with( - 'notify_services' => ['Class[Sensu::Service::Client]', 'Class[Sensu::Service::Server]'] - )} - end - - context 'neither server nor client' do - let(:params) { { :rabbitmq_password => 'asdfjkl', :server => 'false', :client => 'false' } } - let(:facts) { { :fqdn => 'myhost.domain.com', :ipaddress => '1.2.3.4' } } - - it { should contain_class('sensu::rabbitmq').with( - 'notify_services' => [] - )} - end + it 'should compile' do should create_class('sensu') end end diff --git a/spec/classes/sensu_package_spec.rb b/spec/classes/sensu_package_spec.rb index 51eb33d417..a9c205eea0 100644 --- a/spec/classes/sensu_package_spec.rb +++ b/spec/classes/sensu_package_spec.rb @@ -1,41 +1,116 @@ require 'spec_helper' -describe 'sensu::package', :type => :class do +describe 'sensu' do let(:facts) { { :fqdn => 'testhost.domain.com' } } - context 'defaults' do - it { should create_class('sensu::package') } - it { should include_class('sensu::repo') } - it { should contain_package('sensu').with_ensure('latest') } - it { should contain_file('sensu').with_path('/etc/default/sensu') } - it { should contain_file('/etc/sensu/handlers').with_ensure('directory').with_require('Package[sensu]') } - it { should contain_file('/etc/sensu/plugins').with_ensure('directory').with_require('Package[sensu]') } - it { should contain_file('/etc/sensu/config.json').with_ensure('absent') } - end + context 'package' do + context 'defaults' do + it { should create_class('sensu::package') } + it { should contain_package('sensu').with_ensure('latest') } + it { should contain_file('/etc/default/sensu') } + [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks' ].each do |dir| + it { should contain_file(dir).with( + :ensure => 'directory', + :purge => false + ) } + end + it { should contain_file('/etc/sensu/config.json').with_ensure('absent') } + it { should contain_user('sensu') } + it { should contain_group('sensu') } + end - context 'setting parameters' do - let(:params) { { - :version => '0.9.10', - :install_repo => false, - :notify_services => 'Class[Sensu::Service::Server]' - } } - - it { should_not include_class('sensu::repo') } - it { should contain_package('sensu').with( - 'ensure' => '0.9.10', - 'notify' => 'Class[Sensu::Service::Server]' - ) } - end + context 'setting version' do + let(:params) { { + :version => '0.9.10', + } } + + it { should contain_package('sensu').with( + :ensure => '0.9.10', + ) } + end + + context 'repos' do + + context 'ubuntu' do + let(:facts) { { :operatingsystem => 'Ubuntu' } } + + context 'with puppet-apt installed' do + let(:pre_condition) { [ 'define apt::source ($ensure, $location, $release, $repos, $include_src) {}', 'define apt::key ($key, $key_source) {}' ] } + + context 'default' do + it { should contain_apt__source('sensu').with( + :ensure => 'present', + :location => 'http://repos.sensuapp.org/apt', + :release => 'sensu', + :repos => 'main', + :include_src => false, + :before => 'Package[sensu]' + ) } + + it { should contain_apt__key('sensu').with( + :key => '7580C77F', + :key_source => 'http://repos.sensuapp.org/apt/pubkey.gpg' + ) } + end + + context 'unstable repo' do + let(:params) { { :repo => 'unstable' } } + it { should contain_apt__source('sensu').with_repos('unstable') } + end + + context 'install_repo => false' do + let(:params) { { :install_repo => false, :repo => 'main' } } + it { should contain_apt__source('sensu').with_ensure('absent') } + + it { should contain_apt__key('sensu').with( + :key => '7580C77F', + :key_source => 'http://repos.sensuapp.org/apt/pubkey.gpg' + ) } + end + end + + context 'without puppet-apt installed' do + it { expect { should raise_error(Puppet::Error) } } + end + end + + context 'redhat' do + let(:facts) { { :operatingsystem => 'RedHat' } } + + context 'default' do + it { should contain_yumrepo('sensu').with( + :enabled => 1, + :baseurl => 'http://repos.sensuapp.org/yum/el/$releasever/$basearch/', + :gpgcheck => 0, + :before => 'Package[sensu]' + ) } + end + + context 'unstable repo' do + let(:params) { { :repo => 'unstable' } } + it { should contain_yumrepo('sensu').with(:baseurl => 'http://repos.sensuapp.org/yum-unstable/el/$releasever/$basearch/' )} + end + + context 'install_repo => false' do + let(:params) { { :install_repo => false } } + it { should_not contain_yumrepo('sensu') } + end + end + end + + context 'purge_config' do + let(:params) { { :purge_config => true } } - context 'purge_configs' do - let(:params) { { :purge_config => true } } + [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks' ].each do |dir| + it { should contain_file(dir).with( + :ensure => 'directory', + :purge => true, + :recurse => true, + :force => true + ) } + end - it { should contain_file('/etc/sensu/conf.d/').with( - 'ensure' => 'directory', - 'purge' => 'true', - 'recurse' => 'true', - 'force' => 'true' - ) } + end end end diff --git a/spec/classes/sensu_rabbitmq_spec.rb b/spec/classes/sensu_rabbitmq_spec.rb index 2e9f37873b..286d450edc 100644 --- a/spec/classes/sensu_rabbitmq_spec.rb +++ b/spec/classes/sensu_rabbitmq_spec.rb @@ -1,72 +1,78 @@ require 'spec_helper' -describe 'sensu::rabbitmq', :type => :class do - let(:title) { 'myrabbit' } +describe 'sensu', :type => :class do let(:facts) { { :fqdn => 'hostname.domain.com' } } - - context 'when using local key' do - let(:params) { { - :ssl_cert_chain => '/etc/private/ssl/cert.pem', - :ssl_private_key => '/etc/private/ssl/key.pem', - :port => '1234', - :host => 'myhost', - :user => 'sensuuser', - :password => 'sensupass', - :vhost => '/myvhost', - :notify_services => [] - } } - - it { should_not contain_file('/etc/sensu/ssl/cert.pem') } - it { should_not contain_file('/etc/sensu/ssl/key.pem') } - - it { should contain_sensu_rabbitmq_config('hostname.domain.com').with( - 'port' => '1234', - 'host' => 'myhost', - 'user' => 'sensuuser', - 'password' => 'sensupass', - 'vhost' => '/myvhost', - 'ssl_cert_chain' => '/etc/private/ssl/cert.pem', - 'ssl_private_key' => '/etc/private/ssl/key.pem' - ) } - end - - context 'when using key in puppet' do - let(:params) { { - :ssl_cert_chain => 'puppet:///modules/sensu/cert.pem', - :ssl_private_key => 'puppet:///modules/sensu/key.pem', - :port => '1234', - :host => 'myhost', - :user => 'sensuuser', - :password => 'sensupass', - :vhost => '/myvhost', - :notify_services => ['Class[sensu::service::server]'] - } } - - it { should contain_file('/etc/sensu/ssl').with_ensure('directory') } - it { should contain_file('/etc/sensu/ssl/cert.pem').with_source('puppet:///modules/sensu/cert.pem') } - it { should contain_file('/etc/sensu/ssl/key.pem').with_source('puppet:///modules/sensu/key.pem') } - - it { should contain_sensu_rabbitmq_config('hostname.domain.com').with( - 'port' => '1234', - 'host' => 'myhost', - 'user' => 'sensuuser', - 'password' => 'sensupass', - 'vhost' => '/myvhost', - 'ssl_cert_chain' => '/etc/sensu/ssl/cert.pem', - 'ssl_private_key' => '/etc/sensu/ssl/key.pem', - 'notify' => 'Class[sensu::service::server]' - ) } - end + let(:params) { { :client => true } } + + context 'rabbitmq config' do + context 'no ssl (default)' do + it { should contain_sensu_rabbitmq_config('hostname.domain.com').with( + :ssl_cert_chain => nil, + :ssl_private_key => nil + ) } + + end # no ssl (default) + + context 'when using local key' do + let(:params) { { + :rabbitmq_ssl_cert_chain => '/etc/private/ssl/cert.pem', + :rabbitmq_ssl_private_key => '/etc/private/ssl/key.pem', + :rabbitmq_port => '1234', + :rabbitmq_host => 'myhost', + :rabbitmq_user => 'sensuuser', + :rabbitmq_password => 'sensupass', + :rabbitmq_vhost => '/myvhost', + } } + + it { should_not contain_file('/etc/sensu/ssl/cert.pem') } + it { should_not contain_file('/etc/sensu/ssl/key.pem') } + + it { should contain_sensu_rabbitmq_config('hostname.domain.com').with( + :port => '1234', + :host => 'myhost', + :user => 'sensuuser', + :password => 'sensupass', + :vhost => '/myvhost', + :ssl_cert_chain => '/etc/private/ssl/cert.pem', + :ssl_private_key => '/etc/private/ssl/key.pem' + ) } + end # when using local key + + context 'when using key in puppet' do + let(:params) { { + :rabbitmq_ssl_cert_chain => 'puppet:///modules/sensu/cert.pem', + :rabbitmq_ssl_private_key => 'puppet:///modules/sensu/key.pem', + :rabbitmq_port => '1234', + :rabbitmq_host => 'myhost', + :rabbitmq_user => 'sensuuser', + :rabbitmq_password => 'sensupass', + :rabbitmq_vhost => '/myvhost', + } } + + it { should contain_file('/etc/sensu/ssl').with_ensure('directory') } + it { should contain_file('/etc/sensu/ssl/cert.pem').with_source('puppet:///modules/sensu/cert.pem') } + it { should contain_file('/etc/sensu/ssl/key.pem').with_source('puppet:///modules/sensu/key.pem') } + + it { should contain_sensu_rabbitmq_config('hostname.domain.com').with( + :port => '1234', + :host => 'myhost', + :user => 'sensuuser', + :password => 'sensupass', + :vhost => '/myvhost', + :ssl_cert_chain => '/etc/sensu/ssl/cert.pem', + :ssl_private_key => '/etc/sensu/ssl/key.pem', + ) } + end # when using key in puppet + + context 'purge config' do + let(:params) { { + :purge_config => true, + :server => false, + :client => false + } } + + it { should contain_file('/etc/sensu/conf.d/rabbitmq.json').with_ensure('absent') } + end + end # rabbitmq config end - - - - - - - - - - - diff --git a/spec/classes/sensu_redis_spec.rb b/spec/classes/sensu_redis_spec.rb new file mode 100644 index 0000000000..d534749ba6 --- /dev/null +++ b/spec/classes/sensu_redis_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe 'sensu' do + let(:facts) { { :fqdn => 'testhost.domain.com' } } + + context 'redis config' do + + context 'default settings' do + it { should contain_sensu_redis_config('testhost.domain.com').with( + :host => 'localhost', + :port => 6379 + )} + end # default settings + + context 'be configurable' do + let(:params) { { + :redis_host => 'redis.domain.com', + :redis_port => 1234 + } } + + it { should contain_sensu_redis_config('testhost.domain.com').with( + :host => 'redis.domain.com', + :port => 1234 + )} + end # be configurable + + context 'with server' do + let(:params) { { :server => true } } + it { should contain_file('/etc/sensu/conf.d/redis.json').with_ensure('present') } + end # with server + + context 'with api' do + let(:params) { { :api => true } } + it { should contain_file('/etc/sensu/conf.d/redis.json').with_ensure('present') } + end # with api + + context 'with dashboard' do + let(:params) { { :dashboard => true } } + it { should contain_file('/etc/sensu/conf.d/redis.json').with_ensure('present') } + end # with dashboard + + context 'purge configs' do + let(:params) { { + :purge_config => true, + :server => false, + :api => false, + :dashboard => false, + } } + + it { should contain_file('/etc/sensu/conf.d/redis.json').with_ensure('absent') } + end # purge configs + + end #redis config + +end diff --git a/spec/classes/sensu_repo_apt_spec.rb b/spec/classes/sensu_repo_apt_spec.rb deleted file mode 100644 index 879f5a9ac8..0000000000 --- a/spec/classes/sensu_repo_apt_spec.rb +++ /dev/null @@ -1,51 +0,0 @@ -require 'spec_helper' - -describe 'sensu::repo::apt', :type => :class do - - define 'with puppet-apt installed' do - context 'ensure: present' do - let(:facts) { { :apt::source => true, :apt::key => true } } - let(:params) { { :ensure => 'present', :repo => 'main' } } - it { should contain_apt__source('sensu').with( - 'ensure' => 'present', - 'location' => 'http://repos.sensuapp.org/apt', - 'release' => 'sensu', - 'repos' => 'main', - 'include_src' => false, - 'before' => 'Package[sensu]' - ) } - - it { should contain_apt__key('sensu').with( - 'key' => '7580C77F', - 'key_source' => 'http://repos.sensuapp.org/apt/pubkey.gpg' - ) } - end - - context 'ensure: absent' do - let(:facts) { { :apt::source => true, :apt::key => true } } - let(:params) { { :ensure => 'absent', :repo => 'main' } } - it { should contain_apt__source('sensu').with( - 'ensure' => 'absent', - 'location' => 'http://repos.sensuapp.org/apt', - 'release' => 'sensu', - 'repos' => 'main', - 'include_src' => false, - 'before' => 'Package[sensu]' - ) } - - it { should contain_apt__key('sensu').with( - 'key' => '7580C77F', - 'key_source' => 'http://repos.sensuapp.org/apt/pubkey.gpg' - ) } - end - end - - context 'without puppet-apt installed' do - let(:params) { { :ensure => 'present', :repo => 'main' } } - it { expect { should raise_error(Puppet::Error) } } - end - -end - - -# if defined(apt::source) and defined(apt::key) { diff --git a/spec/classes/sensu_repo_spec.rb b/spec/classes/sensu_repo_spec.rb deleted file mode 100644 index 320d95fe08..0000000000 --- a/spec/classes/sensu_repo_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'spec_helper' - -describe 'sensu::repo', :type => :class do - - it { should create_class('sensu::repo') } - - ['Debian', 'Ubuntu' ].each do |os| - describe "operatingsystem: #{os}" do - let(:facts) { { :operatingsystem => os } } - context 'no params' do - it { should contain_class('sensu::repo::apt').with_ensure('present') } - end - - ['present', 'absent'].each do |state| - context "ensure: #{state}" do - let(:params) { { :ensure => state } } - it { should contain_class('sensu::repo::apt').with_ensure(state) } - end - end - end - end - - ['RedHat', 'CentOS' ].each do |os| - describe "operatingsystem: #{os}" do - let(:facts) { { :operatingsystem => os } } - context 'no params' do - it { should contain_class('sensu::repo::yum').with_ensure('present') } - end - - ['present', 'absent'].each do |state| - context "ensure: #{state}" do - let(:params) { { :ensure => state } } - it { should contain_class('sensu::repo::yum').with_ensure(state) } - end - end - end - end - - describe 'operatingsystem: Darwin' do - let(:facts) { { :operatingsystem => 'Darwin' } } - context 'no params' do - it { expect { should raise_error(Puppet::Error) } } - end - - ['present', 'absent'].each do |state| - context "ensure => #{state}" do - let(:params) { { :ensure => state } } - it { expect { should raise_error(Puppet::Error) } } - end - end - end -end - diff --git a/spec/classes/sensu_repo_yum_spec.rb b/spec/classes/sensu_repo_yum_spec.rb deleted file mode 100644 index 1895f792f4..0000000000 --- a/spec/classes/sensu_repo_yum_spec.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'spec_helper' - -describe 'sensu::repo::yum', :type => :class do - - context 'ensure: present' do - let(:params) { { :ensure => 'present' } } - it { should contain_yumrepo('sensu').with( - 'enabled' => 1, - 'baseurl' => 'http://repos.sensuapp.org/yum/el/$releasever/$basearch/', - 'gpgcheck' => 0, - 'before' => 'Package[sensu]' - ) } - end - - context 'ensure: absent' do - let(:params) { { :ensure => 'absent' } } - it { should contain_yumrepo('sensu').with( - 'enabled' => 'absent', - 'before' => 'Package[sensu]' - ) } - end - - context 'ensure: foo' do - let(:params) { { :ensure => 'foo' } } - it { should contain_yumrepo('sensu').with( - 'enabled' => 'absent', - 'before' => 'Package[sensu]' - ) } - end -end \ No newline at end of file diff --git a/spec/classes/sensu_server_spec.rb b/spec/classes/sensu_server_spec.rb index d71d521738..8aa4cf3362 100644 --- a/spec/classes/sensu_server_spec.rb +++ b/spec/classes/sensu_server_spec.rb @@ -1,85 +1,24 @@ require 'spec_helper' -describe 'sensu::server', :type => :class do +describe 'sensu' do let(:title) { 'sensu::server' } - context 'defaults' do - let(:facts) { { :fqdn => 'testhost.domain.com' } } - it { should contain_sensu_redis_config('testhost.domain.com').with_ensure('absent') } - it { should contain_sensu_api_config('testhost.domain.com').with_ensure('absent') } - it { should contain_sensu_dashboard_config('testhost.domain.com').with_ensure('absent') } - end + context 'without server (default)' do - context 'defaults (enabled)' do - let(:facts) { { :fqdn => 'testhost.domain.com', :ipaddress => '1.2.3.4' } } - let(:params) { { :enabled => 'true' } } - - it { should contain_file('/etc/sensu/conf.d/checks').with_ensure('directory').with_require('Package[sensu]') } - it { should contain_file('/etc/sensu/conf.d/handlers').with_ensure('directory').with_require('Package[sensu]') } - - it { should contain_sensu_redis_config('testhost.domain.com').with( - 'host' => 'localhost', - 'port' => '6379', - 'ensure' => 'present' - ) } - - it { should contain_sensu_api_config('testhost.domain.com').with( - 'host' => 'localhost', - 'port' => '4567', - 'ensure' => 'present' - ) } - - it { should contain_sensu_dashboard_config('testhost.domain.com').with( - 'host' => '1.2.3.4', - 'port' => '8080', - 'user' => 'admin', - 'password' => 'secret', - 'ensure' => 'present' - ) } - - end # Defaults - - context 'setting params (enabled)' do - let(:facts) { { :fqdn => 'testhost.domain.com', :ipaddress => '1.2.3.4' } } - let(:params) { { - :redis_host => 'redishost', - :redis_port => '2345', - :api_host => 'apihost', - :api_port => '3456', - :dashboard_host => 'dashhost', - :dashboard_port => '5678', - :dashboard_user => 'user', - :dashboard_password => 'mypass', - :enabled => 'true' - } } - - it { should contain_sensu_redis_config('testhost.domain.com').with( - 'host' => 'redishost', - 'port' => '2345', - 'ensure' => 'present' + it { should contain_service('sensu-server').with( + :ensure => 'stopped', + :enable => false, ) } + end # without server - it { should contain_sensu_api_config('testhost.domain.com').with( - 'host' => 'apihost', - 'port' => '3456', - 'ensure' => 'present' - ) } + context 'with server' do + let(:params) { { :server => true } } - it { should contain_sensu_dashboard_config('testhost.domain.com').with( - 'host' => 'dashhost', - 'port' => '5678', - 'user' => 'user', - 'password' => 'mypass', - 'ensure' => 'present' + it { should contain_service('sensu-server').with( + :ensure => 'running', + :enable => true, ) } - end # setting params - - context 'purge_configs' do - let(:params) { { :purge_config => true, :enabled => true } } - - it { should contain_file('/etc/sensu/conf.d/redis.json').with_ensure('present') } - it { should contain_file('/etc/sensu/conf.d/api.json').with_ensure('present') } - it { should contain_file('/etc/sensu/conf.d/dashboard.json').with_ensure('present') } - end + end # with server end + diff --git a/spec/classes/sensu_service_client_spec.rb b/spec/classes/sensu_service_client_spec.rb deleted file mode 100644 index 4e8d647055..0000000000 --- a/spec/classes/sensu_service_client_spec.rb +++ /dev/null @@ -1,27 +0,0 @@ -require 'spec_helper' - -describe 'sensu::service::client', :type => :class do - - context 'enabled' do - let(:params) { { :enabled => true } } - - it { should contain_service('sensu-client').with( - 'ensure' => 'running', - 'enable' => true, - 'hasrestart' => true - ) } - - end - - context 'disabled' do - let(:params) { { :enabled => false } } - - it { should contain_service('sensu-client').with( - 'ensure' => 'stopped', - 'enable' => false, - 'hasrestart' => true - ) } - - end - -end diff --git a/spec/classes/sensu_service_server_spec.rb b/spec/classes/sensu_service_server_spec.rb deleted file mode 100644 index bf1b3c75ac..0000000000 --- a/spec/classes/sensu_service_server_spec.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'spec_helper' - -describe 'sensu::service::server', :type => :class do - - context 'enabled' do - let(:params) { { :enabled => 'true' } } - - it { should contain_service('sensu-server').with( - 'ensure' => 'running', - 'enable' => 'true', - 'hasrestart' => true - ) } - - it { should contain_service('sensu-api').with( - 'ensure' => 'running', - 'enable' => 'true', - 'hasrestart' => true - ) } - - it { should contain_service('sensu-dashboard').with( - 'ensure' => 'running', - 'enable' => 'true', - 'hasrestart' => true - ) } - end - - context 'disabled' do - let(:params) { { :enabled => 'false' } } - - it { should contain_service('sensu-server').with( - 'ensure' => 'stopped', - 'enable' => 'false', - 'hasrestart' => true - ) } - - it { should contain_service('sensu-api').with( - 'ensure' => 'stopped', - 'enable' => 'false', - 'hasrestart' => true - ) } - - it { should contain_service('sensu-dashboard').with( - 'ensure' => 'stopped', - 'enable' => 'false', - 'hasrestart' => true - ) } - - end - -end diff --git a/spec/defines/sensu_check_spec.rb b/spec/defines/sensu_check_spec.rb index f68c6cf747..4d532bc6b3 100644 --- a/spec/defines/sensu_check_spec.rb +++ b/spec/defines/sensu_check_spec.rb @@ -8,10 +8,10 @@ let(:params) { { :command => '/etc/sensu/somecommand.rb' } } it { should contain_sensu_check('mycheck').with( - 'command' => '/etc/sensu/somecommand.rb', - 'handlers' => '', - 'interval' => '60', - 'subscribers' => '' + :command => '/etc/sensu/somecommand.rb', + :handlers => '', + :interval => 60, + :subscribers => [] ) } end @@ -20,7 +20,7 @@ let(:params) { { :command => '/etc/sensu/command2.rb', :handlers => ['/handler1', '/handler2'], - :interval => '10', + :interval => 10, :subscribers => ['all'], :custom => { 'a' => 'b', 'array' => [ 'c', 'd']}, :type => 'metric', @@ -30,15 +30,15 @@ } } it { should contain_sensu_check('mycheck').with( - 'command' => '/etc/sensu/command2.rb', - 'handlers' => ['/handler1', '/handler2'], - 'interval' => '10', - 'subscribers' => ['all'], - 'custom' => { 'a' => 'b', 'array' => [ 'c', 'd']}, - 'type' => 'metric', - 'standalone' => true, - 'low_flap_threshold' => '10', - 'high_flap_threshold' => '15' + :command => '/etc/sensu/command2.rb', + :handlers => ['/handler1', '/handler2'], + :interval => 10, + :subscribers => ['all'], + :custom => { 'a' => 'b', 'array' => [ 'c', 'd']}, + :type => 'metric', + :standalone => true, + :low_flap_threshold => 10, + :high_flap_threshold => 15 ) } end @@ -55,32 +55,16 @@ let(:params) { { :command => '/etc/sensu/somecommand.rb' } } it { should contain_sensu_check('mycheck_foobar').with( - 'command' => '/etc/sensu/somecommand.rb', - 'handlers' => '', - 'interval' => '60', - 'subscribers' => '' + :command => '/etc/sensu/somecommand.rb', + :handlers => '', + :interval => '60', + :subscribers => [] ) } it { should contain_file('/etc/sensu/conf.d/checks/mycheck_foobar.json') } end - end - - context 'with brackets in name' do - let(:title) { 'mycheck (foo) bar' } - context 'defaults' do - let(:params) { { :command => '/etc/sensu/somecommand.rb' } } - it { should contain_sensu_check('mycheck_foo_bar').with( - 'command' => '/etc/sensu/somecommand.rb', - 'handlers' => '', - 'interval' => '60', - 'subscribers' => '' - ) } - - it { should contain_file('/etc/sensu/conf.d/checks/mycheck_foo_bar.json') } - end end end - diff --git a/spec/defines/sensu_handler_spec.rb b/spec/defines/sensu_handler_spec.rb index fc0fe5a1f1..457d19df05 100644 --- a/spec/defines/sensu_handler_spec.rb +++ b/spec/defines/sensu_handler_spec.rb @@ -5,29 +5,42 @@ context 'default (present)' do - let(:params) { { :type => 'pipe', :source => 'puppet:///somewhere/mycommand.rb' } } + let(:params) { { + :type => 'pipe', + :command => 'mycommand.rb', + :source => 'puppet:///somewhere/mycommand.rb' + } } it { should contain_file('/etc/sensu/handlers/mycommand.rb').with_source('puppet:///somewhere/mycommand.rb')} it { should contain_sensu_handler('myhandler').with( - 'ensure' => 'present', - 'type' => 'pipe', - 'command' => '/etc/sensu/handlers/mycommand.rb', - 'severities' => ['ok', 'warning', 'critical', 'unknown'] + :ensure => 'present', + :type => 'pipe', + :command => '/etc/sensu/handlers/mycommand.rb', + :severities => ['ok', 'warning', 'critical', 'unknown'] ) } end context 'absent' do let(:facts) { { 'Class[sensu::service::server]' => true } } - let(:params) { { :type => 'pipe', :ensure => 'absent', :source => 'puppet:///somewhere/mycommand.rb' } } + let(:params) { { + :type => 'pipe', + :ensure => 'absent', + :source => 'puppet:///somewhere/mycommand.rb' + } } it { should contain_sensu_handler('myhandler').with_ensure('absent') } end context 'install path' do - let(:params) { { :install_path => '/etc', :source => 'puppet:///mycommand.rb'} } + let(:params) { { + :install_path => '/etc', + :source => 'puppet:///mycommand.rb' + } } it { should contain_file('/etc/mycommand.rb') } end context 'command' do - let(:params) { { :command => '/somewhere/file/script.sh' } } + let(:params) { { + :command => '/somewhere/file/script.sh' + } } it { should contain_sensu_handler('myhandler').with_command('/somewhere/file/script.sh') } end @@ -40,17 +53,17 @@ end context 'handlers' do - let(:params) { { :handlers => ['mailer', 'hipchat'] } } + let(:params) { { :type => 'set', :handlers => ['mailer', 'hipchat'] } } it { should contain_sensu_handler('myhandler').with( - 'ensure' => 'present', - 'type' => 'pipe', - 'handlers' => ['mailer', 'hipchat'], - 'severities' => ['ok', 'warning', 'critical', 'unknown'] + :ensure => 'present', + :type => 'set', + :handlers => ['mailer', 'hipchat'], + :severities => ['ok', 'warning', 'critical', 'unknown'] ) } end context 'exchange' do - let(:params) { { :exchange => { 'type' => 'topic' } } } + let(:params) { { :type => 'amqp', :exchange => { 'type' => 'topic' } } } it { should contain_sensu_handler('myhandler').with_exchange({'type' => 'topic'}) } end @@ -62,7 +75,7 @@ end context 'config' do - let(:params) { { :config => {'param' => 'value'} } } + let(:params) { { :command => 'mycommand.rb', :config => {'param' => 'value'} } } it { should contain_sensu_handler('myhandler').with_config( {'param' => 'value' } ) } end