aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bin/mauvesend2
-rw-r--r--lib/mauve/alert.rb31
-rw-r--r--lib/mauve/alert_changed.rb38
-rw-r--r--lib/mauve/history.rb2
-rw-r--r--lib/mauve/mauve_time.rb8
-rw-r--r--lib/mauve/notification.rb2
-rw-r--r--lib/mauve/notifiers/email.rb2
-rw-r--r--lib/mauve/person.rb2
8 files changed, 40 insertions, 47 deletions
diff --git a/bin/mauvesend b/bin/mauvesend
index 42229eb..d30b84a 100644
--- a/bin/mauvesend
+++ b/bin/mauvesend
@@ -167,7 +167,7 @@ require 'getoptlong'
end
end
-NOW = Mauve::MauveTime.now
+NOW = Time.now
def error(msg)
STDERR.print "*** Error: #{msg}\n"
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index 6f6f3d1..07421d5 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -12,7 +12,7 @@ module Mauve
property :id, Serial
property :alert_id, Integer
- property :earliest, DateTime
+ property :earliest, Time
belongs_to :alert, :model => "Alert"
# 1) Shame we can't get this called automatically from DataMapper.auto_upgrade!
@@ -24,7 +24,7 @@ module Mauve
# http://www.mail-archive.com/datamapper@googlegroups.com/msg02314.html
#
def self.create_view!
- the_distant_future = Time.now + 86400000 # it is the year 2000 - the humans are dead
+ the_distant_future = Time.now + 10000.days # it is the year 2000 - the humans are dead
["BEGIN TRANSACTION",
"DROP VIEW IF EXISTS mauve_alert_earliest_dates",
"CREATE VIEW
@@ -67,16 +67,16 @@ module Mauve
property :detail, Text, :length=>65535
property :importance, Integer, :default => 50
- property :raised_at, DateTime
- property :cleared_at, DateTime
- property :updated_at, DateTime
- property :acknowledged_at, DateTime
+ property :raised_at, Time
+ property :cleared_at, Time
+ property :updated_at, Time
+ property :acknowledged_at, Time
property :acknowledged_by, String
property :update_type, String
- property :will_clear_at, DateTime
- property :will_raise_at, DateTime
- property :will_unacknowledge_at, DateTime
+ property :will_clear_at, Time
+ property :will_raise_at, Time
+ property :will_unacknowledge_at, Time
has n, :changes, :model => AlertChanged
has n, :histories, :through => :alerthistory
@@ -98,7 +98,7 @@ module Mauve
#
def check_dates
bad_dates = self.attributes.find_all do |key, value|
- value.is_a?(DateTime) and not (DateTime.new(2000,1,1,0,0,0)..DateTime.new(2020,1,1,0,0,0)).include?(value)
+ value.is_a?(Time) and (value < (Time.now - 3650.days) or value > (Time.now + 3650.days))
end
if bad_dates.empty?
@@ -153,7 +153,7 @@ module Mauve
end
def sort_tuple
- [AlertGroup::LEVELS.index(self.level), (self.raised_at || self.cleared_at || Time.now).to_time]
+ [AlertGroup::LEVELS.index(self.level), (self.raised_at || self.cleared_at || Time.now)]
end
def <=>(other)
@@ -290,14 +290,13 @@ module Mauve
# raise, clear or unacknowldge this event.
#
def due_at
- o = [will_clear_at, will_raise_at, will_unacknowledge_at].compact.sort[0]
- o ? o.to_time : nil
+ [will_clear_at, will_raise_at, will_unacknowledge_at].compact.sort.first
end
def poll
- raise! if (will_unacknowledge_at and will_unacknowledge_at.to_time <= Time.now) or
- (will_raise_at and will_raise_at.to_time <= Time.now)
- clear! if will_clear_at && will_clear_at.to_time <= Time.now
+ raise! if (will_unacknowledge_at and will_unacknowledge_at <= Time.now) or
+ (will_raise_at and will_raise_at <= Time.now)
+ clear! if will_clear_at && will_clear_at <= Time.now
logger.info("Polled #{self.inspect}")
end
diff --git a/lib/mauve/alert_changed.rb b/lib/mauve/alert_changed.rb
index ef062be..9840b84 100644
--- a/lib/mauve/alert_changed.rb
+++ b/lib/mauve/alert_changed.rb
@@ -12,12 +12,12 @@ module Mauve
property :id, Serial
property :alert_id, Integer, :required => true
property :person, String, :required => true
- property :at, DateTime, :required => true
+ property :at, Time, :required => true
property :was_relevant, Boolean, :required => true, :default => true
property :level, String, :required => true
property :update_type, String, :required => true
- property :remind_at, DateTime
- property :updated_at, DateTime
+ property :remind_at, Time
+ # property :updated_at, Time, :required => true
def inspect
@@ -28,28 +28,18 @@ module Mauve
belongs_to :alert
- # There is a bug there. You could have two reminders for the same
- # person if that person has two different notify clauses.
- #
- # See the test cases test_Bug_reminders_get_trashed() in ./test/
- after :create do
- old_changed = AlertChanged.first(
- :alert_id => alert_id,
- :person => person,
- :id.not => id,
- :remind_at.not => nil
- )
- if old_changed
- if !old_changed.update(:remind_at => nil)
- logger.info "Couldn't save #{old_changed}, will get duplicate reminders"
- end
- end
- end
-
def was_relevant=(value)
attribute_set(:was_relevant, value)
end
+ def updated_at
+ self.at
+ end
+
+ def updated_at=(t)
+ self.at = t
+ end
+
def logger
Log4r::Logger.new self.class.to_s
end
@@ -158,7 +148,11 @@ module Mauve
end
def poll # mimic interface from Alert
- remind if remind_at.to_time <= Time.now
+ remind if remind_at.is_a?(Time) and remind_at <= Time.now
+ end
+
+ def alert_group
+ alert.alert_group
end
class << self
diff --git a/lib/mauve/history.rb b/lib/mauve/history.rb
index 086fc6d..096e648 100644
--- a/lib/mauve/history.rb
+++ b/lib/mauve/history.rb
@@ -23,7 +23,7 @@ module Mauve
# 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
+ property :created_at, Time, :required => true
has n, :alerts, :through => :alerthistory
diff --git a/lib/mauve/mauve_time.rb b/lib/mauve/mauve_time.rb
index 4435098..2d9e293 100644
--- a/lib/mauve/mauve_time.rb
+++ b/lib/mauve/mauve_time.rb
@@ -28,15 +28,15 @@ class DateTime
end
def to_s_relative(*args)
- self.to_time.to_s_relative(*args)
+ self.to_s_relative(*args)
end
def to_s_human
- self.to_time.to_s_human
+ self.to_s_human
end
def in_x_hours(*args)
- self.to_time.in_x_hours(*args)
+ self.in_x_hours(*args)
end
end
@@ -135,7 +135,7 @@ class Time
#
# Make sure now is the correct class
#
- now = now.to_time if now.is_a?(DateTime)
+ now = now if now.is_a?(DateTime)
raise ArgumentError, "now must be a Time" unless now.is_a?(Time)
diff --git a/lib/mauve/notification.rb b/lib/mauve/notification.rb
index 71dd69c..dea07a3 100644
--- a/lib/mauve/notification.rb
+++ b/lib/mauve/notification.rb
@@ -100,7 +100,7 @@ module Mauve
@alert &&
@alert.raised? &&
!@alert.acknowledged? &&
- (@test_time - @alert.raised_at.to_time) > seconds
+ (@test_time - @alert.raised_at) >= seconds
end
def x_in_list_of_y(x,y)
diff --git a/lib/mauve/notifiers/email.rb b/lib/mauve/notifiers/email.rb
index 9676bf6..9d825b8 100644
--- a/lib/mauve/notifiers/email.rb
+++ b/lib/mauve/notifiers/email.rb
@@ -79,7 +79,7 @@ module Mauve
alert.acknowledged_at
else
alert.raised_at
- end ).to_time
+ end )
m.header['Content-Type'] = "multipart/alternative"
diff --git a/lib/mauve/person.rb b/lib/mauve/person.rb
index 9d541a9..76b52e0 100644
--- a/lib/mauve/person.rb
+++ b/lib/mauve/person.rb
@@ -179,7 +179,7 @@ module Mauve
end
- if Server.instance.started_at > alert.updated_at.to_time and (Server.instance.started_at + Server.instance.initial_sleep) > Time.now
+ if Server.instance.started_at > alert.updated_at and (Server.instance.started_at + Server.instance.initial_sleep) > Time.now
logger.info("Alert last updated in prior run of mauve -- ignoring for initial sleep period.")
return true
end