class AirbrakeHandler

Constants

VERSION

Attributes

api_key[RW]
ignore[RW]
notify_host[RW]
options[RW]
params[RW]

Public Class Methods

new(options = {}) click to toggle source
# 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) || []
  @params      = options.delete(:params) || {}
  @options     = options
end

Public Instance Methods

airbrake_params() click to toggle source
# File lib/airbrake_handler.rb, line 49
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(params)
  }.merge(options)
end
client() click to toggle source
# File lib/airbrake_handler.rb, line 66
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) click to toggle source
# File lib/airbrake_handler.rb, line 43
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
report() click to toggle source
# File lib/airbrake_handler.rb, line 35
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