Module: Sensu::Plugin::Utils
- Included in:
- Handler
- Defined in:
- lib/sensu-plugin/utils.rb
Instance Method Summary collapse
- #config_files ⇒ Object
- #load_config(filename) ⇒ Object
- #net_http_req_class(method) ⇒ Object
- #read_event(file) ⇒ Object
- #settings ⇒ Object
Instance Method Details
#config_files ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/sensu-plugin/utils.rb', line 5 def config_files if ENV['SENSU_CONFIG_FILES'] ENV['SENSU_CONFIG_FILES'].split(':') else ['/etc/sensu/config.json'] + Dir['/etc/sensu/conf.d/**/*.json'] end end |
#load_config(filename) ⇒ Object
13 14 15 |
# File 'lib/sensu-plugin/utils.rb', line 13 def load_config(filename) JSON.parse(File.open(filename, 'r').read) rescue Hash.new end |
#net_http_req_class(method) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sensu-plugin/utils.rb', line 33 def net_http_req_class(method) case method.to_s.upcase when 'GET' Net::HTTP::Get when 'POST' Net::HTTP::Post when 'DELETE' Net::HTTP::Delete when 'PUT' Net::HTTP::Put end end |
#read_event(file) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/sensu-plugin/utils.rb', line 21 def read_event(file) begin @event = ::JSON.parse(file.read) @event['occurrences'] ||= 1 @event['check'] ||= Hash.new @event['client'] ||= Hash.new rescue => e puts 'error reading event: ' + e. exit 0 end end |
#settings ⇒ Object
17 18 19 |
# File 'lib/sensu-plugin/utils.rb', line 17 def settings @settings ||= config_files.map {|f| load_config(f) }.reduce {|a, b| a.deep_merge(b) } end |