Class: SystemdMon::NotificationCentre
- Inherits:
-
Object
- Object
- SystemdMon::NotificationCentre
- Includes:
- Enumerable
- Defined in:
- lib/systemd_mon/notification_centre.rb
Instance Method Summary collapse
- #add_notifier(notifier) ⇒ Object (also: #<<)
- #classes ⇒ Object
- #each ⇒ Object
-
#initialize ⇒ NotificationCentre
constructor
A new instance of NotificationCentre.
- #notify!(notification) ⇒ Object
- #notify_start!(hostname) ⇒ Object
- #notify_stop!(hostname) ⇒ Object
Constructor Details
#initialize ⇒ NotificationCentre
Returns a new instance of NotificationCentre.
8 9 10 |
# File 'lib/systemd_mon/notification_centre.rb', line 8 def initialize self.notifiers = [] end |
Instance Method Details
#add_notifier(notifier) ⇒ Object Also known as: <<
22 23 24 25 26 27 |
# File 'lib/systemd_mon/notification_centre.rb', line 22 def add_notifier(notifier) unless notifier.respond_to?(:notify!) raise NotifierError, "Notifier #{notifier.class} must respond to 'notify!'" end self.notifiers << notifier end |
#classes ⇒ Object
12 13 14 |
# File 'lib/systemd_mon/notification_centre.rb', line 12 def classes notifiers.map(&:class) end |
#each ⇒ Object
16 17 18 19 20 |
# File 'lib/systemd_mon/notification_centre.rb', line 16 def each notifiers.each do |notifier| yield notifier end end |
#notify!(notification) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/systemd_mon/notification_centre.rb', line 51 def notify!(notification) each_notifier do |notifier| Logger.puts "Notifying state change of #{notification.unit.name} via #{notifier.class}" notifier.notify! notification end end |
#notify_start!(hostname) ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/systemd_mon/notification_centre.rb', line 29 def notify_start!(hostname) each_notifier do |notifier| if notifier.respond_to?(:notify_start!) Logger.puts "Notifying SystemdMon start via #{notifier.class}" notifier.notify_start! hostname else Logger.debug { "#{notifier.class} doesn't respond to 'notify_start!', not sending notification" } end end end |
#notify_stop!(hostname) ⇒ Object
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/systemd_mon/notification_centre.rb', line 40 def notify_stop!(hostname) each_notifier do |notifier| if notifier.respond_to?(:notify_stop!) Logger.puts "Notifying SystemdMon stop via #{notifier.class}" notifier.notify_stop! hostname else Logger.debug { "#{notifier.class} doesn't respond to 'notify_start!', not sending notification" } end end end |