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

Fix conf base path #224

Merged
merged 2 commits into from
Aug 16, 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
6 changes: 0 additions & 6 deletions lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
confine :feature => :json
include Puppet_X::Sensu::Totype

def initialize(*args)
super

@conf = nil
end

def conf
begin
@conf ||= JSON.parse(File.read(config_file))
Expand Down
6 changes: 0 additions & 6 deletions lib/puppet/provider/sensu_check_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
Puppet::Type.type(:sensu_check_config).provide(:json) do
confine :feature => :json

def initialize(*args)
super

@conf = nil
end

def conf
begin
@conf ||= JSON.parse(File.read(config_file))
Expand Down
44 changes: 21 additions & 23 deletions lib/puppet/provider/sensu_client_config/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,17 @@
confine :feature => :json
include Puppet_X::Sensu::Totype

def initialize(*args)
super

def conf
begin
@conf = JSON.parse(File.read(config_file))
@conf ||= JSON.parse(File.read(config_file))
rescue
@conf = {}
@conf ||= {}
end
end

def flush
File.open(config_file, 'w') do |f|
f.puts JSON.pretty_generate(@conf)
f.puts JSON.pretty_generate(conf)
end
end

Expand All @@ -33,7 +31,7 @@ def config_file
end

def create
@conf['client'] = {}
conf['client'] = {}
self.client_name = resource[:client_name]
self.address = resource[:address]
self.bind = resource[:bind]
Expand All @@ -47,71 +45,71 @@ def destroy
end

def exists?
@conf.has_key?('client')
conf.has_key?('client')
end

def check_args
['name', 'address', 'subscriptions', 'safe_mode', 'bind']
end

def client_name
@conf['client']['name']
conf['client']['name']
end

def client_name=(value)
@conf['client']['name'] = value
conf['client']['name'] = value
end

def address
@conf['client']['address']
conf['client']['address']
end

def address=(value)
@conf['client']['address'] = value
conf['client']['address'] = value
end

def bind
@conf['client']['bind']
conf['client']['bind']
end

def bind=(value)
@conf['client']['bind'] = value
conf['client']['bind'] = value
end

def subscriptions
@conf['client']['subscriptions'] || []
conf['client']['subscriptions'] || []
end

def subscriptions=(value)
@conf['client']['subscriptions'] = value
conf['client']['subscriptions'] = value
end

def custom
@conf['client'].reject { |k,v| check_args.include?(k) }
conf['client'].reject { |k,v| check_args.include?(k) }
end

def custom=(value)
@conf['client'].delete_if { |k,v| not check_args.include?(k) }
@conf['client'].merge!(to_type(value))
conf['client'].delete_if { |k,v| not check_args.include?(k) }
conf['client'].merge!(to_type(value))
end

def safe_mode
case @conf['client']['safe_mode']
case conf['client']['safe_mode']
when true
:true
when false
:false
else
@conf['client']['safe_mode']
conf['client']['safe_mode']
end
end

def safe_mode=(value)
case value
when true, 'true', 'True', :true, 1
@conf['client']['safe_mode'] = true
conf['client']['safe_mode'] = true
else
@conf['client']['safe_mode'] = false
conf['client']['safe_mode'] = false
end
end

Expand Down
18 changes: 8 additions & 10 deletions lib/puppet/provider/sensu_client_subscription/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,17 @@
Puppet::Type.type(:sensu_client_subscription).provide(:json) do
confine :feature => :json

def initialize(*args)
super

def conf
begin
@conf = JSON.parse(File.read(config_file))
@conf ||= JSON.parse(File.read(config_file))
rescue
@conf = {}
@conf ||= {}
end
end

def flush
File.open(config_file, 'w') do |f|
f.puts JSON.pretty_generate(@conf)
f.puts JSON.pretty_generate(conf)
end
end

Expand All @@ -25,23 +23,23 @@ def config_file
end

def create
@conf['client'] = {'subscriptions' => [ resource[:name] ] }
conf['client'] = {'subscriptions' => [ resource[:name] ] }
end

def destroy
@conf = nil
end

def subscriptions
@conf['client']['subscriptions']
conf['client']['subscriptions']
end

def subscriptions=(value)
@conf['client']['subscriptions'] = value
conf['client']['subscriptions'] = value
end

def exists?
@conf.has_key?('client') && @conf['client'].has_key?('subscriptions')
conf.has_key?('client') && conf['client'].has_key?('subscriptions')
end
end

