diff options
-rwxr-xr-x | bytemark_example_alerts.sh | 10 | ||||
-rw-r--r-- | lib/mauve/alert.rb | 36 | ||||
-rw-r--r-- | lib/mauve/processor.rb | 2 | ||||
-rw-r--r-- | lib/mauve/web_interface.rb | 9 | ||||
-rw-r--r-- | views/_alerts_table_alert_summary.haml | 1 | ||||
-rw-r--r-- | views/_alerts_table_group.haml | 22 |
6 files changed, 47 insertions, 33 deletions
diff --git a/bytemark_example_alerts.sh b/bytemark_example_alerts.sh index 7d05583..c606423 100755 --- a/bytemark_example_alerts.sh +++ b/bytemark_example_alerts.sh @@ -36,8 +36,14 @@ $PRE -o thresholds -i 1 -u bl1-1.bytemark.co.uk \ -s "bl1-1 exceeded 10Mb/s on bond0" \ -d "<h1>Hello there</h1><p>Here is a paragraph</p><p>And another one</p>" -$PRE -o thresholds -i 2 -u bl1-11.bytemark.co.uk \ - -s "bl1-11 has less than 1GB free memory" +$PRE -o thresholds -i 2 -u bl1-1.bytemark.co.uk \ + -s "bl1-1 has less than 1GB free memory" + +$PRE -o vmhs -i 3 -u bl1-1.bytemark.co.uk \ + -s "bl1-1 is shagged." + +$PRE -o networkmonitor -i 4 -u bl1-1.bytemark.co.uk \ + -s "bl1-1 is shagged. Awooga" $PRE -o thresholds -i 3 -u rom.sh.bytemark.co.uk \ -s "rom.sh.bytemark.co.uk has 1/2 discs available in /dev/md0" \ diff --git a/lib/mauve/alert.rb b/lib/mauve/alert.rb index df10741..c234f03 100644 --- a/lib/mauve/alert.rb +++ b/lib/mauve/alert.rb @@ -120,13 +120,24 @@ module Mauve # AlertGroup.matches must always return a an array of groups. # def alert_group - AlertGroup.matches(self).first + @alert_group ||= AlertGroup.matches(self).first end + # + # + # def level - self.alert_group.level + @level ||= self.alert_group.level end - + + def sort_tuple + [AlertGroup::LEVELS.index(self.level), (self.raised_at.to_time || self.cleared_at.to_time || Time.now)] + end + + def <=>(other) + other.sort_tuple <=> self.sort_tuple + end + def subject; attribute_get(:subject) || attribute_get(:source) ; end def detail; attribute_get(:detail) || "_No detail set._" ; end @@ -147,8 +158,11 @@ module Mauve public def acknowledge!(person, ack_until = Time.now+3600) + raise ArgumentError unless person.is_a?(Person) + raise ArgumentError unless ack_until.is_a?(Time) + self.acknowledged_by = person.username - self.acknowledged_at = MauveTime.now + self.acknowledged_at = Time.now self.update_type = :acknowledged self.will_unacknowledge_at = ack_until logger.error("Couldn't save #{self}") unless save @@ -211,20 +225,6 @@ module Mauve !raised? end - def sort_tuple - # - # raised > cleared - # unacknowldged > acknowledged - # raise / clear time - # level - # - [(self.raised? ? 1 : 0), AlertGroup::LEVELS.index(self.level), (self.raised? ? self.raised_at : self.cleared_at), self.subject, self.summary].collect{|x| x.nil? ? "" : x } - end - - def <=>(other) - self.sort_tuple <=> other.sort_tuple - end - class << self # diff --git a/lib/mauve/processor.rb b/lib/mauve/processor.rb index 9a5c84b..034ba34 100644 --- a/lib/mauve/processor.rb +++ b/lib/mauve/processor.rb @@ -65,7 +65,7 @@ module Mauve DataObjects::IntegrityError => ex @logger.error "#{ex} (#{ex.class}) while parsing #{data.length} bytes "+ - "starting '#{data[0..16].inspect}' from #{ip_source}" + "starting '#{data[0..15].inspect}' from #{ip_source}" @logger.debug ex.backtrace.join("\n") diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb index 2d67957..721fc3f 100644 --- a/lib/mauve/web_interface.rb +++ b/lib/mauve/web_interface.rb @@ -163,6 +163,7 @@ module Mauve @title += " Alerts " + case @alert_type when "raised" @grouped_alerts = group_by(@alerts_raised, @group_by) @@ -359,17 +360,21 @@ module Mauve results = Hash.new{|h,k| h[k] = Array.new} - things.each do |thing| + things.sort.each do |thing| + self.class._logger.debug [AlertGroup::LEVELS.index(thing.level), (thing.raised_at || thing.cleared_at) ].inspect results[thing.__send__(meth)] << thing end - results + results.sort do |a,b| + [a[1].first, a[0]] <=> [b[1].first, b[0]] + end end def find_active_alerts @alerts_raised = Alert.all_raised @alerts_cleared = Alert.all_cleared @alerts_ackd = Alert.all_acknowledged + # # Tot up the levels for raised alerts. # diff --git a/views/_alerts_table_alert_summary.haml b/views/_alerts_table_alert_summary.haml index a06ccb8..24162c6 100644 --- a/views/_alerts_table_alert_summary.haml +++ b/views/_alerts_table_alert_summary.haml @@ -1,4 +1,5 @@ - alert = alerts_table_alert_summary if defined? alerts_table_alert_summary +- row_class = (row_class || []) + [ cycle(nil, "hilight"), alert.raised? && "triggered", alert.acknowledged? && "acknowledged", alert.level] %tr{ :class => row_class, :id => ["tr", "summary", alert.id] } %td %input{ :type => "checkbox", :id => "alerts[#{alert.id}]", :name => "alerts[#{alert.id}]", :class => 'alert' } diff --git a/views/_alerts_table_group.haml b/views/_alerts_table_group.haml index 8bc73b4..6507377 100644 --- a/views/_alerts_table_group.haml +++ b/views/_alerts_table_group.haml @@ -1,14 +1,16 @@ -# Sanity checking. - group, alerts = alerts_table_group unless alerts_table_group.nil? -- hilight = cycle(nil,"hilight") -- row_class = [ hilight, alerts.first.raised? && "triggered", alerts.first.acknowledged? && "acknowledged", alerts.first.level] -=partial("alerts_table_alert_summary", :locals => {:alert => alerts.pop, :row_class => row_class }) -- if alerts.length > 1 - %tr{ :class => [ hilight, alerts.first.raised? && "triggered", alerts.first.acknowledged? && "acknowledged"]} +- if alerts.length <= 2 + =partial("alerts_table_alert_summary", :collection => alerts) +- else + =partial("alerts_table_alert_summary", :collection => [alerts.first]) + =partial("alerts_table_alert_summary", :collection => alerts[1..-1], :locals => {:row_class => ["hidden"]}) + %tr{:id => ["tr","group",group]} %td %td{:colspan => 2} - - if alerts.length == 2 - There is one more alert in this group. - - else - There is #{alerts.length - 1} more alerts in this group. - =partial("alerts_table_alert_summary", :collection => alerts[1..-1], :locals => { :row_class => row_class + ["hidden"] }) + There are + %a{:onclick => alerts[1..-1].collect{|a| "$('#tr_summary_#{a.id}').toggle();"}.join + " return false;", :href => "#"} + =alerts.length - 1 + more alerts + for the #{@group_by} <em>#{group}</em>. + |