Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updated native types and providers to use base_path/config when puppet i... #176

Merged
merged 1 commit into from
May 1, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions lib/puppet/provider/sensu_api_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_check_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_client_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_client_subscription/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_dashboard_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_filter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_handler/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_rabbitmq_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions lib/puppet/provider/sensu_redis_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_api_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_check_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_client_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_client_subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_dashboard_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/puppet/type/sensu_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_rabbitmq_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 5 additions & 0 deletions lib/puppet/type/sensu_redis_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down