Skip to content

Commit

Permalink
Merge pull request #60 from jamtur01/realname
Browse files Browse the repository at this point in the history
Realname
  • Loading branch information
jamtur01 committed Mar 26, 2013
2 parents dc4981b + a815060 commit b4bd298
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 267 deletions.
69 changes: 34 additions & 35 deletions lib/puppet/provider/sensu_check/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,22 @@ def initialize(*args)
end

def conf
resource[:realname] = resource[:name] if resource[:realname] == nil
begin
@conf ||= JSON.parse(File.read("/etc/sensu/conf.d/check_#{resource[:realname]}.json"))
@conf ||= JSON.parse(File.read("/etc/sensu/conf.d/checks/#{resource[:name]}.json"))
rescue
@conf ||= {}
end
end

def flush
File.open("/etc/sensu/conf.d/check_#{resource[:realname]}.json", 'w') do |f|
File.open("/etc/sensu/conf.d/checks/#{resource[:name]}.json", 'w') do |f|
f.puts JSON.pretty_generate(conf)
end
end

def create
conf['checks'] = {}
conf['checks'][resource[:realname]] = {}
conf['checks'][resource[:name]] = {}
self.handlers = resource[:handlers]
self.command = resource[:command]
self.interval = resource[:interval]
Expand All @@ -48,130 +47,130 @@ def destroy
end

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

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

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

def handlers
conf['checks'][resource[:realname]]['handlers'] || []
conf['checks'][resource[:name]]['handlers'] || []
end

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

def aggregate
case conf['checks'][resource[:realname]]['aggregate']
case conf['checks'][resource[:name]]['aggregate']
when true
:true
when false
:false
else
conf['checks'][resource[:realname]]['aggregate']
conf['checks'][resource[:name]]['aggregate']
end
end

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

def command
conf['checks'][resource[:realname]]['command']
conf['checks'][resource[:name]]['command']
end

def command=(value)
conf['checks'][resource[:realname]]['command'] = value
conf['checks'][resource[:name]]['command'] = value
end

def subscribers
conf['checks'][resource[:realname]]['subscribers'] || []
conf['checks'][resource[:name]]['subscribers'] || []
end

def subscribers=(value)
conf['checks'][resource[:realname]]['subscribers'] = value
conf['checks'][resource[:name]]['subscribers'] = value
end

def type
conf['checks'][resource[:realname]]['type']
conf['checks'][resource[:name]]['type']
end

def type=(value)
conf['checks'][resource[:realname]]['type'] = value
conf['checks'][resource[:name]]['type'] = value
end

def notification
conf['checks'][resource[:realname]]['notification']
conf['checks'][resource[:name]]['notification']
end

def notification=(value)
conf['checks'][resource[:realname]]['notification'] = value
conf['checks'][resource[:name]]['notification'] = value
end

def refresh
conf['checks'][resource[:realname]]['refresh']
conf['checks'][resource[:name]]['refresh']
end

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

def occurrences
conf['checks'][resource[:realname]]['occurrences']
conf['checks'][resource[:name]]['occurrences']
end

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

def low_flap_threshold
conf['checks'][resource[:realname]]['low_flap_threshold']
conf['checks'][resource[:name]]['low_flap_threshold']
end

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

def high_flap_threshold
conf['checks'][resource[:realname]]['high_flap_threshold']
conf['checks'][resource[:name]]['high_flap_threshold']
end

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

def standalone
case conf['checks'][resource[:realname]]['standalone']
case conf['checks'][resource[:name]]['standalone']
when true
:true
when false
:false
else
conf['checks'][resource[:realname]]['standalone']
conf['checks'][resource[:name]]['standalone']
end
end

def standalone=(value)
case value
when true, 'true', 'True', :true, 1
conf['checks'][resource[:realname]]['standalone'] = true
conf['checks'][resource[:name]]['standalone'] = true
when false, 'false', 'False', :false, 0
conf['checks'][resource[:realname]]['standalone'] = false
conf['checks'][resource[:name]]['standalone'] = false
else
conf['checks'][resource[:realname]]['standalone'] = value
conf['checks'][resource[:name]]['standalone'] = value
end
end
end
43 changes: 0 additions & 43 deletions lib/puppet/provider/sensu_check_config/json.rb

This file was deleted.

4 changes: 2 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/handler_#{resource[:name]}.json"))
@conf = JSON.parse(File.read("/etc/sensu/conf.d/handlers/#{resource[:name]}.json"))
rescue
@conf = {}
end
end

def flush
File.open("/etc/sensu/conf.d/handler_#{resource[:name]}.json", 'w') do |f|
File.open("/etc/sensu/conf.d/handlers/#{resource[:name]}.json", 'w') do |f|
f.puts JSON.pretty_generate(@conf)
end
end
Expand Down
43 changes: 0 additions & 43 deletions lib/puppet/provider/sensu_handler_config/json.rb

This file was deleted.

6 changes: 1 addition & 5 deletions lib/puppet/type/sensu_check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,7 @@ def initialize(*args)
end

newparam(:name) do
desc "Some unique name, not the name of the check."
end

newparam(:realname) do
desc "The name of the check"
desc "The name of the check."
end

newproperty(:aggregate, :boolean => true) do
Expand Down
31 changes: 0 additions & 31 deletions lib/puppet/type/sensu_check_config.rb

This file was deleted.

35 changes: 0 additions & 35 deletions lib/puppet/type/sensu_handler_config.rb

This file was deleted.

Loading

0 comments on commit b4bd298

Please sign in to comment.