Class: HoptoadHandler

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

Constant Summary collapse

VERSION =
"0.1.4"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ HoptoadHandler

Returns a new instance of HoptoadHandler.



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

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

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#clientObject

Raises:

  • (ArgumentError)


53
54
55
56
# File 'lib/hoptoad_handler.rb', line 53

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

#hoptoad_paramsObject



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

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,
      :end_time => run_status.end_time,
      :elapsed_time => run_status.elapsed_time,
      :run_list => run_status.node.run_list.to_s
    }
  }.merge(options)
end

#reportObject



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

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

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