Class: AirbrakeHandler

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

Constant Summary collapse

VERSION =
"0.4.0"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ AirbrakeHandler

Returns a new instance of AirbrakeHandler.



27
28
29
30
31
32
# File 'lib/airbrake_handler.rb', line 27

def initialize(options={})
  @api_key = options.delete(:api_key)
  @notify_host = options.delete(:notify_host) || nil
  @ignore = options.delete(:ignore) || []
  @options = options
end

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



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

def api_key
  @api_key
end

#ignoreObject

Returns the value of attribute ignore.



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

def ignore
  @ignore
end

#notify_hostObject

Returns the value of attribute notify_host.



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

def notify_host
  @notify_host
end

#optionsObject

Returns the value of attribute options.



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

def options
  @options
end

Instance Method Details

#airbrake_paramsObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/airbrake_handler.rb', line 48

def airbrake_params
  {
    :notifier_name => "Chef Airbrake Notifier", :notifier_version => VERSION, :notifier_url => "https://github.com/morgoth/airbrake_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

#clientObject

Raises:

  • (ArgumentError)


61
62
63
64
# File 'lib/airbrake_handler.rb', line 61

def client
  raise ArgumentError.new("You must specify Airbrake api key") unless api_key
  Toadhopper.new(api_key, :notify_host => @notify_host)
end

#ignore_exception?(exception) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
45
46
# File 'lib/airbrake_handler.rb', line 42

def ignore_exception?(exception)
  ignore.any? do |ignore_case|
    ignore_case[:class] == exception.class.name && (!ignore_case.key?(:message) || !!ignore_case[:message].match(exception.message))
  end
end

#reportObject



34
35
36
37
38
39
40
# File 'lib/airbrake_handler.rb', line 34

def report
  if run_status.failed? && !ignore_exception?(run_status.exception)
    Chef::Log.error("Creating Airbrake exception report")

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