Skip to content

Commit

Permalink
Merge branch 'notifu_notification' of github.com:bogue1979/sensu-pupp…
Browse files Browse the repository at this point in the history
…et into notifu_notification
  • Loading branch information
Daniel Rossbach committed May 8, 2013
2 parents e57e47e + cee8d5b commit 55bfb78
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 7 deletions.
58 changes: 53 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ or gem on all your nodes.
}
}

### Advanced Example (hiera)
## Advanced Example (hiera)
This example includes the `sensu` class as part of a base class or role
and configures Sensu on each individual node via
[Hiera](http://docs.puppetlabs.com/#hierahiera1).

hiera.yaml
### hiera.yaml

---
:hierarchy:
Expand All @@ -86,7 +86,7 @@ hiera.yaml
:yaml:
:datadir: '/etc/puppet/%{environment}/modules/hieradata'

common.yaml
### common.yaml

sensu::dashboard_port: 8090
sensu::dashboard_password: mysupersecretpassword
Expand All @@ -96,7 +96,7 @@ common.yaml
sensu::rabbitmq_password: password
sensu::rabbitmq_port: 5672

sensu-server.foo.com.yaml
### sensu-server.foo.com.yaml

sensu::server: true

Expand All @@ -111,8 +111,56 @@ site.pp
...
}

## Safe Mode checks

### Including Sensu monitoring in other modules
By default Sensu clients will execute whatever check messages are on the
queue. This is potentially a large security hole.
If you enable the safe_mode parameter, it will require that checks are
defined on the client. If standalone checks are used then defining on
the client is sufficient, otherwise checks will also need to be defined
on the server as well.

A usage example is shown below.

### Sensu server

node 'sensu-server.foo.com' {
class { 'sensu':
rabbitmq_password => 'secret',
server => true,
plugins => [
'puppet:///data/sensu/plugins/ntp.rb',
'puppet:///data/sensu/plugins/postfix.rb'
],
safe_mode => true,
}

...

sensu::check { "diskspace":
command => '/etc/sensu/plugins/system/check-disk.rb',
}


}

### Sensu client

node 'sensu-client.foo.com' {
class { 'sensu':
rabbitmq_password => 'secret',
rabbitmq_host => 'sensu-server.foo.com',
subscriptions => 'sensu-test',
safe_mode => true,
}

sensu::check { "diskspace":
command => '/etc/sensu/plugins/system/check-disk.rb',
}
}


## Including Sensu monitoring in other modules

There are a few different patterns that can be used to include Sensu
monitoring into other modules. One pattern creates a new class that is
Expand Down
10 changes: 10 additions & 0 deletions lib/puppet/provider/sensu_client_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def create
self.client_name = resource[:client_name]
self.address = resource[:address]
self.subscriptions = resource[:subscriptions]
self.safe_mode = resource[:safe_mode]
end

def destroy
Expand Down Expand Up @@ -58,4 +59,13 @@ def subscriptions
def subscriptions=(value)
@conf['client']['subscriptions'] = value
end

def safe_mode
@conf['client']['safe_mode']
end

def safe_mode=(value)
@conf['client']['safe_mode'] = value
end

end
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_client_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ def initialize(*args)
desc ""
end

newproperty(:safe_mode, :boolean => true) do
desc "Require checks to be defined on server and client"
newvalues(:true, :false)
end

autorequire(:package) do
['sensu']
end
Expand Down
2 changes: 2 additions & 0 deletions manifests/client.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
$client_name = $::fqdn,
$enabled = 'true',
$purge_config = 'false',
$safe_mode = false,
) {

$ensure = $enabled ? {
Expand All @@ -27,6 +28,7 @@
client_name => $client_name,
address => $address,
subscriptions => $subscriptions,
safe_mode => $safe_mode,
}

}
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
$plugins = [],
$purge_config = false,
$use_embedded_ruby = false,
$safe_mode = false,
){

Class['sensu::package'] ->
Expand Down Expand Up @@ -102,6 +103,7 @@
client_name => $client_name,
enabled => $client,
purge_config => $purge_config,
safe_mode => $safe_mode,
}

class { 'sensu::service::client': enabled => $client }
Expand Down
6 changes: 4 additions & 2 deletions spec/classes/sensu_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@
let(:params) { {
:address => '1.2.3.4',
:subscriptions => ['all'],
:client_name => 'myclient'
:client_name => 'myclient',
:safe_mode => true
} }

it { should contain_sensu_client_config('host.domain.com').with(
'client_name' => 'myclient',
'address' => '1.2.3.4',
'subscriptions' => ['all'],
'ensure' => 'present'
'ensure' => 'present',
'safe_mode' => true
) }

end
Expand Down

0 comments on commit 55bfb78

Please sign in to comment.