-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added flapjack types and config generator
- Loading branch information
Kyrill Poole
committed
Dec 10, 2014
1 parent
3e5e23c
commit 4122d2b
Showing
3 changed files
with
149 additions
and
0 deletions.
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,31 @@ | ||
# = 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', | ||
} | ||
|
||
sensu_flapjack_config { $::fqdn: | ||
ensure => $ensure, | ||
host => $sensu::flapjack_redis_host, | ||
port => $sensu::flapjack_redis_port, | ||
db => $sensu::flapjack_redis_db, | ||
} | ||
|
||
} |