Skip to content

Commit

Permalink
added flapjack types and config generator
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyrill Poole committed Dec 10, 2014
1 parent 3e5e23c commit 4122d2b
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib/puppet/provider/sensu_flapjack_config/json.rb
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
55 changes: 55 additions & 0 deletions lib/puppet/type/sensu_flapjack_config.rb
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
31 changes: 31 additions & 0 deletions manifests/flapjack/config.pp
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,
}

}

0 comments on commit 4122d2b

Please sign in to comment.