Skip to content

Commit

Permalink
sensu_check provider: transorm input with munge in type
Browse files Browse the repository at this point in the history
  • Loading branch information
ttarczynski committed Nov 5, 2016
1 parent b331c2c commit 4f1fa9f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 27 deletions.
42 changes: 15 additions & 27 deletions lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ def exists?
end

def interval
conf['checks'][resource[:name]]['interval'].to_s
conf['checks'][resource[:name]]['interval']
end

def config_file
"#{resource[:base_path]}/#{resource[:name]}.json"
end

def interval=(value)
conf['checks'][resource[:name]]['interval'] = value.to_i
conf['checks'][resource[:name]]['interval']
end

def handlers
Expand All @@ -73,19 +73,19 @@ def handlers=(value)
end

def occurrences
conf['checks'][resource[:name]]['occurrences'].to_s
conf['checks'][resource[:name]]['occurrences']
end

def occurrences=(value)
conf['checks'][resource[:name]]['occurrences'] = value.to_i
conf['checks'][resource[:name]]['occurrences'] = value
end

def refresh
conf['checks'][resource[:name]]['refresh'].to_s
conf['checks'][resource[:name]]['refresh']
end

def refresh=(value)
conf['checks'][resource[:name]]['refresh'] = value.to_i
conf['checks'][resource[:name]]['refresh'] = value
end

def command
Expand Down Expand Up @@ -122,19 +122,19 @@ def type=(value)
end

def low_flap_threshold
conf['checks'][resource[:name]]['low_flap_threshold'].to_s
conf['checks'][resource[:name]]['low_flap_threshold']
end

def low_flap_threshold=(value)
conf['checks'][resource[:name]]['low_flap_threshold'] = value.to_i
conf['checks'][resource[:name]]['low_flap_threshold'] = value
end

def high_flap_threshold
conf['checks'][resource[:name]]['high_flap_threshold'].to_s
conf['checks'][resource[:name]]['high_flap_threshold']
end

def high_flap_threshold=(value)
conf['checks'][resource[:name]]['high_flap_threshold'] = value.to_i
conf['checks'][resource[:name]]['high_flap_threshold'] = value
end

def source
Expand All @@ -146,31 +146,19 @@ def source=(value)
end

def timeout
conf['checks'][resource[:name]]['timeout'].to_s
end

def trim num
i, f = num.to_i, num.to_f
i == f ? i : f
conf['checks'][resource[:name]]['timeout']
end

def timeout=(value)
conf['checks'][resource[:name]]['timeout'] = trim(value)
conf['checks'][resource[:name]]['timeout'] = value
end

def aggregate
conf['checks'][resource[:name]]['aggregate']
end

def aggregate=(value)
case value
when true, 'true', 'True', :true, 1
conf['checks'][resource[:name]]['aggregate'] = true
when false, 'false', 'False', :false, 0
conf['checks'][resource[:name]]['aggregate'] = false
else
conf['checks'][resource[:name]]['aggregate'] = value
end
conf['checks'][resource[:name]]['aggregate'] = value
end

def aggregates
Expand Down Expand Up @@ -206,11 +194,11 @@ def standalone=(value)
end

def ttl
conf['checks'][resource[:name]]['ttl'].to_s
conf['checks'][resource[:name]]['ttl']
end

def ttl=(value)
conf['checks'][resource[:name]]['ttl'] = value.to_i
conf['checks'][resource[:name]]['ttl'] = value
end

def subdue
Expand Down
32 changes: 32 additions & 0 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,30 @@ def insync?(is)

newproperty(:high_flap_threshold) do
desc "A host is determined to be flapping when the percent change exceedes this threshold."
munge do |value|
value.to_i
end
end

newproperty(:interval) do
desc "How frequently the check runs in seconds"
munge do |value|
value.to_i
end
end

newproperty(:occurrences) do
desc "The number of event occurrences before the handler should take action."
munge do |value|
value.to_i
end
end

newproperty(:refresh) do
desc "The number of seconds sensu-plugin-aware handlers should wait before taking second action."
munge do |value|
value.to_i
end
end

newparam(:base_path) do
Expand All @@ -73,6 +85,9 @@ def insync?(is)

newproperty(:low_flap_threshold) do
desc "A host is determined to be flapping when the percent change is below this threshold."
munge do |value|
value.to_i
end
end

newproperty(:source) do
Expand Down Expand Up @@ -124,10 +139,24 @@ def insync?(is)

newproperty(:timeout) do
desc "Check timeout in seconds, after it fails"
munge do |value|
i, f = value.to_i, value.to_f
i == f ? i : f
end
end

newproperty(:aggregate) do
desc "Whether check is aggregate"
munge do |value|
case value
when true, 'true', 'True', :true, 1
true
when false, 'false', 'False', :false, 0
false
else
value
end
end
end

newproperty(:aggregates, :array_matching => :all) do
Expand All @@ -152,6 +181,9 @@ def insync?(is)

newproperty(:ttl) do
desc "Check ttl in seconds"
munge do |value|
value.to_i
end
end

autorequire(:package) do
Expand Down

0 comments on commit 4f1fa9f

Please sign in to comment.