Module: Tocsin
- Defined in:
- lib/tocsin.rb,
lib/tocsin/config.rb,
lib/tocsin/version.rb,
lib/tocsin/notifiers.rb,
lib/tocsin/notifiers/email_notifier.rb
Overview
Library for escalating and logging errors.
Defined Under Namespace
Modules: Notifiers Classes: Config, NotificationJob
Constant Summary collapse
- VERSION =
"0.1.2"
Class Method Summary collapse
- .config ⇒ Object
- .configure {|config| ... } ⇒ Object
- .logger ⇒ Object
-
.notify(options) ⇒ Object
Synonyms for raise_alert when no exception is involved.
-
.raise_alert(exception, options = {}) ⇒ Tocsin::Alert
Raise an alarm and escalate as configured in etc/tocsin.yml.
-
.recipients(alert) ⇒ Object
Determine the recipients per notification method for a particular alert.
- .warn!(options) ⇒ Object
-
.watch(options = {}) ⇒ Object
Watch the yielded block for exceptions, and log one if it’s raised.
-
.watch!(options = {}) ⇒ Object
Same as watch, but re-raises the exception after catching it.
Class Method Details
.config ⇒ Object
88 89 90 |
# File 'lib/tocsin.rb', line 88 def self.config @config ||= Tocsin::Config.new end |
.configure {|config| ... } ⇒ Object
83 84 85 86 |
# File 'lib/tocsin.rb', line 83 def self.configure @config = nil yield config end |
.logger ⇒ Object
96 97 98 |
# File 'lib/tocsin.rb', line 96 def self.logger @logger ||= config.logger end |
.notify(options) ⇒ Object
Synonyms for raise_alert when no exception is involved.
33 34 35 |
# File 'lib/tocsin.rb', line 33 def self.notify() self.raise_alert(nil, {:severity => "notification"}.merge()) end |
.raise_alert(exception, options = {}) ⇒ Tocsin::Alert
Raise an alarm and escalate as configured in etc/tocsin.yml. medium, high, critical, or notification (arbitrary, though) this field.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tocsin.rb', line 18 def self.raise_alert(exception, ={}) urgent = .delete(:now) || .delete(:urgent) || .delete(:synchronous) alert = alert_for(exception, ) begin urgent ? sound(alert) : queue(alert) rescue => e sound cannot_enqueue_alert(e) sound alert end alert end |
.recipients(alert) ⇒ Object
Determine the recipients per notification method for a particular alert.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/tocsin.rb', line 61 def self.recipients(alert) # Each recipient group should look like (where the filter values are regexps): # - category: .* # severity: (critical|high) # recipients: # - [email protected] # notifier: email return {} unless config.recipient_groups recipients_per_notifier = config.recipient_groups.inject({}) do |rec_lists, group| if alert_matches_group(alert, group) notifier = group[:notifier] || Tocsin::Notifiers.default_notifier rec_lists[notifier] ||= [] rec_lists[notifier] += group[:recipients] end rec_lists end recipients_per_notifier.each do |k, v| v.uniq!; v.sort! end # Filter duplicates and sort for sanity end |
.warn!(options) ⇒ Object
37 38 39 |
# File 'lib/tocsin.rb', line 37 def self.warn!() self.raise_alert(nil, ) end |
.watch(options = {}) ⇒ Object
Watch the yielded block for exceptions, and log one if it’s raised.
42 43 44 45 46 47 48 |
# File 'lib/tocsin.rb', line 42 def self.watch(={}) begin yield rescue exception_level => e raise_alert(e, ) end end |
.watch!(options = {}) ⇒ Object
Same as watch, but re-raises the exception after catching it.
51 52 53 54 55 56 57 58 |
# File 'lib/tocsin.rb', line 51 def self.watch!(={}) begin yield rescue exception_level => e raise_alert(e, ) raise e end end |