diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-17 21:26:49 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2012-04-17 21:26:49 +0100 |
commit | 4c99233f3b3112cd2be5ab6fd5d6e7c1c344406b (patch) | |
tree | ca5a7c3659b5aa3be4ecf40af95ef24870c09e7c /lib | |
parent | 3a579efcd3ea7e4362f7abeb4138c4087e6f13c1 (diff) |
* The notification buffer is now used to store Alerts/AlertChangeds and times
to notify about, rather than notifications to be sent.
* Fixed up the debug notifier a bit more.
* Using the debug notifier extras more now.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mauve/alert.rb | 7 | ||||
-rw-r--r-- | lib/mauve/alert_changed.rb | 6 | ||||
-rw-r--r-- | lib/mauve/notification.rb | 2 | ||||
-rw-r--r-- | lib/mauve/notifier.rb | 14 | ||||
-rw-r--r-- | lib/mauve/notifiers/debug.rb | 12 |
5 files changed, 16 insertions, 25 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index 706b0e3..28079a2 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -401,12 +401,7 @@ module Mauve # # @return [Boolean] Showing if an alert has been sent. def notify(at = Time.now) - if self.alert_group.nil? - logger.warn "Could not notify for #{self} since there are no matching alert groups" - false - else - self.alert_group.notify(self, at) - end + Server.notification_push([self, at]) end # Acknowledge an alert diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb index 7cfdb76..0e0d257 100644 --- a/lib/mauve/alert_changed.rb +++ b/lib/mauve/alert_changed.rb @@ -98,7 +98,11 @@ module Mauve return save end - alert_group.notify(alert, Time.now) + # + # Push this notifitcation onto the queue. + # + Server.notification_push([alert, Time.now]) + # # Need to make sure this reminder is cleared. # diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb index 522f9fa..3c902a2 100644 --- a/lib/mauve/notification.rb +++ b/lib/mauve/notification.rb @@ -239,7 +239,7 @@ module Mauve if already_sent_to.include?(person.username) logger.info("Already sent notification of #{alert} to #{person.username}") else - Server.notification_push([person, level, alert]) + person.send_alert(level, alert) already_sent_to << person.username end end diff --git a/lib/mauve/notifier.rb b/lib/mauve/notifier.rb index bf36162..8a26b2c 100644 --- a/lib/mauve/notifier.rb +++ b/lib/mauve/notifier.rb @@ -86,14 +86,12 @@ module Mauve # Empty the buffer, one notification at a time. # sz.times do - person, *args = Server.notification_pop - - # - # Nil person.. that's craaazy too! - # - next if person.nil? - - person.send_alert(*args) + alert, at = Server.notification_pop + if alert.alert_group.nil? + logger.warn "Could not notify for #{alert} since there are no matching alert groups" + else + alert.alert_group.notify(alert, at) + end end end diff --git a/lib/mauve/notifiers/debug.rb b/lib/mauve/notifiers/debug.rb index 417bc94..a9afc52 100644 --- a/lib/mauve/notifiers/debug.rb +++ b/lib/mauve/notifiers/debug.rb @@ -53,27 +53,21 @@ module Mauve end def send_alert_to_debug_channels(destination, alert, all_alerts, conditions = nil) - message = if respond_to?(:prepare_message) + message = if self.respond_to?(:prepare_message) prepare_message(destination, alert, all_alerts, conditions) else [destination, alert, all_alerts].inspect end if deliver_to_file - #lock_file = "#{deliver_to_file}.lock" - #while File.exists?(lock_file) - # sleep 0.1 - #end - #FileUtils.touch(lock_file) File.open("#{deliver_to_file}", "a+") do |fh| fh.flock(File::LOCK_EX) - fh.print("#{Time.now} from #{self.class}: " + message + "\n") + fh.print YAML.dump([Time.now, self.class, destination, message]) fh.flush() end - #FileUtils.rm(lock_file) end - deliver_to_queue << [destination, alert, all_alerts, conditions] if deliver_to_queue + deliver_to_queue << [Time.now, self.class, destination, message] if deliver_to_queue if @disable_normal_delivery true # pretend it happened OK if we're just testing |