Class: AirbrakeHandler
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- AirbrakeHandler
- Defined in:
- lib/airbrake_handler.rb
Constant Summary collapse
- VERSION =
"0.3.0"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
Returns the value of attribute api_key.
-
#ignore ⇒ Object
Returns the value of attribute ignore.
-
#options ⇒ Object
Returns the value of attribute options.
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 |
# File 'lib/airbrake_handler.rb', line 27 def initialize(={}) @api_key = .delete(:api_key) @ignore = .delete(:ignore) || [] @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 |
#options ⇒ Object
Returns the value of attribute options.
25 26 27 |
# File 'lib/airbrake_handler.rb', line 25 def @options end |
Instance Method Details
#airbrake_params ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/airbrake_handler.rb', line 47 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() end |
#client ⇒ Object
60 61 62 63 |
# File 'lib/airbrake_handler.rb', line 60 def client raise ArgumentError.new("You must specify Airbrake api key") unless api_key Toadhopper.new(api_key) end |
#ignore_exception?(exception) ⇒ Boolean
41 42 43 44 45 |
# File 'lib/airbrake_handler.rb', line 41 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
33 34 35 36 37 38 39 |
# File 'lib/airbrake_handler.rb', line 33 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 |