Skip to content

Commit

Permalink
refactor class structure
Browse files Browse the repository at this point in the history
  • Loading branch information
jlambert121 committed Feb 25, 2013
1 parent b80f3a4 commit d925b31
Show file tree
Hide file tree
Showing 14 changed files with 417 additions and 232 deletions.
39 changes: 9 additions & 30 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,22 @@
#

class sensu::client(
$rabbitmq_password,
$rabbitmq_ssl_private_key = '',
$rabbitmq_ssl_cert_chain = '',
$rabbitmq_port = '5671',
$rabbitmq_host = 'localhost',
$rabbitmq_user = 'sensu',
$rabbitmq_vhost = '/sensu',
$address = $::ipaddress,
$subscriptions = [],
$client_name = $::fqdn
) {
$address = $::ipaddress,
$subscriptions = [],
$client_name = $::fqdn,
$enabled = true
) {

include sensu::package

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,
vhost => $rabbitmq_vhost,
password => $rabbitmq_password,
$ensure = $enabled ? {
true => 'present',
default => 'absent'
}

sensu_client_config { $::fqdn:
client_name => $client_name,
address => $address,
subscriptions => $subscriptions,
ensure => $ensure
}

service { 'sensu-client':
ensure => running,
enable => true,
hasrestart => true,
require => [
Sensu_rabbitmq_config[$::fqdn],
Sensu_client_config[$::fqdn],
],
}
}
10 changes: 6 additions & 4 deletions manifests/handler.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
#

define sensu::handler(
$type,
$command
) {
$type,
$command,
$ensure = 'present'
) {

sensu_handler_config { $name:
type => $type,
command => $command,
before => Service['sensu-server'],
ensure => $ensure,
notify => Class['sensu::service::server']
}
}
83 changes: 82 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,87 @@
# None.
#

class sensu {
class sensu (
$rabbitmq_password,
$server = false,
$client = true,
$rabbitmq_port = '5671',
$rabbitmq_host = 'localhost',
$rabbitmq_user = 'sensu',
$rabbitmq_vhost = '/sensu',
$rabbitmq_ssl_private_key = '',
$rabbitmq_ssl_cert_chain = '',
$redis_host = 'localhost',
$redis_port = '6379',
$api_host = 'localhost',
$api_port = '4567',
$dashboard_host = $::ipaddress,
$dashboard_port = '8080',
$dashboard_user = 'admin',
$dashboard_password = 'secret',
$subscriptions = [],
$client_address = $::ipaddress,
$client_name = $::fqdn
){

Class['sensu::package'] ->
Class['sensu::rabbitmq']

Class['sensu::rabbitmq'] ->
Class['sensu::server'] ~>
Class['sensu::service::server'] ->
Class['sensu']

Class['sensu::rabbitmq'] ->
Class['sensu::client'] ~>
Class['sensu::service::client'] ->
Class['sensu']

if $server == true {
if $client == true {
$notify_services = [ Class['sensu::service::client'], Class['sensu::service::server'] ]
} else {
$notify_services = Class['sensu::service::server']
}
} elsif $client == true {
$notify_services = Class['sensu::service::client']
} else {
$notify_services = []
}

class { 'sensu::package': }
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
}

class { 'sensu::service::server': enabled => $server }

class { 'sensu::client':
address => $client_address,
subscriptions => $subscriptions,
client_name => $client_name,
enabled => $client
}

class { 'sensu::service::client': enabled => $client }

}
4 changes: 3 additions & 1 deletion manifests/rabbitmq.pp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
$host,
$user,
$password,
$vhost
$vhost,
$notify_services
) {

if !defined(Sensu_rabbitmq_config[$::fqdn]) {
Expand Down Expand Up @@ -71,6 +72,7 @@
user => $user,
password => $password,
vhost => $vhost,
notify => $notify_services
}
}
}
80 changes: 22 additions & 58 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,81 +6,45 @@
#

class sensu::server(
$rabbitmq_password,
$rabbitmq_port = '5671',
$rabbitmq_host = 'localhost',
$rabbitmq_user = 'sensu',
$rabbitmq_vhost = '/sensu',
$rabbitmq_ssl_private_key = '',
$rabbitmq_ssl_cert_chain = '',
$redis_host = 'localhost',
$redis_port = '6379',
$api_host = 'localhost',
$api_port = '4567',
$dashboard_host = $::ipaddress,
$dashboard_port = '8080',
$dashboard_user = 'admin',
$dashboard_password = 'secret',
$ensure = 'present'
) {
include sensu::package

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,
$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
) {

$ensure = $enabled ? {
true => 'present',
false => 'absent'
}

sensu_redis_config { $::fqdn:
host => $redis_host,
port => $redis_port,
host => $redis_host,
port => $redis_port,
ensure => $ensure,
}

sensu_api_config { $::fqdn:
host => $api_host,
port => $api_port,
host => $api_host,
port => $api_port,
ensure => $ensure,
}

sensu_dashboard_config { $::fqdn:
host => $dashboard_host,
port => $dashboard_port,
user => $dashboard_user,
password => $dashboard_password,
}

Service {
ensure => running,
enable => true,
hasrestart => true,
}

service {
'sensu-server':
require => [
Sensu_rabbitmq_config[$::fqdn],
Sensu_redis_config[$::fqdn],
];
'sensu-api':
require => [
Sensu_rabbitmq_config[$::fqdn],
Sensu_api_config[$::fqdn],
Service['sensu-server'],
];
'sensu-dashboard':
require => [
Sensu_rabbitmq_config[$::fqdn],
Sensu_dashboard_config[$::fqdn],
Service['sensu-api'],
];
ensure => $ensure,
}

sensu::handler { 'default':
type => 'pipe',
command => '/etc/sensu/handlers/default',
ensure => $ensure
}

}
16 changes: 16 additions & 0 deletions manifests/service/client.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class sensu::service::client (
$enabled
) {

$real_ensure = $enabled ? {
true => 'running',
false => 'stopped',
}

service { 'sensu-client':
ensure => $real_ensure,
enable => $enabled,
hasrestart => true,
}

}
19 changes: 19 additions & 0 deletions manifests/service/server.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class sensu::service::server(
$enabled
) {

$real_ensure = $enabled ? {
true => 'running',
false => 'stopped',
}

Service {
ensure => $real_enabled,
enable => $enabled,
hasrestart => true,
}

service { 'sensu-server': }
service { 'sensu-api': }
service { 'sensu-dashboard': }
}
Loading

0 comments on commit d925b31

Please sign in to comment.