diff --git a/lib/puppet/provider/sensu_api_config/json.rb b/lib/puppet/provider/sensu_api_config/json.rb index 8357860ca0..b008ef7d62 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/conf.d/api.json')) + @conf ||= JSON.parse(File.read(config_file)) rescue @conf ||= {} end @@ -20,7 +20,7 @@ def conf # # Returns nothing. def flush - File.open('/etc/sensu/conf.d/api.json', 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(@conf) end end @@ -57,6 +57,11 @@ def port conf['api']['port'].to_s end + + def config_file + "#{resource[:base_path]}/api.json" + end + # Public: Set the port that the API should listen on. # # Returns nothing. diff --git a/lib/puppet/provider/sensu_check/json.rb b/lib/puppet/provider/sensu_check/json.rb index 061f4a7c6e..0ff1907736 100644 --- a/lib/puppet/provider/sensu_check/json.rb +++ b/lib/puppet/provider/sensu_check/json.rb @@ -20,14 +20,14 @@ def initialize(*args) def conf begin - @conf ||= JSON.parse(File.read("/etc/sensu/conf.d/checks/#{resource[:name]}.json")) + @conf ||= JSON.parse(File.read(config_file)) rescue @conf ||= {} end end def flush - File.open("/etc/sensu/conf.d/checks/#{resource[:name]}.json", 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(conf) end end @@ -76,6 +76,10 @@ def interval conf['checks'][resource[:name]]['interval'].to_s end + def config_file + "#{resource[:base_path]}/#{resource[:name]}.json" + end + def interval=(value) conf['checks'][resource[:name]]['interval'] = value.to_i end diff --git a/lib/puppet/provider/sensu_check_config/json.rb b/lib/puppet/provider/sensu_check_config/json.rb index 04987eafab..15471d7991 100644 --- a/lib/puppet/provider/sensu_check_config/json.rb +++ b/lib/puppet/provider/sensu_check_config/json.rb @@ -12,14 +12,14 @@ def initialize(*args) def conf begin - @conf ||= JSON.parse(File.read("/etc/sensu/conf.d/checks/config_#{resource[:name]}.json")) + @conf ||= JSON.parse(File.read(config_file)) rescue @conf ||= {} end end def flush - File.open("/etc/sensu/conf.d/checks/config_#{resource[:name]}.json", 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(conf) end end @@ -50,6 +50,10 @@ def exists? end end + def config_file + "#{resource[:base_path]}/config_#{resource[:name]}.json" + end + def config conf[resource[:name]] = resource[:config] || {} end diff --git a/lib/puppet/provider/sensu_client_config/json.rb b/lib/puppet/provider/sensu_client_config/json.rb index 1d2c61e7fc..0011c9d031 100644 --- a/lib/puppet/provider/sensu_client_config/json.rb +++ b/lib/puppet/provider/sensu_client_config/json.rb @@ -16,18 +16,22 @@ def initialize(*args) super begin - @conf = JSON.parse(File.read('/etc/sensu/conf.d/client.json')) + @conf = JSON.parse(File.read(config_file)) rescue @conf = {} end end def flush - File.open('/etc/sensu/conf.d/client.json', 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(@conf) end end + def config_file + "#{resource[:base_path]}/client.json" + end + def create @conf['client'] = {} self.client_name = resource[:client_name] diff --git a/lib/puppet/provider/sensu_client_subscription/json.rb b/lib/puppet/provider/sensu_client_subscription/json.rb index 280c4fe9b7..0b11813385 100644 --- a/lib/puppet/provider/sensu_client_subscription/json.rb +++ b/lib/puppet/provider/sensu_client_subscription/json.rb @@ -8,18 +8,22 @@ def initialize(*args) super begin - @conf = JSON.parse(File.read("/etc/sensu/conf.d/subscription_#{resource[:name]}.json")) + @conf = JSON.parse(File.read(config_file)) rescue @conf = {} end end def flush - File.open("/etc/sensu/conf.d/subscription_#{resource[:name]}.json", 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(@conf) end end + def config_file + "#{resource[:base_path]}/subscription_#{resource[:name]}.json" + end + def create @conf['client'] = {'subscriptions' => [ resource[:name] ] } end diff --git a/lib/puppet/provider/sensu_dashboard_config/json.rb b/lib/puppet/provider/sensu_dashboard_config/json.rb index d26c50cc34..6ed2623474 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/conf.d/dashboard.json')) + @conf ||= JSON.parse(File.read(config_file)) rescue @conf ||= {} end end def flush - File.open('/etc/sensu/conf.d/dashboard.json', 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(conf) end end @@ -26,6 +26,10 @@ def create self.password = resource[:password] end + def config_file + "#{resource[:base_path]}/dashboard.json" + end + def destroy conf.delete 'dashboard' end diff --git a/lib/puppet/provider/sensu_filter/json.rb b/lib/puppet/provider/sensu_filter/json.rb index 0aef30df2e..05cfa67b13 100644 --- a/lib/puppet/provider/sensu_filter/json.rb +++ b/lib/puppet/provider/sensu_filter/json.rb @@ -19,14 +19,18 @@ def initialize(*args) def conf begin - @conf ||= JSON.parse(File.read("/etc/sensu/conf.d/filters/#{resource[:name]}.json")) + @conf ||= JSON.parse(File.read(config_file)) rescue @conf ||= {} end end + def config_file + "#{resource[:base_path]}/#{resource[:name]}.json" + end + def flush - File.open("/etc/sensu/conf.d/filters/#{resource[:name]}.json", 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(conf) end end diff --git a/lib/puppet/provider/sensu_handler/json.rb b/lib/puppet/provider/sensu_handler/json.rb index b9cb2bcee4..ffb6563136 100644 --- a/lib/puppet/provider/sensu_handler/json.rb +++ b/lib/puppet/provider/sensu_handler/json.rb @@ -8,14 +8,14 @@ def initialize(*args) super begin - @conf = JSON.parse(File.read("/etc/sensu/conf.d/handlers/#{resource[:name]}.json")) + @conf = JSON.parse(File.read(config_file)) rescue @conf = {} end end def flush - File.open("/etc/sensu/conf.d/handlers/#{resource[:name]}.json", 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(@conf) end end @@ -35,6 +35,10 @@ def create self.filters = resource[:filters] unless resource[:filters].nil? end + def config_file + "#{resource[:base_path]}/#{resource[:name]}.json" + end + def destroy @conf = nil end diff --git a/lib/puppet/provider/sensu_rabbitmq_config/json.rb b/lib/puppet/provider/sensu_rabbitmq_config/json.rb index a6d780f395..7f27c02b53 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/conf.d/rabbitmq.json')) + @conf ||= JSON.parse(File.read(config_file)) rescue @conf ||= {} end end def flush - File.open('/etc/sensu/conf.d/rabbitmq.json', 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(conf) end end @@ -79,6 +79,10 @@ def ssl_cert_chain=(value) end end + def config_file + "#{resource[:base_path]}/rabbitmq.json" + end + def port conf['rabbitmq']['port'].to_s end diff --git a/lib/puppet/provider/sensu_redis_config/json.rb b/lib/puppet/provider/sensu_redis_config/json.rb index d19d7693a5..cd495bd667 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/conf.d/redis.json')) + @conf ||= JSON.parse(File.read(config_file)) rescue @conf ||= {} end end def flush - File.open('/etc/sensu/conf.d/redis.json', 'w') do |f| + File.open(config_file, 'w') do |f| f.puts JSON.pretty_generate(conf) end end @@ -24,6 +24,10 @@ def create self.host = resource[:host] end + def config_file + "#{resource[:base_path]}/redis.json" + end + def destroy conf.delete 'redis' end diff --git a/lib/puppet/type/sensu_api_config.rb b/lib/puppet/type/sensu_api_config.rb index 5f1b40df90..ffc4219c66 100644 --- a/lib/puppet/type/sensu_api_config.rb +++ b/lib/puppet/type/sensu_api_config.rb @@ -38,6 +38,11 @@ def initialize(*args) defaultto 'localhost' end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/' + end + newproperty(:user) do desc "The username used for clients to authenticate against the Sensu API" end diff --git a/lib/puppet/type/sensu_check.rb b/lib/puppet/type/sensu_check.rb index 419a1dee69..f3e83e4c78 100644 --- a/lib/puppet/type/sensu_check.rb +++ b/lib/puppet/type/sensu_check.rb @@ -48,6 +48,11 @@ def initialize(*args) desc "How frequently the check runs in seconds" end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/checks' + end + newproperty(:low_flap_threshold) do desc "A host is determined to be flapping when the percent change is below this threshold." end diff --git a/lib/puppet/type/sensu_check_config.rb b/lib/puppet/type/sensu_check_config.rb index 0811ba2b63..6beb42e8eb 100644 --- a/lib/puppet/type/sensu_check_config.rb +++ b/lib/puppet/type/sensu_check_config.rb @@ -26,6 +26,11 @@ def initialize(*args) desc "The check name to configure" end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/checks' + end + newparam(:config) do desc "Check configuration for the client to use" end diff --git a/lib/puppet/type/sensu_client_config.rb b/lib/puppet/type/sensu_client_config.rb index bd73951f19..25ec53c2f9 100644 --- a/lib/puppet/type/sensu_client_config.rb +++ b/lib/puppet/type/sensu_client_config.rb @@ -43,6 +43,11 @@ def initialize(*args) desc "" end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/' + end + newproperty(:safe_mode, :boolean => true) do desc "Require checks to be defined on server and client" newvalues(:true, :false) diff --git a/lib/puppet/type/sensu_client_subscription.rb b/lib/puppet/type/sensu_client_subscription.rb index 82710f6ce6..e21fb1ac42 100644 --- a/lib/puppet/type/sensu_client_subscription.rb +++ b/lib/puppet/type/sensu_client_subscription.rb @@ -25,6 +25,11 @@ def initialize(*args) desc "The subscription name" end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/' + end + newparam(:subscriptions) do desc "Subscriptions included" defaultto :name diff --git a/lib/puppet/type/sensu_dashboard_config.rb b/lib/puppet/type/sensu_dashboard_config.rb index 0456bcb5ad..b2a7980ef0 100644 --- a/lib/puppet/type/sensu_dashboard_config.rb +++ b/lib/puppet/type/sensu_dashboard_config.rb @@ -43,6 +43,11 @@ def initialize(*args) defaultto 'sensu' end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/' + end + newproperty(:password) do desc "The password to use when connecting to the Sensu Dashboard" end diff --git a/lib/puppet/type/sensu_filter.rb b/lib/puppet/type/sensu_filter.rb index cced30ed43..53ff3aa996 100644 --- a/lib/puppet/type/sensu_filter.rb +++ b/lib/puppet/type/sensu_filter.rb @@ -27,6 +27,10 @@ def initialize(*args) desc "The name of the filter." end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/filters/' + end newparam(:attributes) do desc "" diff --git a/lib/puppet/type/sensu_handler.rb b/lib/puppet/type/sensu_handler.rb index eae6becdbe..b7703c7387 100644 --- a/lib/puppet/type/sensu_handler.rb +++ b/lib/puppet/type/sensu_handler.rb @@ -55,6 +55,11 @@ def insync?(is) defaultto {} end + newparam(:base_path) do + desc "The base path to the client config file" + defaultto '/etc/sensu/conf.d/handlers/' + end + newproperty(:mutator) do desc "Handler specific data massager" end diff --git a/lib/puppet/type/sensu_rabbitmq_config.rb b/lib/puppet/type/sensu_rabbitmq_config.rb index a15d498c24..3458e17413 100644 --- a/lib/puppet/type/sensu_rabbitmq_config.rb +++ b/lib/puppet/type/sensu_rabbitmq_config.rb @@ -27,6 +27,11 @@ def initialize(*args) 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(:ssl_private_key) do desc "The path on disk to the SSL private key needed to connect to RabbitMQ" diff --git a/lib/puppet/type/sensu_redis_config.rb b/lib/puppet/type/sensu_redis_config.rb index 359b4ad125..8b0698641e 100644 --- a/lib/puppet/type/sensu_redis_config.rb +++ b/lib/puppet/type/sensu_redis_config.rb @@ -26,6 +26,11 @@ def initialize(*args) 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 Redis is listening on"