Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

module rewrite #126

Merged
merged 1 commit into from
Jan 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions manifests/api/config.pp
Original file line number Diff line number Diff line change
@@ -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,
}

}
30 changes: 30 additions & 0 deletions manifests/api/service.pp
Original file line number Diff line number Diff line change
@@ -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'] ]
}
}
}
59 changes: 54 additions & 5 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'] ],
}

}
38 changes: 0 additions & 38 deletions manifests/client.pp

This file was deleted.

33 changes: 33 additions & 0 deletions manifests/client/config.pp
Original file line number Diff line number Diff line change
@@ -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,
}

}
31 changes: 31 additions & 0 deletions manifests/client/service.pp
Original file line number Diff line number Diff line change
@@ -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'] ],
}
}
}
23 changes: 19 additions & 4 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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'],
}

}
34 changes: 34 additions & 0 deletions manifests/dashboard/config.pp
Original file line number Diff line number Diff line change
@@ -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'],

}

}
30 changes: 30 additions & 0 deletions manifests/dashboard/service.pp
Original file line number Diff line number Diff line change
@@ -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'] ]
}
}
}
Loading