Class: HoptoadHandler

Inherits:
Chef::Handler
  • Object
show all
Defined in:
lib/hoptoad_handler.rb

Constant Summary collapse

VERSION =
"0.1.2"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HoptoadHandler

Returns a new instance of HoptoadHandler.



28
29
30
31
# File 'lib/hoptoad_handler.rb', line 28

def initialize(options={})
  @api_key = options.delete(:api_key)
  @options = options
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



26
27
28
# File 'lib/hoptoad_handler.rb', line 26

def api_key
  @api_key
end

#optionsObject

Returns the value of attribute options.



26
27
28
# File 'lib/hoptoad_handler.rb', line 26

def options
  @options
end

Instance Method Details

#clientObject



55
56
57
58
# File 'lib/hoptoad_handler.rb', line 55

def client
  raise "You must specify Hoptoad api key" unless api_key
  Toadhopper.new(api_key)
end

#hoptoad_paramsObject

TODO: remove to_s when toadhopper will be fixed



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/hoptoad_handler.rb', line 42

def hoptoad_params
  {
    :notifier_name => "Chef Hoptoad Notifier", :notifier_version => VERSION, :notifier_url => "https://github.com/morgoth/hoptoad_handler",
    :component => run_status.node.name, :url => nil, :environment => {},
    :params => {
      :start_time => run_status.start_time.to_s,
      :end_time => run_status.end_time.to_s,
      :elapsed_time => run_status.elapsed_time.to_s,
      :run_list => run_status.node.run_list.to_s
    }
  }.merge(options)
end

#reportObject



33
34
35
36
37
38
39
# File 'lib/hoptoad_handler.rb', line 33

def report
  if run_status.failed?
    Chef::Log.error("Creating Hoptoad exception report")

    client.post!(run_status.exception, hoptoad_params)
  end
end