Skip to content

Commit

Permalink
Merge pull request #106 from LarsFronius/master
Browse files Browse the repository at this point in the history
Several fixes
  • Loading branch information
jamtur01 committed Sep 24, 2013
2 parents 5257d8a + 41925b7 commit 74489f6
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 46 deletions.
8 changes: 4 additions & 4 deletions lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ def flush
def create
conf['checks'] = {}
conf['checks'][resource[:name]] = {}
self.handlers = resource[:handlers]
self.command = resource[:command]
self.interval = resource[:interval]
self.subscribers = resource[:subscribers]
# Optional arguments
self.handlers = resource[:handlers] unless resource[:handlers].nil?
self.subscribers = resource[:subscribers] unless resource[:subscribers].nil?
self.type = resource[:type] unless resource[:type].nil?
self.standalone = resource[:standalone] unless resource[:standalone].nil?
self.high_flap_threshold = resource[:high_flap_threshold] unless resource[:high_flap_threshold].nil?
Expand Down Expand Up @@ -83,7 +83,7 @@ def interval=(value)
end

def handlers
conf['checks'][resource[:name]]['handlers'] || []
conf['checks'][resource[:name]]['handlers']
end

def handlers=(value)
Expand All @@ -99,7 +99,7 @@ def command=(value)
end

def subscribers
conf['checks'][resource[:name]]['subscribers'] || []
conf['checks'][resource[:name]]['subscribers']
end

def subscribers=(value)
Expand Down
12 changes: 7 additions & 5 deletions manifests/check.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,26 @@
$command,
$ensure = 'present',
$type = undef,
$handlers = [],
$handlers = undef,
$standalone = true,
$interval = '60',
$subscribers = [],
$subscribers = undef,
$low_flap_threshold = undef,
$high_flap_threshold = undef,
$custom = undef,
) {

file { "/etc/sensu/conf.d/checks/${name}.json":
$check_name = regsubst($name, ' ', '_', 'G')

file { "/etc/sensu/conf.d/checks/${check_name}.json":
ensure => $ensure,
owner => 'sensu',
group => 'sensu',
mode => '0440',
before => Sensu_check[$name],
before => Sensu_check[$check_name],
}

sensu_check { $name:
sensu_check { $check_name:
ensure => $ensure,
type => $type,
standalone => $standalone,
Expand Down
1 change: 1 addition & 0 deletions manifests/package.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
purge => true,
recurse => true,
force => true,
require => Package['sensu']
}
}

Expand Down
94 changes: 57 additions & 37 deletions spec/defines/sensu_check_spec.rb
Original file line number Diff line number Diff line change
@@ -1,50 +1,70 @@
require 'spec_helper'

describe 'sensu::check', :type => :define do
let(:title) { 'mycheck' }
context 'without whitespace in name' do
let(:title) { 'mycheck' }

context 'defaults' do
let(:params) { { :command => '/etc/sensu/somecommand.rb' } }
context 'defaults' do
let(:params) { { :command => '/etc/sensu/somecommand.rb' } }

it { should contain_sensu_check('mycheck').with(
'command' => '/etc/sensu/somecommand.rb',
'handlers' => [],
'interval' => '60',
'subscribers' => []
) }
it { should contain_sensu_check('mycheck').with(
'command' => '/etc/sensu/somecommand.rb',
'handlers' => [],
'interval' => '60',
'subscribers' => []
) }

end
end

context 'setting params' do
let(:params) { {
: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
} }

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'
) }
end

context 'ensure absent' do
let(:params) { { :command => '/etc/sensu/somecommand.rb', :ensure => 'absent' } }

context 'setting params' do
let(:params) { {
: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
} }

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'
) }
it { should contain_sensu_check('mycheck').with_ensure('absent') }
end
end

context 'ensure absent' do
let(:params) { { :command => '/etc/sensu/somecommand.rb', :ensure => 'absent' } }
context 'with whitespace in name' do
let(:title) { 'mycheck foobar' }
context 'defaults' do
let(:params) { { :command => '/etc/sensu/somecommand.rb' } }

it { should contain_sensu_check('mycheck_foobar').with(
'command' => '/etc/sensu/somecommand.rb',
'handlers' => [],
'interval' => '60',
'subscribers' => []
) }

it { should contain_file('/etc/sensu/conf.d/checks/mycheck_foobar.json') }

end

it { should contain_sensu_check('mycheck').with_ensure('absent') }
end

end

0 comments on commit 74489f6

Please sign in to comment.