Module: Sensu::Plugin::Utils
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 12 13 |
# File 'lib/sensu-plugin/utils.rb', line 5 def config_files if ENV['SENSU_LOADED_TEMPFILE'] IO.read(ENV['SENSU_LOADED_TEMPFILE']).split(':') elsif 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
15 16 17 |
# File 'lib/sensu-plugin/utils.rb', line 15 def load_config(filename) JSON.parse(File.open(filename, 'r').read) rescue Hash.new end |
#net_http_req_class(method) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sensu-plugin/utils.rb', line 35 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
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/sensu-plugin/utils.rb', line 23 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
19 20 21 |
# File 'lib/sensu-plugin/utils.rb', line 19 def settings @settings ||= config_files.map {|f| load_config(f) }.reduce {|a, b| a.deep_merge(b) } end |