aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick J Cherry <patrick@bytemark.co.uk>2011-06-18 18:14:38 +0100
committerPatrick J Cherry <patrick@bytemark.co.uk>2011-06-18 18:14:38 +0100
commitde83746b5a33f1d2ac573f67c94760cb0a67b57e (patch)
tree15bba173841054b11fd3ab0515f9ea60c0850b0f
parent9e3d08a472053ddcd16ab69ad057b9e59194f9af (diff)
* Don't send acknowledged notifications unless the alert is raised
* Unacknowledge a cleared alert or a newly raised one * Fixed interface unexpected nil errors.
-rw-r--r--lib/mauve/alert.rb21
-rw-r--r--lib/mauve/web_interface.rb4
-rw-r--r--views/_alerts_table_alert_detail.haml2
-rw-r--r--views/_alerts_table_alert_summary.haml2
4 files changed, 18 insertions, 11 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb
index cf88114..6dc3216 100644
--- a/lib/mauve/alert.rb
+++ b/lib/mauve/alert.rb
@@ -131,7 +131,7 @@ module Mauve
end
def sort_tuple
- [AlertGroup::LEVELS.index(self.level), (self.raised_at.to_time || self.cleared_at.to_time || Time.now)]
+ [AlertGroup::LEVELS.index(self.level), (self.raised_at || self.cleared_at || Time.now).to_time]
end
def <=>(other)
@@ -167,7 +167,7 @@ module Mauve
self.update_type = :acknowledged
logger.error("Couldn't save #{self}") unless save
- AlertGroup.notify([self])
+ AlertGroup.notify([self]) if self.raised?
end
def unacknowledge!
@@ -177,7 +177,7 @@ module Mauve
self.update_type = (raised? ? :raised : :cleared)
logger.error("Couldn't save #{self}") unless save
- AlertGroup.notify([self])
+ AlertGroup.notify([self]) if self.raised?
end
def raise!
@@ -400,15 +400,22 @@ module Mauve
alert_db.cleared_at = nil
end
- #
- #
- #
if alert_db.cleared?
alert_db.update_type = :cleared
else
alert_db.update_type = :raised
end
-
+
+ #
+ # If the alert is cleared ,or has just been raised unset the acknowledge dates.
+ #
+ if alert_db.acknowledged? and (alert_db.cleared? or (alert_db.raised? and !was_raised))
+ alert_db.acknowledged_at = nil
+ end
+
+ #
+ # Set the subject
+ #
if alert.subject and !alert.subject.empty?
alert_db.subject = Alert.remove_html(alert.subject)
else
diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb
index de12291..29e41f7 100644
--- a/lib/mauve/web_interface.rb
+++ b/lib/mauve/web_interface.rb
@@ -186,10 +186,10 @@ EOF
type_hours = params[:type_hours] || "daylight"
alerts = params[:alerts] || []
- n_hours = (n_hours > 188 ? 188 : n_hours)
+ n_hours = (n_hours.to_i > 188 ? 188 : n_hours.to_i)
if ack_until.to_s.empty?
- ack_until = Time.now.in_x_hours(n_hours.to_i, type_hours.to_s)
+ ack_until = Time.now.in_x_hours(n_hours, type_hours.to_s)
else
ack_until = Time.at(ack_until.to_i)
end
diff --git a/views/_alerts_table_alert_detail.haml b/views/_alerts_table_alert_detail.haml
index b5ada45..3bb25c3 100644
--- a/views/_alerts_table_alert_detail.haml
+++ b/views/_alerts_table_alert_detail.haml
@@ -6,7 +6,7 @@
#{alert.detail}
%address
- if alert.raised? or alert.acknowledged?
- Raised at #{alert.raised_at.to_s_human} &bull;
+ Raised at #{(alert.raised_at || Time.now).to_s_human} &bull;
- if alert.acknowledged?
Ack'd at #{alert.acknowledged_at.to_s_human} by #{alert.acknowledged_by} &bull;
Source: #{alert.source} &bull;
diff --git a/views/_alerts_table_alert_summary.haml b/views/_alerts_table_alert_summary.haml
index 24162c6..f27ceeb 100644
--- a/views/_alerts_table_alert_summary.haml
+++ b/views/_alerts_table_alert_summary.haml
@@ -11,4 +11,4 @@
:href => "/alert/#{alert.id}", |
:onclick => "fetchDetail('#{alert.id}'); return false;"}
Details &darr;
- %td= alert.raised_at.to_s_relative
+ %td= (alert.raised_at || alert.cleared_at || Time.now).to_s_relative