diff options
author | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-06-16 18:23:52 +0100 |
---|---|---|
committer | Patrick J Cherry <patrick@bytemark.co.uk> | 2011-06-16 18:23:52 +0100 |
commit | f6d9144af81f2078567691614fa7831c1a116fdf (patch) | |
tree | 8dbd6f49c518e090e1b7da18cb6ebc2c70113f7a /lib | |
parent | 4ca1b2c8db777cd1e389a227072b1cd108e23d05 (diff) |
Fixed up date handling in the xmpp/email template
Changed basic notification logic in Alert.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/mauve/alert.rb | 38 | ||||
-rw-r--r-- | lib/mauve/mauve_time.rb | 2 | ||||
-rw-r--r-- | lib/mauve/notifier.rb | 2 | ||||
-rw-r--r-- | lib/mauve/notifiers/templates/email.txt.erb | 6 | ||||
-rw-r--r-- | lib/mauve/notifiers/templates/xmpp.txt.erb | 2 | ||||
-rw-r--r-- | lib/mauve/processor.rb | 2 |
6 files changed, 33 insertions, 19 deletions
diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index c234f03..6e5249f 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -366,16 +366,20 @@ module Mauve # if raise_time if raise_time <= (reception_time + 5) - alert_db.raised_at = raise_time + alert_db.raised_at = raise_time + alert_db.will_raise_at = nil else + alert_db.raised_at = nil alert_db.will_raise_at = raise_time end end if clear_time if clear_time <= (reception_time + 5) - alert_db.cleared_at = clear_time + alert_db.cleared_at = clear_time + alert_db.will_clear_at = nil else + alert_db.cleared_at = nil alert_db.will_clear_at = clear_time end end @@ -386,7 +390,7 @@ module Mauve if alert_db.cleared_at && alert_db.raised_at && alert_db.cleared_at < alert_db.raised_at alert_db.cleared_at = nil end - + # # # @@ -402,6 +406,8 @@ module Mauve alert_db.subject = alert_db.source end + logger.debug [alert_db.source, alert_db.subject].inspect + alert_db.summary = Alert.remove_html(alert.summary) if alert.summary && !alert.summary.empty? # @@ -411,18 +417,26 @@ module Mauve alert_db.importance = alert.importance if alert.importance != 0 - # FIXME: this logic ought to be clearer as it may get more complicated + alert_db.update_type = :changed unless alert_db.update_type + + # + # This decides if we notify. # - if alert_db.update_type - if alert_db.update_type.to_sym == :changed && !alert_db.raised? - # do nothing + should_notify = case alert_db.update_type.to_sym + when :raised + !was_raised + when :acknowledged + !was_acknowledged + when :cleared + !was_cleared else - alerts_updated << alert_db - end - else - alert_db.update_type = :changed + alert_db.raised? end + alerts_updated << alert_db if should_notify + + alert_db.updated_at = reception_time + logger.debug "Saving #{alert_db}" if !alert_db.save @@ -431,7 +445,7 @@ module Mauve else msg = alert_db.errors.inspect end - logger.error "Couldn't save update #{alert} because of #{msg}" unless alert_db.save + logger.error "Couldn't save update #{alert} because of #{msg}" end end diff --git a/lib/mauve/mauve_time.rb b/lib/mauve/mauve_time.rb index 2251c53..79fa4f3 100644 --- a/lib/mauve/mauve_time.rb +++ b/lib/mauve/mauve_time.rb @@ -124,7 +124,7 @@ class Time # # Make sure now is the correct class # - now now.to_time if now.is_a?(DateTime) + now = now.to_time if now.is_a?(DateTime) raise ArgumentError, "now must be a Time" unless now.is_a?(Time) diff --git a/lib/mauve/notifier.rb b/lib/mauve/notifier.rb index ce8c2b0..5c0e5a7 100644 --- a/lib/mauve/notifier.rb +++ b/lib/mauve/notifier.rb @@ -25,7 +25,7 @@ module Mauve logger.debug("Notifier buffer is #{sz} in length") - (sz > 10 ? 10 : sz).times do + (sz > 50 ? 50 : sz).times do person, level, alert = Server.notification_pop begin person.do_send_alert(level, alert) diff --git a/lib/mauve/notifiers/templates/email.txt.erb b/lib/mauve/notifiers/templates/email.txt.erb index eb49da9..1bc79a4 100644 --- a/lib/mauve/notifiers/templates/email.txt.erb +++ b/lib/mauve/notifiers/templates/email.txt.erb @@ -1,11 +1,11 @@ <%= alert.update_type.upcase %>: <% case alert.update_type when :cleared -%><%= MauveTime.now.to_s_relative(alert.cleared_at.to_time) %><% +%><%= alert.cleared_at.to_s_relative %><% when :acknowleged -%><%= MauveTime.now.to_s_relative(alert.acknowledged_at.to_time) %><% +%><%= alert.acknowledged_at.to_s_relative %><% else -%><%= MauveTime.now.to_s_relative(alert.raised_at.to_time) %><% +%><%= alert.raised_at.to_s_relative %><% end %>: <%= alert.summary %><% if alert.source != alert.subject diff --git a/lib/mauve/notifiers/templates/xmpp.txt.erb b/lib/mauve/notifiers/templates/xmpp.txt.erb index 22e2d8c..30ff1e6 100644 --- a/lib/mauve/notifiers/templates/xmpp.txt.erb +++ b/lib/mauve/notifiers/templates/xmpp.txt.erb @@ -7,7 +7,7 @@ when :acknowleged else %><%= MauveTime.now.to_s_relative(alert.raised_at.to_time) %><% end -%>: <%= alert.summary %><% +%>: <%= alert.subject %> <%= alert.summary %><% if alert.source != alert.subject %> -- from <%= alert.source %><% end diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb index 034ba34..a46f229 100644 --- a/lib/mauve/processor.rb +++ b/lib/mauve/processor.rb @@ -36,7 +36,7 @@ module Mauve # Only do the loop a maximum of 10 times every @sleep_interval seconds # - (sz > 10 ? 10 : sz).times do + (sz > 50 ? 50 : sz).times do data, client, received_at = Server.packet_pop @logger.debug("Got #{data.inspect} from #{client.inspect}") |