Skip to content

Commit

Permalink
refactor custom option handling in sensu_check type/provider
Browse files Browse the repository at this point in the history
  • Loading branch information
fpletz committed Jun 20, 2013
1 parent 640b756 commit 41982e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
22 changes: 3 additions & 19 deletions lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,12 @@ def check_args
end

def custom
tmp = {}
conf['checks'][resource[:name]].each do |k,v|
if v.is_a?( Fixnum )
tmp.merge!( k => v.to_s )
else
tmp.merge!( k => v )
end
end
check_args.each do | del_arg |
tmp.delete(del_arg)
end
tmp
conf['checks'][resource[:name]].reject { |k,v| check_args.include?(k) }
end

def custom=(value)
tmp = custom
tmp.each_key do |k|
conf['checks'][resource[:name]].delete(k) unless check_args.include?(k)
end
value.each do | k, v |
conf['checks'][resource[:name]][ k ] = to_type( v )
end
conf['checks'][resource[:name]].delete_if { |k,v| not check_args.include?(k) }
conf['checks'][resource[:name]].merge!(value)
end

def to_type(value)
Expand Down
12 changes: 11 additions & 1 deletion lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,17 @@ def initialize(*args)
end

newproperty(:custom) do
desc "custom variable"
desc "Custom check variables"

def is_to_s(hash = @is)
hash.keys.sort.map {|key| "#{key} => #{hash[key]}"}.join(", ")
end

def should_to_s(hash = @should)
hash.keys.sort.map {|key| "#{key} => #{hash[key]}"}.join(", ")
end

defaultto {}
end

newproperty(:type) do
Expand Down

0 comments on commit 41982e8

Please sign in to comment.