Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlambert121 committed Jan 23, 2015
2 parents 4b7b191 + 47a744a commit 737e14a
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 10 deletions.
21 changes: 18 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
## Change Log

### upcoming (2015/01/12 19:01 +00:00)
### upcoming (2015/01/16 16:33 +00:00)
- [1d5c4ce](https://github.com/sensu/sensu-puppet/commit/1d5c4ced29fd4ee7d8ff18ad4a105c3a244984f6) Tagged v1.5.0 (@jamtur01)

### v1.5.0 (2015/01/16 13:27 +00:00)
- [#297](https://github.com/sensu/sensu-puppet/pull/297) Added support for loading and configuring extensions. (@jonathanio)
- [4790352](https://github.com/sensu/sensu-puppet/commit/4790352713bb33d004befffbd85491449bccb02f) Added extra tests to catch JSON configuration error. (@jonathanio)
- [5b7047d](https://github.com/sensu/sensu-puppet/commit/5b7047d715baa5b6d079c3d00e76ebc026d9c13d) Fix error with extension configuration creation. (@jonathanio)
- [a96ebc8](https://github.com/sensu/sensu-puppet/commit/a96ebc8f0a3f19435d4b5c4d7176f7589d867d37) Added support for loading and configuring extensions. (@jonathanio)
- [6f1e9ee](https://github.com/sensu/sensu-puppet/commit/6f1e9ee20b46683267fac4c126bb9e6a426b1031) add ability to specify name and provider for sensu-plugin package (@jlambert121)

### v1.4.0 (2015/01/13 09:01 +00:00)
- [#285](https://github.com/sensu/sensu-puppet/pull/285) Fixes for dependencies and subscribers properties in sensu::check. (@jonathanio)
- [1cbafe7](https://github.com/sensu/sensu-puppet/commit/1cbafe70c9724db901fc278a397e505eb1e11f4d) Added CHANGELOG generated by https://github.com/lalitkapoor/github-changes (@jamtur01)
- [#295](https://github.com/sensu/sensu-puppet/pull/295) enable travis container environment (@jlambert121)
- [95da534](https://github.com/sensu/sensu-puppet/commit/95da534f580effb29a611bce200856c8f426430e) enable travis container environment (@jlambert121)
- [#294](https://github.com/sensu/sensu-puppet/pull/294) update gemfile (@jlambert121)
- [f1095ae](https://github.com/sensu/sensu-puppet/commit/f1095ae97ddf380ff77b0f1e8e1a0667e3d93bc0) update gemfile (@jlambert121)
- [73dfb0e](https://github.com/sensu/sensu-puppet/commit/73dfb0e7b9da478c2d1655de7a7b6330e544be9b) Fixed Spec tests. (@jonathanio)
- [9532e4b](https://github.com/sensu/sensu-puppet/commit/9532e4b0db2065602cf738c507f00c69b370750f) Set subscribers to under instead of empty array. (@jonathanio)
- [7485d9f](https://github.com/sensu/sensu-puppet/commit/7485d9f0a0e47842a7866458f74237c24a379c20) Fix handling of dependencies property. (@jonathanio)
- [#292](https://github.com/sensu/sensu-puppet/pull/292) fix for future parser (@jlambert121)
- [76906ab](https://github.com/sensu/sensu-puppet/commit/76906aba0f9f9c77dff0b87b0a6a96644e4c680e) fix for future parser (@jlambert121)
- [#287](https://github.com/sensu/sensu-puppet/pull/287) enhance acceptance tests, update spec tests (@jlambert121)
Expand Down Expand Up @@ -308,9 +323,9 @@
- [627590d](https://github.com/sensu/sensu-puppet/commit/627590d0dfe7f724b6ce590533fecae661cb9255) set version on dependencies in Modulefile (@antonlindstrom)
- [#106](https://github.com/sensu/sensu-puppet/pull/106) Several fixes (@LarsFronius)
- [#104](https://github.com/sensu/sensu-puppet/pull/104) fix for issue 102 (@jlambert121)
- [61088be](https://github.com/sensu/sensu-puppet/commit/61088becc17e480cdc4ad08d5a25b452b5407a87) Construct correct yum repo URL with facts
- [41925b7](https://github.com/sensu/sensu-puppet/commit/41925b7d73b4cfa8215fea12d6173d066f9c843a) Don't set empty arrays for subscribers/handlers (@LarsFronius)
- [2b09855](https://github.com/sensu/sensu-puppet/commit/2b098551034cd1a25e6f1b69da34ca4372bd872b) Revert "Construct correct yum repo URL with facts" (@jamtur01)
- [41925b7](https://github.com/sensu/sensu-puppet/commit/41925b7d73b4cfa8215fea12d6173d066f9c843a) Don't set empty arrays for subscribers/handlers (@LarsFronius)
- [61088be](https://github.com/sensu/sensu-puppet/commit/61088becc17e480cdc4ad08d5a25b452b5407a87) Construct correct yum repo URL with facts
- [ca08502](https://github.com/sensu/sensu-puppet/commit/ca08502b6300765da8b34d6fb9e4bb72811c9991) fix for issue 102 (@jlambert121)
- [c851fd8](https://github.com/sensu/sensu-puppet/commit/c851fd87a0031be4eca1af5f83468461017e0f98) Revert "Construct correct yum repo URL with facts" (@jamtur01)
- [#103](https://github.com/sensu/sensu-puppet/pull/103) Construct correct yum repo URL with facts (@gregmason)
Expand Down
29 changes: 24 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Installs and manages the open source monitoring framework [Sensu](http://sensuap

## Sensu version supported

The module currently supports Sensu version 0.12 and later. If not explictly stated it should always
The module currently supports Sensu version 0.12 and later. If not explictly stated it should always
support the latest Sensu release. Please log an issue if you identify any incompatibilties.

## Upgrade note
Expand Down Expand Up @@ -54,7 +54,7 @@ Debian & Ubuntu:

## Quick start

Before this puppet module can be used, the following items must be configured on the server.
Before this puppet module can be used, the following items must be configured on the server.

- Install redis
- Install rabbitmq
Expand All @@ -66,7 +66,7 @@ To quickly try out sensu, spin up a test VM with Vagrant that already has these
vagrant up
vagrant status
vagrant ssh sensu-server

You can then access the api

curl http://admin:secret@localhost:4567/info
Expand All @@ -76,12 +76,12 @@ Navigate to `192.168.56.10:3000` to use the uchiwa dashboard

username => uchiwa
password => uchiwa

Navigate to `192.168.56.10:15672` to manage rabbitmq

username => sensu
password => correct-horse-battery-staple

See the [tests directory](https://github.com/sensu/sensu-puppet/tree/vagrant/tests) and [Vagrantfile](https://github.com/sensu/sensu-puppet/blob/vagrant/Vagrantfile) for examples on setting up the prerequisites.


Expand Down Expand Up @@ -290,6 +290,25 @@ This will create the following handler definition for Sensu (server):
}
}

## Extension configuration

sensu::extension {
'an_extension':
source => 'puppet://somewhere/an_extension.rb',
config => {
'foobar_setting' => 'value',
}
}

This will save the extension under /etc/sensu/extensions and create
the following configuration definition for Sensu:

{
"an_extension": {
"foobar_setting": "value"
},
}

### Disable Service Management

If you'd prefer to use an external service management tool such as
Expand Down
45 changes: 45 additions & 0 deletions lib/puppet/provider/sensu_extension/json.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require 'rubygems' if RUBY_VERSION < '1.9.0' && Puppet.version < '3'
require 'json' if Puppet.features.json?

Puppet::Type.type(:sensu_extension).provide(:json) do
confine :feature => :json

def conf
begin
@conf ||= JSON.parse(File.read(config_file))
rescue
@conf ||= {}
end
end

def flush
File.open(config_file, 'w') do |f|
f.puts JSON.pretty_generate(conf)
end
end

def create
conf[resource[:name]] = {}
self.config = resource[:config]
end

def config_file
"#{resource[:base_path]}/#{resource[:name]}.json"
end

def destroy
conf.delete resource[:name]
end

def exists?
conf.has_key? resource[:name]
end

def config
conf[resource[:name]]
end

def config=(value)
conf[resource[:name]] = value
end
end
42 changes: 42 additions & 0 deletions lib/puppet/type/sensu_extension.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
Puppet::Type.newtype(:sensu_extension) do
@doc = ""

def initialize(*args)
super

self[:notify] = [
"Service[sensu-api]",
"Service[sensu-server]",
].select { |ref| catalog.resource(ref) }
end

ensurable do
newvalue(:present) do
provider.create
end

newvalue(:absent) do
provider.destroy
end

defaultto :present
end

newparam(:name) do
desc "This value has no effect, set it to what ever you want."
end

newparam(:base_path) do
desc "The base path to the client config file"
defaultto '/etc/sensu/conf.d/extensions/'
end

newproperty(:config) do
desc "The configuration for this extension"
defaultto {}
end

autorequire(:package) do
['sensu']
end
end
74 changes: 74 additions & 0 deletions manifests/extension.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# = Define: sensu::extension
#
# Defines Sensu extensions
#
# == Parameters
#
# [*ensure*]
# String. Whether the check should be present or not
# Default: present
# Valid values: present, absent
#
# [*source*]
# String. Source of the puppet extension
# Default: undef
#
# [*install_path*]
# String. Path to install the extension
# Default: /etc/sensu/extensions
#
# [*config*]
# Hash. Extension specific config
# Default: undef
#
#
define sensu::extension(
$ensure = 'present',
# Used to install the handler
$source = undef,
$install_path = '/etc/sensu/extensions',
# Handler specific config
$config = {},
) {

validate_re($ensure, ['^present$', '^absent$'] )
validate_re($source, ['^puppet://'] )

if $sensu::client {
$notify_services = Class['sensu::client::service']
} else {
$notify_services = []
}

$filename = inline_template('<%= scope.lookupvar(\'source\').split(\'/\').last %>')
$handler = "${install_path}/${filename}"

$file_ensure = $ensure ? {
'absent' => 'absent',
default => 'file'
}

file { $handler:
ensure => $file_ensure,
owner => 'sensu',
group => 'sensu',
mode => '0555',
source => $source,
}

file { "/etc/sensu/conf.d/extensions/${name}.json":
ensure => $ensure,
owner => 'sensu',
group => 'sensu',
mode => '0444',
before => Sensu_extension[$name],
}

sensu_extension { $name:
ensure => $ensure,
config => $config,
notify => $notify_services,
require => File['/etc/sensu/conf.d/extensions'],
}

}
2 changes: 1 addition & 1 deletion manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
require => Package['sensu'],
}

file { [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks', '/etc/sensu/conf.d/filters' ]:
file { [ '/etc/sensu/conf.d', '/etc/sensu/conf.d/handlers', '/etc/sensu/conf.d/checks', '/etc/sensu/conf.d/filters', '/etc/sensu/conf.d/extensions' ]:
ensure => directory,
owner => 'sensu',
group => 'sensu',
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sensu-sensu",
"version": "1.3.1",
"version": "1.5.0",
"author": "sensu",
"summary": "A module to install the Sensu monitoring framework",
"license": "MIT",
Expand Down
58 changes: 58 additions & 0 deletions spec/defines/sensu_extension_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
require 'spec_helper'

describe 'sensu::extension', :type => :define do
let(:title) { 'myextension' }

context 'default (present)' do
let(:params) { {
:source => 'puppet:///somewhere/mycommand.rb'
} }
it { should contain_file('/etc/sensu/extensions/mycommand.rb').with_source('puppet:///somewhere/mycommand.rb')}
it { should contain_file('/etc/sensu/conf.d/extensions/myextension.json') }
it { should contain_sensu_extension('myextension').with(
:ensure => 'present',
:config => {}
) }
end

context 'absent' do
let(:facts) { { 'Class[sensu::service::server]' => true } }
let(:params) { {
:ensure => 'absent',
:source => 'puppet:///somewhere/mycommand.rb'
} }
it { should contain_sensu_extension('myextension').with_ensure('absent') }
it { should contain_file('/etc/sensu/conf.d/extensions/myextension.json').with_ensure('absent') }
end

context 'install path' do
let(:params) { {
:install_path => '/etc',
:source => 'puppet:///mycommand.rb'
} }
it { should contain_file('/etc/mycommand.rb') }
end

context 'source' do
let(:params) { {
:source => 'puppet:///sensu/extension/script.rb'
} }
it { should contain_file('/etc/sensu/extensions/script.rb').with(
:ensure => 'file',
:source => 'puppet:///sensu/extension/script.rb'
) }
end

context 'source and config' do
let(:params) { {
:source => 'puppet:///sensu/extension/script.rb',
:config => {'param' => 'value'}
} }
it { should contain_file('/etc/sensu/extensions/script.rb').with(
:ensure => 'file',
:source => 'puppet:///sensu/extension/script.rb'
) }
it { should contain_sensu_extension('myextension').with_config( {'param' => 'value'} ) }
end

end

0 comments on commit 737e14a

Please sign in to comment.