diff --git a/lib/puppet/provider/sensu_flapjack_config/json.rb b/lib/puppet/provider/sensu_flapjack_config/json.rb new file mode 100644 index 0000000000..aaf0330acb --- /dev/null +++ b/lib/puppet/provider/sensu_flapjack_config/json.rb @@ -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 diff --git a/lib/puppet/type/sensu_flapjack_config.rb b/lib/puppet/type/sensu_flapjack_config.rb new file mode 100644 index 0000000000..7be601dae0 --- /dev/null +++ b/lib/puppet/type/sensu_flapjack_config.rb @@ -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 diff --git a/manifests/flapjack/config.pp b/manifests/flapjack/config.pp new file mode 100644 index 0000000000..f118be5900 --- /dev/null +++ b/manifests/flapjack/config.pp @@ -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, + } + +}