aboutsummaryrefslogtreecommitdiff
path: root/lib/mauve
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-31 12:19:48 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-31 12:19:48 +0100
commitb87b69ca3fb266bdb5de88b9e77da54e23e370a5 (patch)
tree94698670ecd9b8562ae41b0ab793fac821f91f97 /lib/mauve
parent36543941d784715e962599f7bf73f4680387e610 (diff)
Fixed up alert suppression to be less jumpy
Diffstat (limited to 'lib/mauve')
-rw-r--r--lib/mauve/alert.rb7
-rw-r--r--lib/mauve/alert_group.rb3
-rw-r--r--lib/mauve/configuration_builders/person.rb5
-rw-r--r--lib/mauve/notification.rb1
-rw-r--r--lib/mauve/person.rb36
-rw-r--r--lib/mauve/server.rb4
6 files changed, 35 insertions, 21 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 3810d25..ee5c1ba 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -172,15 +172,16 @@ module Mauve
html_permitted_in = [:detail]
attributes.each do |key, val|
- next unless val.is_a?(String)
next if html_permitted_in.include?(key)
+ next unless val.is_a?(String)
attribute_set(key, Alert.remove_html(val))
end
- html_permitted_in.each do |key|
+ attributes.each do |key, val|
+ next unless html_permitted_in.include?(key)
next unless val.is_a?(String)
- val = attribute_get(key)
+
attribute_set(key, Alert.clean_html(val))
end
end
diff --git a/lib/mauve/alert_group.rb b/lib/mauve/alert_group.rb
index df76f40..b320f18 100644
--- a/lib/mauve/alert_group.rb
+++ b/lib/mauve/alert_group.rb
@@ -133,8 +133,9 @@ module Mauve
#
sent_to = []
notifications.each do |notification|
- sent_to = notification.notify(alert, sent_to)
+ sent_to << notification.notify(alert, sent_to)
end
+
end
#
diff --git a/lib/mauve/configuration_builders/person.rb b/lib/mauve/configuration_builders/person.rb
index 1f2af71..014987f 100644
--- a/lib/mauve/configuration_builders/person.rb
+++ b/lib/mauve/configuration_builders/person.rb
@@ -41,6 +41,7 @@ module Mauve
def suppress_notifications_after(h)
raise ArgumentError.new("notification_threshold must be specified as e.g. (10 => 1.minute)") unless
h.kind_of?(Hash) && h.keys[0].kind_of?(Integer) && h.values[0].kind_of?(Integer)
+
@result.notification_thresholds[h.values[0]] = Array.new(h.keys[0])
end
end
@@ -53,6 +54,10 @@ module Mauve
def created_person(person)
name = person.username
raise BuildException.new("Duplicate person '#{name}'") if @result.people[name]
+ #
+ # Add a default notification threshold
+ #
+ person.notification_thresholds[60] = Array.new(10) if person.notification_thresholds.empty?
@result.people[person.username] = person
end
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index 2007b90..00ce989 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -99,6 +99,7 @@ module Mauve
## Return true if the alert has not been acknowledged within a certain time.
#
def unacknowledged(seconds)
+ @test_time = @time if @test_time.nil?
@alert &&
@alert.raised? &&
!@alert.acknowledged? &&
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index 60ad60a..c26c456 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -8,10 +8,7 @@ module Mauve
attr_reader :notification_thresholds, :last_pop3_login
def initialize(*args)
- #
- # By default send 10 thresholds in a minute maximum
- #
- @notification_thresholds = { 60 => Array.new(10) }
+ @notification_thresholds = nil
@suppressed = false
#
# TODO fix up web login so pop3 can be used as a proxy.
@@ -25,7 +22,14 @@ module Mauve
def suppressed?
@suppressed
end
-
+
+ def notification_thresholds
+ #
+ # By default send 10 thresholds in a minute maximum
+ #
+ @notification_thresholds ||= { }
+ end
+
# This class implements an instance_eval context to execute the blocks
# for running a notification block for each person.
#
@@ -86,6 +90,7 @@ module Mauve
end
#
+ #
# Sends the alert
#
def send_alert(level, alert)
@@ -93,20 +98,21 @@ module Mauve
was_suppressed = self.suppressed?
- @suppressed = @notification_thresholds.any? do |period, previous_alert_times|
+ @suppressed = self.notification_thresholds.any? do |period, previous_alert_times|
#
# Choose the second one as the first.
#
first = previous_alert_times[1]
- first.is_a?(Time) and (now - first) < period
+ last = previous_alert_times[-1]
+
+ first.is_a?(Time) and (
+ (now - first) < period or
+ (was_suppressed and (now - last) < period)
+ )
end
- if self.suppressed?
- logger.info("Suspending further notifications to #{username} until further notice.") unless was_suppressed
- else
- logger.info "Starting to send notifications again for #{username}." if was_suppressed
- end
+ logger.info "Starting to send notifications again for #{username}." if was_suppressed and not self.suppressed?
#
# We only suppress notifications if we were suppressed before we started,
@@ -135,12 +141,12 @@ module Mauve
#
# Remember that we've sent an alert
#
- @notification_thresholds.each do |period, previous_alert_times|
+ self.notification_thresholds.each do |period, previous_alert_times|
#
# Hmm.. not sure how to make this thread-safe.
#
- @notification_thresholds[period].push Time.now
- @notification_thresholds[period].shift
+ self.notification_thresholds[period].push Time.now
+ self.notification_thresholds[period].shift
end
return true
diff --git a/lib/mauve/server.rb b/lib/mauve/server.rb
index 0d56f7f..a217aab 100644
--- a/lib/mauve/server.rb
+++ b/lib/mauve/server.rb
@@ -121,11 +121,11 @@ module Mauve
#
# Check buffer sizes
#
- if self.class.notification_buffer_size > 10
+ if self.class.notification_buffer_size >= 10
logger.warn "Notification buffer has #{self.class.notification_buffer_size} messages in it"
end
- if self.class.packet_buffer_size > 50
+ if self.class.packet_buffer_size >= 100
logger.warn "Packet buffer has #{self.class.packet_buffer_size} updates in it"
end