aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve/person.rb
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-07-14 14:50:22 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-07-14 14:50:22 +0100
commit494b083408b354f38da9b1fc5e8ffb7238d009b3 (patch)
tree4a9122f13b4f36840a2223616b41e3608ae9ba4f /lib/mauve/person.rb
parente07cea09e884607d6ad005f5e2822251ca31b9ba (diff)
Fixed mauveclient to obey time multipliers
Fixed logrotate script to rotate the correct script Init script now uses the correct user lib/mauve/history.rb is now installed Further logging cleanups
Diffstat (limited to 'lib/mauve/person.rb')
-rw-r--r--lib/mauve/person.rb27
1 files changed, 14 insertions, 13 deletions
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index cf29ff9..199bc23 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -24,11 +24,10 @@ module Mauve
#
class NotificationCaller
- def initialize(person, alert, other_alerts, notification_methods, base_conditions={})
+ def initialize(person, alert, other_alerts, base_conditions={})
@person = person
@alert = alert
@other_alerts = other_alerts
- @notification_methods = notification_methods
@base_conditions = base_conditions
end
@@ -66,7 +65,7 @@ module Mauve
#
# Log the result
- note = "#{@alert.update_type.upcase}: notification " + (res ? "succeeded" : "failed" ) + " for #{@person.username} using notifier '#{name}' to '#{destination}'."
+ note = "#{@alert.update_type.capitalize} #{name} notification to #{@person.username} (#{destination}) " + (res ? "succeeded" : "failed" )
logger.info note
h = History.new(:alert_id => @alert.id, :type => "notification", :event => note)
logger.error "Unable to save history due to #{h.errors.inspect}" if !h.save
@@ -155,6 +154,10 @@ module Mauve
# This just wraps send_alert by sending the job to a queue.
#
def send_alert(level, alert)
+ Server.notification_push([self, level, alert])
+ end
+
+ def do_send_alert(level, alert)
now = MauveTime.now
threshold_breached = @notification_thresholds.any? do |period, previous_alert_times|
@@ -162,15 +165,15 @@ module Mauve
first.is_a?(MauveTime) and (now - first) < period
end
- was_suppressed = self.suppressed?
+ was_suppressed = self.suppressed?
if Server.instance.started_at > alert.updated_at.to_time and (Server.instance.started_at + Server.instance.initial_sleep) > MauveTime.now
logger.info("Alert last updated in prior run of mauve -- ignoring for initial sleep period.")
- return
+ return true
end
if threshold_breached
- logger.info("Suspending notifications to #{username} until further notice.") unless was_suppressed
+ logger.info("Suspending further notifications to #{username} until further notice.") unless was_suppressed
@suppressed = true
else
@@ -183,18 +186,14 @@ module Mauve
# We only suppress notifications if we were suppressed before we started,
# and are still suppressed.
#
- return if was_suppressed and self.suppressed?
-
- Server.notification_push([self, level, alert, was_suppressed])
- end
+ return true if was_suppressed and self.suppressed?
- def do_send_alert(level, alert, was_suppressed)
result = NotificationCaller.new(
self,
alert,
current_alerts,
- Configuration.current.notification_methods,
- :was_suppressed => was_suppressed
+ {:is_suppressed => @suppressed,
+ :was_suppressed => was_suppressed, }
).instance_eval(&__send__(level))
if result
@@ -209,8 +208,10 @@ module Mauve
@notification_thresholds[period].shift
end
true
+
else
false
+
end
end