Class: AirbrakeHandler
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- AirbrakeHandler
- Defined in:
- lib/airbrake_handler.rb
Constant Summary collapse
- VERSION =
"0.5.0"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#ignore ⇒ Object
Returns the value of attribute ignore.
-
#notify_host ⇒ Object
Returns the value of attribute notify_host.
-
#options ⇒ Object
Returns the value of attribute options.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #airbrake_params ⇒ Object
- #client ⇒ Object
- #ignore_exception?(exception) ⇒ Boolean
-
#initialize(options = {}) ⇒ AirbrakeHandler
constructor
A new instance of AirbrakeHandler.
- #report ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AirbrakeHandler
Returns a new instance of AirbrakeHandler.
27 28 29 30 31 32 33 |
# File 'lib/airbrake_handler.rb', line 27 def initialize( = {}) @api_key = .delete(:api_key) @notify_host = .delete(:notify_host) || nil @ignore = .delete(:ignore) || [] @params = .delete(:params) || {} @options = end |
Instance Attribute Details
#api_key ⇒ Object
Returns the value of attribute api_key.
25 26 27 |
# File 'lib/airbrake_handler.rb', line 25 def api_key @api_key end |
#ignore ⇒ Object
Returns the value of attribute ignore.
25 26 27 |
# File 'lib/airbrake_handler.rb', line 25 def ignore @ignore end |
#notify_host ⇒ Object
Returns the value of attribute notify_host.
25 26 27 |
# File 'lib/airbrake_handler.rb', line 25 def notify_host @notify_host end |
#options ⇒ Object
Returns the value of attribute options.
25 26 27 |
# File 'lib/airbrake_handler.rb', line 25 def @options end |
#params ⇒ Object
Returns the value of attribute params.
25 26 27 |
# File 'lib/airbrake_handler.rb', line 25 def params @params end |
Instance Method Details
#airbrake_params ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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() end |
#client ⇒ Object
66 67 68 69 |
# 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) ⇒ Boolean
43 44 45 46 47 |
# 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.)) end end |
#report ⇒ Object
35 36 37 38 39 40 41 |
# 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 |