aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-08-10 16:05:20 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-08-10 16:05:20 +0100
commita54a32084e9870af6f1ede97887c2332c21e812c (patch)
tree5ccc3afa55e3dc9a9cbb7dedefd0c2d19453ba5c /lib
parent8621a1b4914f70975f83ad59d31da25d5c01aa1a (diff)
Added ability to tag multiple alerts with the same history item.
Diffstat (limited to 'lib')
-rw-r--r--lib/mauve/alert.rb5
-rw-r--r--lib/mauve/history.rb16
-rw-r--r--lib/mauve/notifiers/debug.rb2
-rw-r--r--lib/mauve/person.rb6
-rw-r--r--lib/mauve/pop3_server.rb2
5 files changed, 22 insertions, 9 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 027cc8c..20a0861 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -78,7 +78,8 @@ module Mauve
property :will_raise_at, DateTime
property :will_unacknowledge_at, DateTime
has n, :changes, :model => AlertChanged
- has n, :histories, :model => Mauve::History
+ has n, :histories, :through => :alerthistory
+
has 1, :alert_earliest_date
before :save, :take_copy_of_changes
@@ -209,7 +210,7 @@ module Mauve
(self.update_type == "raised" and (is_a_new_alert or is_a_change))
self.notify
- h = History.new(:alert_id => self.id, :type => "update")
+ h = History.new(:alerts => [self], :type => "update")
if self.update_type == "acknowledged"
h.event = "ACKNOWLEDGED by #{self.acknowledged_by} until #{self.will_unacknowledge_at}"
diff --git a/lib/mauve/history.rb b/lib/mauve/history.rb
index 1c2cdf4..086fc6d 100644
--- a/lib/mauve/history.rb
+++ b/lib/mauve/history.rb
@@ -3,6 +3,16 @@ require 'mauve/datamapper'
require 'log4r'
module Mauve
+ class AlertHistory
+ include DataMapper::Resource
+
+ property :alert_id, Integer, :key => true
+ property :history_id, Integer, :key => true
+
+ belongs_to :alert
+ belongs_to :history
+ end
+
class History
include DataMapper::Resource
@@ -10,12 +20,12 @@ module Mauve
default_scope(:default).update(:order => [:created_at.desc, :id.desc])
property :id, Serial
- property :alert_id, Integer, :required => true
+# property :alert_id, String, :required => true
property :type, String, :required => true, :default => "unknown"
property :event, Text, :required => true, :default => "Nothing set"
property :created_at, DateTime, :required => true
- belongs_to :alert
+ has n, :alerts, :through => :alerthistory
before :valid?, :set_created_at
@@ -29,4 +39,6 @@ module Mauve
end
+
end
+
diff --git a/lib/mauve/notifiers/debug.rb b/lib/mauve/notifiers/debug.rb
index 889a428..775364d 100644
--- a/lib/mauve/notifiers/debug.rb
+++ b/lib/mauve/notifiers/debug.rb
@@ -47,7 +47,7 @@ module Mauve
#FileUtils.touch(lock_file)
File.open("#{deliver_to_file}", "a+") do |fh|
fh.flock(File::LOCK_EX)
- fh.print("#{MauveTime.now} from #{self.class}: " + message + "\n")
+ fh.print("#{Time.now} from #{self.class}: " + message + "\n")
fh.flush()
end
#FileUtils.rm(lock_file)
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index 1a5f2c9..58d696c 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -72,10 +72,10 @@ module Mauve
# Log the result
note = "#{@alert.update_type.capitalize} #{name} notification to #{@person.username} (#{destination}) " + (res ? "succeeded" : "failed" )
logger.info note+" about #{@alert}."
- h = History.new(:alert_id => @alert.id, :type => "notification", :event => note)
+ h = History.new(:alerts => [@alert], :type => "notification", :event => note)
logger.error "Unable to save history due to #{h.errors.inspect}" if !h.save
- res
+ return res
end
end
@@ -191,7 +191,7 @@ module Mauve
if was_suppressed and self.suppressed?
note = "#{alert.update_type.capitalize} notification to #{self.username} suppressed"
logger.info note + " about #{alert}."
- History.create(:alert_id => alert.id, :type => "notification", :event => note)
+ History.create(:alerts => [alert], :type => "notification", :event => note)
return true
end
diff --git a/lib/mauve/pop3_server.rb b/lib/mauve/pop3_server.rb
index e455591..ef307d5 100644
--- a/lib/mauve/pop3_server.rb
+++ b/lib/mauve/pop3_server.rb
@@ -258,7 +258,7 @@ module Mauve
send_data ["+OK #{msg.length} octets", msg, "."].join(CRLF)
note = "#{alert_changed.update_type.capitalize} notification downloaded via POP3 by #{@user}"
logger.info note+" about #{alert_changed}."
- h = History.new(:alert_id => alert_changed.alert_id, :type => "notification", :event => note)
+ h = History.new(:alerts => [alert_changed.alert_id], :type => "notification", :event => note)
logger.error "Unable to save history due to #{h.errors.inspect}" if !h.save
else
send_data "-ERR Message not found."