From e8eeb8b3450cbda0e31dd06fe0f2d49901c945fa Mon Sep 17 00:00:00 2001 From: Justin Lambert Date: Tue, 26 Feb 2013 14:56:59 -0700 Subject: [PATCH] move each service config to conf.d - no munging config.json --- lib/puppet/provider/sensu_api_config/json.rb | 4 +-- .../provider/sensu_clean_config/json.rb | 30 ------------------- .../provider/sensu_dashboard_config/json.rb | 4 +-- .../provider/sensu_rabbitmq_config/json.rb | 4 +-- .../provider/sensu_redis_config/json.rb | 4 +-- lib/puppet/type/sensu_clean_config.rb | 19 ------------ manifests/package.pp | 2 +- spec/classes/sensu_package_spec.rb | 2 +- 8 files changed, 10 insertions(+), 59 deletions(-) delete mode 100644 lib/puppet/provider/sensu_clean_config/json.rb delete mode 100644 lib/puppet/type/sensu_clean_config.rb diff --git a/lib/puppet/provider/sensu_api_config/json.rb b/lib/puppet/provider/sensu_api_config/json.rb index 48ce173df8..75b4a72ae9 100644 --- a/lib/puppet/provider/sensu_api_config/json.rb +++ b/lib/puppet/provider/sensu_api_config/json.rb @@ -10,7 +10,7 @@ # /etc/sensu/config.json or an empty Hash if the file can not be read. def conf begin - @conf ||= JSON.parse(File.read('/etc/sensu/config.json')) + @conf ||= JSON.parse(File.read('/etc/sensu/conf.d/api.json')) rescue @conf ||= {} end @@ -20,7 +20,7 @@ def conf # # Returns nothing. def flush - File.open('/etc/sensu/config.json', 'w') do |f| + File.open('/etc/sensu/conf.d/api.json', 'w') do |f| f.puts JSON.pretty_generate(@conf) end end diff --git a/lib/puppet/provider/sensu_clean_config/json.rb b/lib/puppet/provider/sensu_clean_config/json.rb deleted file mode 100644 index d378d78430..0000000000 --- a/lib/puppet/provider/sensu_clean_config/json.rb +++ /dev/null @@ -1,30 +0,0 @@ -require 'rubygems' if RUBY_VERSION < '1.9.0' && Puppet.features.rubygems? -require 'json' if Puppet.features.json? - -Puppet::Type.type(:sensu_clean_config).provide(:json) do - confine :feature => :json - - def conf - begin - @conf ||= JSON.parse(File.read('/etc/sensu/config.json')) - rescue - @conf ||= {} - end - end - - def flush - File.open('/etc/sensu/config.json', 'w') do |f| - f.puts JSON.pretty_generate(conf) - end - end - - def destroy - conf.delete 'checks' if @conf.has_key? 'checks' - conf.delete 'handlers' if @conf.has_key? 'handlers' - conf.delete 'client' if @conf.has_key? 'client' - end - - def exists? - conf.has_key? 'checks' or conf.has_key? 'handlers' or conf.has_key? 'client' - end -end diff --git a/lib/puppet/provider/sensu_dashboard_config/json.rb b/lib/puppet/provider/sensu_dashboard_config/json.rb index b8ea85c403..1111729010 100644 --- a/lib/puppet/provider/sensu_dashboard_config/json.rb +++ b/lib/puppet/provider/sensu_dashboard_config/json.rb @@ -6,14 +6,14 @@ def conf begin - @conf ||= JSON.parse(File.read('/etc/sensu/config.json')) + @conf ||= JSON.parse(File.read('/etc/sensu/conf.d/dashboard.json')) rescue @conf ||= {} end end def flush - File.open('/etc/sensu/config.json', 'w') do |f| + File.open('/etc/sensu/conf.d/dashboard.json', 'w') do |f| f.puts JSON.pretty_generate(conf) end end diff --git a/lib/puppet/provider/sensu_rabbitmq_config/json.rb b/lib/puppet/provider/sensu_rabbitmq_config/json.rb index ed1e79db2e..bd739def2b 100644 --- a/lib/puppet/provider/sensu_rabbitmq_config/json.rb +++ b/lib/puppet/provider/sensu_rabbitmq_config/json.rb @@ -6,14 +6,14 @@ def conf begin - @conf ||= JSON.parse(File.read('/etc/sensu/config.json')) + @conf ||= JSON.parse(File.read('/etc/sensu/conf.d/rabbitmq.json')) rescue @conf ||= {} end end def flush - File.open('/etc/sensu/config.json', 'w') do |f| + File.open('/etc/sensu/conf.d/rabbitmq.json', 'w') do |f| f.puts JSON.pretty_generate(conf) end end diff --git a/lib/puppet/provider/sensu_redis_config/json.rb b/lib/puppet/provider/sensu_redis_config/json.rb index 263bed798b..54742c07d3 100644 --- a/lib/puppet/provider/sensu_redis_config/json.rb +++ b/lib/puppet/provider/sensu_redis_config/json.rb @@ -6,14 +6,14 @@ def conf begin - @conf ||= JSON.parse(File.read('/etc/sensu/config.json')) + @conf ||= JSON.parse(File.read('/etc/sensu/conf.d/redis.json')) rescue @conf ||= {} end end def flush - File.open('/etc/sensu/config.json', 'w') do |f| + File.open('/etc/sensu/conf.d/redis.json', 'w') do |f| f.puts JSON.pretty_generate(conf) end end diff --git a/lib/puppet/type/sensu_clean_config.rb b/lib/puppet/type/sensu_clean_config.rb deleted file mode 100644 index 8b93648bbc..0000000000 --- a/lib/puppet/type/sensu_clean_config.rb +++ /dev/null @@ -1,19 +0,0 @@ -Puppet::Type.newtype(:sensu_clean_config) do - @doc = "" - - ensurable do - newvalue(:absent) do - provider.destroy - end - - defaultto :absent - end - - newparam(:name) do - desc "This value has no effect, set it to what ever you want." - end - - autorequire(:package) do - ['sensu'] - end -end diff --git a/manifests/package.pp b/manifests/package.pp index 242c51040d..3d4d4e5363 100644 --- a/manifests/package.pp +++ b/manifests/package.pp @@ -20,5 +20,5 @@ notify => $notify_services } - sensu_clean_config { $::fqdn: } + file { '/etc/sensu/config.json': ensure => absent } } diff --git a/spec/classes/sensu_package_spec.rb b/spec/classes/sensu_package_spec.rb index a2b71b3ee9..584a70e350 100644 --- a/spec/classes/sensu_package_spec.rb +++ b/spec/classes/sensu_package_spec.rb @@ -7,7 +7,7 @@ it { should create_class('sensu::package') } it { should include_class('sensu::repo') } it { should contain_package('sensu').with_ensure('latest') } - it { should contain_sensu_clean_config('testhost.domain.com') } + it { should contain_file('/etc/sensu/config.json').with_ensure('absent') } end context 'setting parameters' do