module Sensu::Plugin::Utils

Public Instance Methods

config_files() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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.message
    exit 0
  end
end
settings() click to toggle source
# 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