aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.hgtags1
-rw-r--r--debian/changelog14
-rw-r--r--lib/mauve/alert.rb23
-rw-r--r--lib/mauve/alert_changed.rb6
-rw-r--r--lib/mauve/alert_group.rb76
-rw-r--r--lib/mauve/configuration_builders/alert_group.rb6
-rw-r--r--lib/mauve/configuration_builders/notification_method.rb4
-rw-r--r--lib/mauve/notification.rb36
-rw-r--r--lib/mauve/notifier.rb14
-rw-r--r--lib/mauve/notifiers/debug.rb58
-rw-r--r--lib/mauve/notifiers/email.rb1
-rw-r--r--lib/mauve/version.rb2
-rw-r--r--lib/mauve/web_interface.rb2
-rw-r--r--static/javascript/mauve_utils.js4
-rw-r--r--test/tc_mauve_alert_changed.rb83
-rw-r--r--test/tc_mauve_alert_group.rb2
-rw-r--r--test/tc_mauve_configuration_builders_alert_group.rb3
-rw-r--r--test/tc_mauve_configuration_builders_notification_method.rb16
-rw-r--r--test/tc_mauve_configuration_builders_person.rb3
-rw-r--r--test/tc_mauve_notification.rb84
-rw-r--r--views/alert.haml4
-rw-r--r--views/alerts.haml2
22 files changed, 335 insertions, 109 deletions
diff --git a/.hgtags b/.hgtags
index d10c6d8..4632656 100644
--- a/.hgtags
+++ b/.hgtags
@@ -19,3 +19,4 @@ b720f7eaf50048e8430cb3fa79cb9ea96ef1a418 3.7.1
7f35d4f171ecaa46941fcb1beb5b1a026e98e985 3.7.3
299d570786ce3029855e06090ec5314d66732b9d 3.7.4
0196bd006ccf888bb0e0e1adf1a34d3b82320660 3.7.5
+2a8a0b46def44710562ed0440bff9fa011f930fd 3.7.6
diff --git a/debian/changelog b/debian/changelog
index 0bc0909..acdbfb8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,17 @@
+mauvealert (3.7.7) stable; urgency=low
+
+ * Javascript refreshes now happen every two minutes.
+ * Alert now tries to find just one matching AlertGroup, not all.
+
+ -- Patrick J Cherry <patrick@bytemark.co.uk> Fri, 23 Mar 2012 15:02:53 +0000
+
+mauvealert (3.7.6) stable; urgency=low
+
+ * Tweaked alert display to show the alert_group properly.
+ * Bumped Mauve::Version correctly.
+
+ -- Patrick J Cherry <patrick@bytemark.co.uk> Thu, 22 Mar 2012 17:55:51 +0000
+
mauvealert (3.7.5) stable; urgency=low
* Added tests for web interface.
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 9d6ab85..28079a2 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -146,14 +146,15 @@ module Mauve
#
# Find the AlertGroup by name if we've got a cached value
#
- alert_group = AlertGroup.all.find{|a| self.cached_alert_group == a.name} if self.cached_alert_group
+ alert_group = AlertGroup.find{|a| self.cached_alert_group == a.name} if self.cached_alert_group
if alert_group.nil?
#
# If we've not found the alert group by name look for it again, the
# proper way.
#
- alert_group = AlertGroup.matches(self).first
+ alert_group = AlertGroup.find{|a| a.includes?(self)}
+ alert_group = AlertGroup.all.last if alert_group.nil?
self.cached_alert_group = alert_group.name unless alert_group.nil?
end
@@ -399,13 +400,8 @@ module Mauve
# Send a notification for this alert.
#
# @return [Boolean] Showing if an alert has been sent.
- def notify
- 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)
- end
+ def notify(at = Time.now)
+ Server.notification_push([self, at])
end
# Acknowledge an alert
@@ -485,12 +481,6 @@ module Mauve
self.will_unacknowledge_at = postpone_until
end
- #
- # Re-cache the alert group.
- #
- self.cached_alert_group = nil
- self.alert_group
-
logger.info("Postponing raise of #{self} until #{postpone_until} as it was last updated in a prior run of Mauve.")
else
self.acknowledged_by = nil
@@ -503,8 +493,9 @@ module Mauve
self.update_type = "raised" if self.update_type.nil? or self.update_type != "changed" or self.original_attributes[Alert.properties[:update_type]] == "cleared"
#
- # Cache the alert group, but only if not already set.
+ # Find the alert group to allow it to be cached.
#
+ self.cached_alert_group = nil
self.alert_group
end
diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb
index 9b2bea4..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)
+ #
+ # 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/alert_group.rb b/lib/mauve/alert_group.rb
index 7ea7ffb..31d9cc8 100644
--- a/lib/mauve/alert_group.rb
+++ b/lib/mauve/alert_group.rb
@@ -26,7 +26,7 @@ module Mauve
#
# @return [Array] AlertGroups that match
def matches(alert)
- grps = all.select { |alert_group| alert_group.includes?(alert) }
+ grps = find_all { |alert_group| alert_group.includes?(alert) }
#
# Make sure we always match the last (and therefore default) group.
@@ -36,6 +36,28 @@ module Mauve
grps
end
+ #
+ #
+ #
+ def find_all(&block)
+ return all unless block_given?
+
+ all.find_all do |alert_group|
+ yield(alert_group)
+ end
+ end
+
+ #
+ #
+ #
+ def find(&block)
+ return nil unless block_given?
+
+ all.find do |alert_group|
+ yield(alert_group)
+ end
+ end
+
# @return [Log4r::Logger]
def logger
Log4r::Logger.new self.to_s
@@ -113,13 +135,16 @@ module Mauve
# @return [Log4r::Logger]
def logger ; self.class.logger ; end
- # Signals that a given alert (which is assumed to belong in this group)
- # has undergone a significant change. We resend this to every notify list.
+ # Signals that a given alert (which is assumed to belong in this group) has
+ # undergone a significant change. We resend this to every notify list.
+ # The time is used to determine the time to be used when evaluating
+ # "during" blocks in the notifier clauses.
#
# @param [Mauve::Alert] alert
+ # @param [Time] at
#
# @return [Boolean] indicates success or failure of alert.
- def notify(alert)
+ def notify(alert, at=Time.now)
#
# If there are no notifications defined.
#
@@ -128,16 +153,39 @@ module Mauve
return false
end
+ during_runners = []
+
#
# This is where we set the reminder -- i.e. on a per-alert-group basis.
- #
- remind_at = notifications.inject(nil) do |reminder_time, notification|
- this_time = notification.remind_at_next(alert)
- if reminder_time.nil? or (!this_time.nil? and reminder_time > this_time)
- this_time
- else
- reminder_time
- end
+
+ remind_at = nil
+ notifications.each do |notification|
+ #
+ # Create a new during_runner for this notification clause, and keep it
+ # handy.
+ #
+ during_runner = DuringRunner.new(at, alert, &notification.during)
+ during_runners << during_runner
+
+ #
+ # Work out the next reminder time
+ #
+ this_remind_at = notification.remind_at_next(alert, during_runner)
+
+ #
+ # Skip this one if no reminder time can be found
+ #
+ next if this_remind_at.nil?
+
+ #
+ # Set the next reminder time if we've not had one already.
+ #
+ remind_at = this_remind_at if remind_at.nil?
+
+ #
+ # We need the next soonest reminder time.
+ #
+ remind_at = this_remind_at if remind_at > this_remind_at
end
#
@@ -148,7 +196,7 @@ module Mauve
:level => level.to_s,
:alert_id => alert.id,
:person => self.name,
- :at => Time.now,
+ :at => at,
:update_type => alert.update_type,
:remind_at => remind_at,
:was_relevant => true)
@@ -161,7 +209,7 @@ module Mauve
#
sent_to = []
notifications.each do |notification|
- sent_to << notification.notify(alert, sent_to)
+ sent_to << notification.notify(alert, sent_to, during_runners.shift)
end
return (sent_to.length > 0)
diff --git a/lib/mauve/configuration_builders/alert_group.rb b/lib/mauve/configuration_builders/alert_group.rb
index c652de8..56c446d 100644
--- a/lib/mauve/configuration_builders/alert_group.rb
+++ b/lib/mauve/configuration_builders/alert_group.rb
@@ -20,15 +20,15 @@ module Mauve
# @return [Mauve::Notification] New notification instance.
def builder_setup(*who)
who = who.map do |username|
- #raise BuildException.new("You haven't declared who #{username} is") unless
- # @context.people[username]
- #@context.people[username]
if @context.people[username]
@context.people[username]
+
elsif @context.people_lists[username]
@context.people_lists[username]
+
else
raise ArgumentError.new("You have not declared who #{username} is")
+
end
end
@result = Mauve::Notification.new(who, @context.last_alert_group.level)
diff --git a/lib/mauve/configuration_builders/notification_method.rb b/lib/mauve/configuration_builders/notification_method.rb
index 9596587..3f9283e 100644
--- a/lib/mauve/configuration_builders/notification_method.rb
+++ b/lib/mauve/configuration_builders/notification_method.rb
@@ -35,6 +35,10 @@ module Mauve
def result
@result ||= @provider_class.new(@name)
end
+
+ def debug!
+ result.extend(Mauve::Notifiers::Debug)
+ end
# This catches all methods available for a provider, as needed.
#
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index 920f1b1..3c902a2 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -42,6 +42,7 @@ module Mauve
@alert = alert
@during = during || Proc.new { true }
@logger = Log4r::Logger.new "Mauve::DuringRunner"
+ @now_cache = Hash.new
end
# This evaluates the +during+ block, returning the result.
@@ -49,8 +50,21 @@ module Mauve
# @param [Time] t Set the time at which to evaluate the +during+ block.
# @return [Boolean]
def now?(t=@time)
+ #
+ # Use the cache if we've already worked out what happens at time t.
+ #
+ return @now_cache[t] if @now_cache.has_key?(t)
+
+ #
+ # Store the test time in an instance variable so the test knows what time
+ # we're testing against.
+ #
@test_time = t
- instance_eval(&@during) ? true : false
+
+ #
+ # Store the answer in our cache and return.
+ #
+ @now_cache[t] = (instance_eval(&@during) ? true : false)
end
# This finds the next occurance of the +during+ block evaluating to true.
@@ -195,15 +209,18 @@ module Mauve
# @param [Array] already_sent_to A list of people that have already received this alert.
#
# @return [Array] The list of people that have received this alert.
- def notify(alert, already_sent_to = [])
+ def notify(alert, already_sent_to = [], during_runner = nil)
if people.nil? or people.empty?
logger.warn "No people found in for notification #{list}"
return
end
+ # Set up a during_runner
+ during_runner ||= DuringRunner.new(Time.now, self.alert, &self.during)
+
# Should we notify at all?
- return already_sent_to unless DuringRunner.new(Time.now, alert, &during).now?
+ return already_sent_to unless during_runner.now?
people.collect do |person|
case person
@@ -222,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
@@ -236,13 +253,16 @@ module Mauve
# @param [Mauve::Alert] alert The alert in question
# @return [Time or nil] The time a reminder should get sent, or nil if it
# should never get sent again.
- def remind_at_next(alert)
+ def remind_at_next(alert, during_runner = nil)
return nil unless alert.raised?
- if DuringRunner.new(Time.now, alert, &during).now?
- return DuringRunner.new(Time.now, alert, &during).find_next(every)
+ # Set up a during_runner
+ during_runner ||= DuringRunner.new(Time.now, self.alert, &self.during)
+
+ if during_runner.now?
+ return during_runner.find_next(every)
else
- return DuringRunner.new(Time.now, alert, &during).find_next()
+ return during_runner.find_next()
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 775364d..a9afc52 100644
--- a/lib/mauve/notifiers/debug.rb
+++ b/lib/mauve/notifiers/debug.rb
@@ -12,48 +12,62 @@ module Mauve
base.class_eval do
alias_method :send_alert_without_debug, :send_alert
alias_method :send_alert, :send_alert_to_debug_channels
-
- # Specifying deliver_to_file allows the administrator to ask for alerts
- # to be delivered to a particular file, which is assumed to be perused
- # by a person rather than a machine.
- #
- attr :deliver_to_file, true
-
- # Specifying deliver_to_queue allows a tester to ask for the send_alert
- # parameters to be appended to a Queue object (or anything else that
- # responds to <<).
- #
- attr :deliver_to_queue, true
end
end
+
+ def extended(base)
+ base.instance_eval do
+ alias :send_alert_without_debug :send_alert
+ alias :send_alert :send_alert_to_debug_channels
+ end
+ end
end
-
+
+
+ # Specifying deliver_to_file allows the administrator to ask for alerts
+ # to be delivered to a particular file, which is assumed to be perused
+ # by a person rather than a machine.
+ #
+ def deliver_to_file
+ @deliver_to_file
+ end
+
+ def deliver_to_file=(fn)
+ @deliver_to_file = fn
+ end
+
+ # Specifying deliver_to_queue allows a tester to ask for the send_alert
+ # parameters to be appended to a Queue object (or anything else that
+ # responds to <<).
+ #
+ def deliver_to_queue
+ @deliver_to_queue
+ end
+
+ def deliver_to_queue=(q)
+ @deliver_to_queue = q
+ end
+
def disable_normal_delivery!
@disable_normal_delivery = true
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
diff --git a/lib/mauve/notifiers/email.rb b/lib/mauve/notifiers/email.rb
index 8efdbec..5b8e9a0 100644
--- a/lib/mauve/notifiers/email.rb
+++ b/lib/mauve/notifiers/email.rb
@@ -97,7 +97,6 @@ module Mauve
m.to_s
end
- include Debug
end
end
end
diff --git a/lib/mauve/version.rb b/lib/mauve/version.rb
index 43befb4..d7af3a9 100644
--- a/lib/mauve/version.rb
+++ b/lib/mauve/version.rb
@@ -5,6 +5,6 @@ module Mauve
#
# Current version
- VERSION="3.7.3"
+ VERSION="3.7.7"
end
diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb
index 225cc33..16e7da2 100644
--- a/lib/mauve/web_interface.rb
+++ b/lib/mauve/web_interface.rb
@@ -165,6 +165,8 @@ EOF
if Authentication.authenticate(usr, pwd)
session['username'] = usr
+ # Clear the flash.
+ flash['error'] = nil
redirect next_page
else
flash['error'] = "Authentication failed."
diff --git a/static/javascript/mauve_utils.js b/static/javascript/mauve_utils.js
index e467b5d..1918006 100644
--- a/static/javascript/mauve_utils.js
+++ b/static/javascript/mauve_utils.js
@@ -152,7 +152,7 @@ function updateAlertsTable(alert_type, group_by) {
//
// Schedule next update.
//
- setTimeout("updateAlertsTable('"+alert_type+"','"+group_by+"');", 30000);
+ setTimeout("updateAlertsTable('"+alert_type+"','"+group_by+"');", 120000);
}
},
error: function( a,b,c ) {
@@ -164,7 +164,7 @@ function updateAlertsTable(alert_type, group_by) {
//
// Schedule next update.
//
- setTimeout("updateAlertsTable('"+alert_type+"','"+group_by+"');", 30000);
+ setTimeout("updateAlertsTable('"+alert_type+"','"+group_by+"');", 120000);
},
});
diff --git a/test/tc_mauve_alert_changed.rb b/test/tc_mauve_alert_changed.rb
index 86f31d7..167ea75 100644
--- a/test/tc_mauve_alert_changed.rb
+++ b/test/tc_mauve_alert_changed.rb
@@ -6,6 +6,7 @@ require 'mauve/alert_changed'
require 'mauve/configuration'
require 'mauve/configuration_builder'
require 'mauve/configuration_builders'
+require 'mauve/notifiers'
class TcMauveAlertChanged < Mauve::UnitTest
include Mauve
@@ -23,8 +24,15 @@ class TcMauveAlertChanged < Mauve::UnitTest
def test_reminder
config=<<EOF
+notification_method("email") {
+ debug!
+ deliver_to_queue []
+ disable_normal_delivery!
+}
+
person("test_person") {
- all { true }
+ email "test_person@example.com"
+ all { email }
}
alert_group("test_group") {
@@ -37,20 +45,27 @@ alert_group("test_group") {
EOF
Configuration.current = ConfigurationBuilder.parse(config)
+ notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
Server.instance.setup
alert = Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
alert.raise!
- reminders = 1
+ reminders = 1
notifications = 1
mins = 0
11.times do
mins += 1
- assert_equal(notifications, Server.instance.notification_buffer.length)
+ #
+ # In order to send the notification and stick in the reminder, we need to
+ # process the buffer.
+ #
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+
+ assert_equal(notifications, notification_buffer.length)
assert_equal(reminders, AlertChanged.count)
Timecop.freeze(Time.now+1.minute)
@@ -67,7 +82,12 @@ EOF
alert.clear!
notifications += 1
- assert_equal(notifications, Server.instance.notification_buffer.length)
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(notifications, notification_buffer.length)
+ #
+ # Process the buffer again
+ #
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
assert_equal(reminders, AlertChanged.count)
Timecop.freeze(Time.now + 10.minutes)
@@ -75,15 +95,23 @@ EOF
#
# Send NO MORE notifications.
#
- assert_equal(notifications, Server.instance.notification_buffer.length)
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(notifications, notification_buffer.length)
assert_equal(reminders, AlertChanged.count)
end
def test_only_send_one_alert_on_unacknowledge
config=<<EOF
+notification_method("email") {
+ debug!
+ deliver_to_queue []
+ disable_normal_delivery!
+}
+
person("test_person") {
- all { true }
+ email "test@example.com"
+ all { email }
}
alert_group("test_group") {
@@ -96,21 +124,29 @@ alert_group("test_group") {
EOF
Configuration.current = ConfigurationBuilder.parse(config)
+ notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
Server.instance.setup
alert = Alert.new(:source => "test", :alert_id => "test_alert", :summary => "test alert")
alert.raise!
- assert_equal(1,Server.instance.notification_buffer.length, "Wrong no of notifications sent after raise.")
- assert_equal(1,AlertChanged.count, "Wrong no of AlertChangeds created after raise.")
+
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(1, notification_buffer.length, "Wrong no of notifications sent after raise.")
+ assert_equal(1, AlertChanged.count, "Wrong no of AlertChangeds created after raise.")
alert.acknowledge!(Configuration.current.people["test_person"], Time.now + 10.minutes)
- assert_equal(2,Server.instance.notification_buffer.length, "Wrong no of notifications sent after acknowledge.")
- assert_equal(2,AlertChanged.count, "Wrong no of AlertChangeds created after acknowledge.")
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(2, notification_buffer.length, "Wrong no of notifications sent after raise.")
+ assert_equal(2, AlertChanged.count, "Wrong no of AlertChangeds created after acknowledge.")
+ #
+ # The alert has been acknowledged so send no more reminders.
+ #
Timecop.freeze(Time.now + 10.minutes)
AlertChanged.all.each{|ac| ac.poll}
- assert_equal(2,Server.instance.notification_buffer.length, "Extra notifications sent when alertchangeds are polled.")
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(2, notification_buffer.length, "Extra notifications sent when alertchangeds are polled.")
#
# OK if we poll the alert now it should be re-raised.
@@ -118,19 +154,28 @@ EOF
alert.poll
assert(!alert.acknowledged?,"Alert not unacknowledged")
assert(alert.raised?,"Alert not raised following unacknowledgment")
- assert_equal(3,Server.instance.notification_buffer.length, "No re-raise notification sent.")
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(3, notification_buffer.length, "No re-raise notification sent.")
+
#
# If we poll the AlertChangeds again, no further notification should be sent.
#
AlertChanged.all.each{|ac| ac.poll}
- assert_equal(3,Server.instance.notification_buffer.length, "Extra notifications sent when alertchangeds are polled.")
-
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(3, notification_buffer.length, "Extra notifications sent when alertchangeds are polled.")
end
def test_only_set_one_alert_changed_on_a_reminder_after_multiple_raises_and_clears
config=<<EOF
+notification_method("email") {
+ debug!
+ deliver_to_queue []
+ disable_normal_delivery!
+}
+
person("office_chat") {
- all { true }
+ email "test@example.com"
+ all { email }
}
alert_group("test_group") {
@@ -147,6 +192,7 @@ EOF
Configuration.current = ConfigurationBuilder.parse(config)
+ notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
Server.instance.setup
@@ -165,7 +211,8 @@ EOF
#
# No notification should have been sent, since it is the middle of the night
#
- assert_equal(0,Server.instance.notification_buffer.length, "No notifications should have been sent.")
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(0, notification_buffer.length, "No notifications should have been sent.")
assert(alert.cleared?)
#
@@ -175,14 +222,14 @@ EOF
#
# Still no alerts should be sent.
#
- assert_equal(0,Server.instance.notification_buffer.length, "No notifications should have been sent.")
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(0, notification_buffer.length, "No notifications should have been sent.")
assert(alert.raised?)
#
# Only one AlertChanged should be set now, with a reminder time of 8.30.
#
assert_equal(1, AlertChanged.all(:remind_at.not => nil).length, "Too many reminders are due to be sent.")
-
end
end
diff --git a/test/tc_mauve_alert_group.rb b/test/tc_mauve_alert_group.rb
index d6416a2..7e7c4dd 100644
--- a/test/tc_mauve_alert_group.rb
+++ b/test/tc_mauve_alert_group.rb
@@ -5,7 +5,7 @@ require 'mauve/alert_group'
require 'th_mauve_resolv'
require 'pp'
-class TcMauveAlert < Mauve::UnitTest
+class TcMauveAlertGroup < Mauve::UnitTest
def test_matches_alert
diff --git a/test/tc_mauve_configuration_builders_alert_group.rb b/test/tc_mauve_configuration_builders_alert_group.rb
index 77d16b5..f260fa2 100644
--- a/test/tc_mauve_configuration_builders_alert_group.rb
+++ b/test/tc_mauve_configuration_builders_alert_group.rb
@@ -1,10 +1,9 @@
$:.unshift "../lib/"
require 'th_mauve'
-require 'pp'
require 'mauve/configuration_builders/alert_group'
-class TcMauveConfigurationBuildersNotificationMethod < Mauve::UnitTest
+class TcMauveConfigurationBuildersAlertGroup < Mauve::UnitTest
def test_load
diff --git a/test/tc_mauve_configuration_builders_notification_method.rb b/test/tc_mauve_configuration_builders_notification_method.rb
index e5e8475..80768e8 100644
--- a/test/tc_mauve_configuration_builders_notification_method.rb
+++ b/test/tc_mauve_configuration_builders_notification_method.rb
@@ -1,13 +1,25 @@
$:.unshift "../lib/"
require 'th_mauve'
-require 'pp'
+require 'mauve/configuration_builder'
require 'mauve/configuration_builders/notification_method'
class TcMauveConfigurationBuildersNotificationMethod < Mauve::UnitTest
- def test_load
+ def test_debug_methods
+ config =<<EOF
+notification_method("email") {
+ debug!
+ disable_normal_delivery!
+ deliver_to_queue []
+}
+EOF
+ x = nil
+ assert_nothing_raised { x = Mauve::ConfigurationBuilder.parse(config) }
+ y = x.notification_methods["email"]
+
+ # TODO test delivery
end
end
diff --git a/test/tc_mauve_configuration_builders_person.rb b/test/tc_mauve_configuration_builders_person.rb
index b4fbd4f..61a6202 100644
--- a/test/tc_mauve_configuration_builders_person.rb
+++ b/test/tc_mauve_configuration_builders_person.rb
@@ -1,10 +1,9 @@
$:.unshift "../lib/"
require 'th_mauve'
-require 'pp'
require 'mauve/configuration_builders/person'
-class TcMauveConfigurationBuildersNotificationMethod < Mauve::UnitTest
+class TcMauveConfigurationBuildersPerson < Mauve::UnitTest
def test_load
diff --git a/test/tc_mauve_notification.rb b/test/tc_mauve_notification.rb
index 0b3bc04..bac389f 100644
--- a/test/tc_mauve_notification.rb
+++ b/test/tc_mauve_notification.rb
@@ -185,16 +185,25 @@ class TcMauveNotification < Mauve::UnitTest
t = Time.now
config=<<EOF
+notification_method("email") {
+ debug!
+ deliver_to_queue []
+ disable_normal_delivery!
+}
+
person ("test1") {
- all { true }
+ email "test1@example.com"
+ all { email }
}
person ("test2") {
- all { true }
+ email "test2@example.com"
+ all { email }
}
person ("test3") {
- all { true }
+ email "test3@example.com"
+ all { email }
}
people_list "testers", %w(
@@ -227,6 +236,8 @@ alert_group("default") {
EOF
Configuration.current = ConfigurationBuilder.parse(config)
+ notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
+
Server.instance.setup
alert = Alert.new(
:alert_id => "test",
@@ -240,7 +251,8 @@ EOF
#
# Also make sure that only 2 notifications has been sent..
#
- assert_equal(2, Server.instance.notification_buffer.size, "Wrong number of notifications sent")
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(2, notification_buffer.size, "Wrong number of notifications sent")
#
# Although there are four clauses above for notifications, test1 should be
@@ -303,8 +315,9 @@ EOF
)
alert.raise!
- assert_equal(1, Alert.count, "Wrong number of alerts saved")
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+ assert_equal(1, Alert.count, "Wrong number of alerts saved")
assert_equal(1, AlertChanged.count, "Wrong number of reminders inserted")
a = AlertChanged.first
@@ -315,4 +328,65 @@ EOF
end
+ #
+ # Test to make sure that if a bondary is crossed, then the during clauses all
+ # work.
+ #
+ def test_no_race_conditions_in_during
+
+ config=<<EOF
+notification_method("email") {
+ debug!
+ deliver_to_queue []
+ disable_normal_delivery!
+}
+
+person ("test1") {
+ email "test1@example.com"
+ all { email }
+}
+
+person ("test2") {
+ email "test1@example.com"
+ all { email }
+}
+
+alert_group("default") {
+ level URGENT
+ notify("test1") {
+ every 0
+ during { sleep 2 ; hours_in_day 1..7 }
+ }
+
+ notify("test2") {
+ every 0
+ during { hours_in_day 8..10 }
+ }
+
+}
+EOF
+
+ #
+ # Wind forward until 7:59:59am
+ #
+ Configuration.current = ConfigurationBuilder.parse(config)
+ notification_buffer = Configuration.current.notification_methods["email"].deliver_to_queue
+
+ Server.instance.setup
+
+ alert = Alert.new(
+ :alert_id => "test",
+ :source => "test",
+ :subject => "test"
+ )
+
+ Timecop.travel(Time.now + 7.hours + 59.minutes + 59.seconds)
+ alert.raise!
+
+ assert_nothing_raised{ Notifier.instance.__send__(:main_loop) }
+
+ assert_equal(1, notification_buffer.size, "Wrong number of notifications sent")
+ end
+
+
end
diff --git a/views/alert.haml b/views/alert.haml
index b16047a..ff13a62 100644
--- a/views/alert.haml
+++ b/views/alert.haml
@@ -18,8 +18,8 @@
%th{:title => "ID set by the source of the alert."} Alert ID
%td= @alert.alert_id
%tr
- %th{:title => "The group in the Mauve server configuration that match this alert"} Alert groups
- %td= @alert.alert_group
+ %th{:title => "The group in the Mauve server configuration that matches this alert"} Alert group
+ %td= @alert.alert_group.name
%tr
%th{:title => "The level of the first group in the Mauve server configuration that matched this alert"} Alert level
%td= @alert.level.to_s.upcase
diff --git a/views/alerts.haml b/views/alerts.haml
index 8968249..896b5a3 100644
--- a/views/alerts.haml
+++ b/views/alerts.haml
@@ -8,5 +8,5 @@
%p No alerts to display.
:javascript
// Do the magic updates..
- setTimeout("updateAlertsTable('#{@alert_type}','#{@group_by}');", 30000)
+ setTimeout("updateAlertsTable('#{@alert_type}','#{@group_by}');", 120000)