7 changes: 1 addition & 6 deletions lib/puppet/provider/sensu_filter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
confine :feature => :json
include Puppet_X::Sensu::Totype

def initialize(*args)
super
@conf = nil
end

def conf
begin
@conf ||= JSON.parse(File.read(config_file))
Expand All @@ -42,7 +37,7 @@ def create
end

def destroy
conf = nil
@conf = nil
end

def exists?
Expand Down
58 changes: 28 additions & 30 deletions lib/puppet/provider/sensu_handler/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@
Puppet::Type.type(:sensu_handler).provide(:json) do
confine :feature => :json

def initialize(*args)
super

def conf
begin
@conf = JSON.parse(File.read(config_file))
@conf ||= JSON.parse(File.read(config_file))
rescue
@conf = {}
@conf ||= {}
end
end

def flush
File.open(config_file, 'w') do |f|
f.puts JSON.pretty_generate(@conf)
f.puts JSON.pretty_generate(conf)
end
end

def create
@conf['handlers'] = {}
@conf['handlers'][resource[:name]] = {}
conf['handlers'] = {}
conf['handlers'][resource[:name]] = {}
self.command = resource[:command]
self.type = resource[:type]
# Optional arguments
Expand All @@ -44,85 +42,85 @@ def destroy
end

def exists?
@conf.has_key?('handlers') and @conf['handlers'].has_key?(resource[:name])
conf.has_key?('handlers') and conf['handlers'].has_key?(resource[:name])
end

def command
@conf['handlers'][resource[:name]]['command']
conf['handlers'][resource[:name]]['command']
end

def command=(value)
@conf['handlers'][resource[:name]]['command'] = value
conf['handlers'][resource[:name]]['command'] = value
end

def config
@conf[resource[:name]]
conf[resource[:name]]
end

def config=(value)
@conf[resource[:name]] = value
conf[resource[:name]] = value
end

def exchange
@conf['handlers'][resource[:name]]['exchange']
conf['handlers'][resource[:name]]['exchange']
end

def exchange=(value)
@conf['handlers'][resource[:name]]['exchange'] = value
conf['handlers'][resource[:name]]['exchange'] = value
end

def socket
@conf['handlers'][resource[:name]]['socket']
conf['handlers'][resource[:name]]['socket']
end

def socket=(value)
@conf['handlers'][resource[:name]]['socket'] = value
if @conf['handlers'][resource[:name]]['socket'].has_key?('port')
@conf['handlers'][resource[:name]]['socket']['port'] = @conf['handlers'][resource[:name]]['socket']['port'].to_i
conf['handlers'][resource[:name]]['socket'] = value
if conf['handlers'][resource[:name]]['socket'].has_key?('port')
conf['handlers'][resource[:name]]['socket']['port'] = conf['handlers'][resource[:name]]['socket']['port'].to_i
end
end

def handlers
@conf['handlers'][resource[:name]]['handlers']
conf['handlers'][resource[:name]]['handlers']
end

def handlers=(value)
@conf['handlers'][resource[:name]]['handlers'] = value
conf['handlers'][resource[:name]]['handlers'] = value
end

def mutator
@conf['handlers'][resource[:name]]['mutator']
conf['handlers'][resource[:name]]['mutator']
end

def mutator=(value)
@conf['handlers'][resource[:name]]['mutator'] = value
conf['handlers'][resource[:name]]['mutator'] = value
end

def filters
@conf['filters'][resource[:name]]['filters']
conf['filters'][resource[:name]]['filters']
end

def filters=(value)
if value.is_a?(Array)
@conf['handlers'][resource[:name]]['filters'] = value
conf['handlers'][resource[:name]]['filters'] = value
else
@conf['handlers'][resource[:name]]['filters'] = [ value ]
conf['handlers'][resource[:name]]['filters'] = [ value ]
end
end

def severities
@conf['handlers'][resource[:name]]['severities']
conf['handlers'][resource[:name]]['severities']
end

def severities=(value)
@conf['handlers'][resource[:name]]['severities'] = value
conf['handlers'][resource[:name]]['severities'] = value
end

def type
@conf['handlers'][resource[:name]]['type']
conf['handlers'][resource[:name]]['type']
end

def type=(value)
@conf['handlers'][resource[:name]]['type'] = value
conf['handlers'][resource[:name]]['type'] = value
end
end