-
Notifications
You must be signed in to change notification settings - Fork 289
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #284 from pancentric/master
Flapjack support for puppet
- Loading branch information
Showing
6 changed files
with
219 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
require 'rubygems' if RUBY_VERSION < '1.9.0' && Puppet.version < '3' | ||
require 'json' if Puppet.features.json? | ||
|
||
Puppet::Type.type(:sensu_flapjack_config).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['flapjack'] = {} | ||
self.port = resource[:port] | ||
self.host = resource[:host] | ||
self.db = resource[:db] | ||
end | ||
|
||
def config_file | ||
"#{resource[:base_path]}/flapjack.json" | ||
end | ||
|
||
def destroy | ||
conf.delete 'flapjack' | ||
end | ||
|
||
def exists? | ||
conf.has_key? 'flapjack' | ||
end | ||
|
||
def port | ||
conf['flapjack']['port'].to_s | ||
end | ||
|
||
def port=(value) | ||
conf['flapjack']['port'] = value.to_i | ||
end | ||
|
||
def host | ||
conf['flapjack']['host'] | ||
end | ||
|
||
def host=(value) | ||
conf['flapjack']['host'] = value | ||
end | ||
|
||
def db | ||
conf['flapjack']['db'] | ||
end | ||
|
||
def db=(value) | ||
conf['flapjack']['db'] = value.to_i | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
Puppet::Type.newtype(:sensu_flapjack_config) 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/' | ||
end | ||
|
||
newproperty(:port) do | ||
desc "The port that Flapjack's Redis instance is listening on" | ||
|
||
defaultto '6380' | ||
end | ||
|
||
newproperty(:host) do | ||
desc "The hostname that Flapjack's Redis instance is listening on" | ||
|
||
defaultto 'localhost' | ||
end | ||
|
||
newproperty(:db) do | ||
desc "The Flapjack Redis DB to use" | ||
|
||
defaultto '0' | ||
end | ||
|
||
autorequire(:package) do | ||
['sensu'] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# = Class: sensu::flapjack::config | ||
# | ||
# Sets the Sensu flapjack config | ||
# | ||
class sensu::flapjack::config { | ||
|
||
if $caller_module_name != $module_name { | ||
fail("Use of private class ${name} by ${caller_module_name}") | ||
} | ||
|
||
if $sensu::purge_config and !$sensu::server and !$sensu::api { | ||
$ensure = 'absent' | ||
} else { | ||
$ensure = 'present' | ||
} | ||
|
||
file { '/etc/sensu/conf.d/flapjack.json': | ||
ensure => $ensure, | ||
owner => 'sensu', | ||
group => 'sensu', | ||
mode => '0444', | ||
} | ||
|
||
exec { 'flapjack.rb': | ||
command => 'wget -O /etc/sensu/extensions/flapjack.rb https://raw.githubusercontent.com/sensu/sensu-community-plugins/master/extensions/handlers/flapjack.rb', | ||
creates => '/etc/sensu/extensions/flapjack.rb', | ||
path => '/usr/bin:/usr/sbin:/bin:/usr/local/bin', | ||
before => File['/etc/sensu/extensions/flapjack.rb'], | ||
} | ||
|
||
file { '/etc/sensu/extensions/flapjack.rb': | ||
ensure => $ensure, | ||
owner => 'sensu', | ||
group => 'sensu', | ||
mode => '0444', | ||
} | ||
|
||
sensu_flapjack_config { $::fqdn: | ||
ensure => $ensure, | ||
host => $sensu::flapjack_redis_host, | ||
port => $sensu::flapjack_redis_port, | ||
db => $sensu::flapjack_redis_db, | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
require 'spec_helper' | ||
|
||
describe 'sensu' do | ||
let(:facts) { { :fqdn => 'testhost.domain.com', :osfamily => 'RedHat' } } | ||
|
||
context 'flapjack config' do | ||
|
||
context 'default settings' do | ||
it { should contain_sensu_flapjack_config('testhost.domain.com').with( | ||
:host => 'localhost', | ||
:port => 6380 | ||
)} | ||
end # default settings | ||
|
||
context 'be configurable' do | ||
let(:params) { { | ||
:flapjack_redis_host => 'flapjack.domain.com', | ||
:flapjack_redis_port => 1234, | ||
:flapjack_redis_db => 2 | ||
} } | ||
|
||
it { should contain_sensu_flapjack_config('testhost.domain.com').with( | ||
:host => 'flapjack.domain.com', | ||
:port => 1234, | ||
:db => 2 | ||
)} | ||
end # be configurable | ||
|
||
context 'with server' do | ||
let(:params) { { :server => true } } | ||
it { should contain_file('/etc/sensu/conf.d/flapjack.json').with_ensure('present') } | ||
end # with server | ||
|
||
context 'with api' do | ||
let(:params) { { :api => true } } | ||
it { should contain_file('/etc/sensu/conf.d/flapjack.json').with_ensure('present') } | ||
end # with api | ||
|
||
context 'purge configs' do | ||
let(:params) { { | ||
:purge_config => true, | ||
:server => false, | ||
:api => false, | ||
} } | ||
|
||
it { should contain_file('/etc/sensu/conf.d/flapjack.json').with_ensure('absent') } | ||
end # purge configs | ||
|
||
end #flapjack config | ||
|
||
end |