diff options
-rw-r--r-- | lib/mauve/web_interface.rb | 120 | ||||
-rw-r--r-- | views/_alerts_table_alert_summary.haml | 4 | ||||
-rw-r--r-- | views/_head.haml | 7 | ||||
-rw-r--r-- | views/_navbar.haml | 11 |
4 files changed, 90 insertions, 52 deletions
diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb index f9cf0fd..889c676 100644 --- a/lib/mauve/web_interface.rb +++ b/lib/mauve/web_interface.rb @@ -88,6 +88,11 @@ EOF @title = "Mauve:" @person = nil # + # Set our alert counts hash up, needed by the navbar. + # + @alert_counts = Hash.new{|h,k| h[k] = 0} + + # # Make sure we're authenticated. # if session.has_key?('username') and Configuration.current.people.has_key?(session['username'].to_s) @@ -110,9 +115,7 @@ EOF # Set up some defaults. # @group_by = "subject" - @alerts_ackd = [] - @alerts_cleared = [] - @alerts_raised = [] + else # Uh-oh.. Intruder alert! # @@ -198,10 +201,12 @@ EOF end get '/alerts/:alert_type/:group_by' do - return haml(:not_implemented) unless %w(raised acknowledged).include?(params[:alert_type]) - alerts_table(params) + @alert_type = params[:alert_type] == "acknowledged" ? "acknowledged" : "raised" + @alert_counts = alert_counts(true) + @grouped_alerts = alerts_table(@alert_type, params[:group_by]) + @title += " #{@alert_type.capitalize}: " haml(:alerts) end @@ -283,7 +288,6 @@ EOF else type_hours = "daytime" unless %w(daytime working wallclock).include?(type_hours) ack_until = now.in_x_hours(n_hours, type_hours) - pp ack_until ack_until = max_ack if ack_until > max_ack end @@ -305,16 +309,16 @@ EOF get '/ajax/alert_counts' do content_type :json - counts = Hash.new{|h,k| h[k] = 0} - - Alert.all_unacknowledged.each{|a| counts[a.level] += 1} + alert_counts = alert_counts(true) - (AlertGroup::LEVELS.reverse.collect{|l| counts[l]}+ - [Alert.all_acknowledged.length, 0]).to_json + [:urgent, :normal, :low, :acknowledged, :cleared].collect{|k| alert_counts[k]}.to_json end get '/ajax/alerts_table/:alert_type/:group_by' do - alerts_table(params) + return haml(:not_implemented, :layout => false) unless %w(raised acknowledged).include?(params[:alert_type]) + + @alert_type = params[:alert_type] == "acknowledged" ? "acknowledged" : "raised" + @grouped_alerts = alerts_table(@alert_type, params[:group_by]) haml :_alerts_table, :layout => false end @@ -350,6 +354,7 @@ EOF get '/alert/:id' do @alert = Alert.get!(params['id']) + @alert_counts = alert_counts(false) haml :alert end @@ -428,6 +433,8 @@ EOF query[:history][:type] = ["update", "notification"] @alert = Alert.get!(params['id']) + @title += " Events: Alert #{alert.alert_id} from #{alert.source}" + @alert_counts = alert_counts(false) @events = find_events(query) haml :events_list @@ -488,6 +495,9 @@ EOF end @today = start + @title += " Events" + @alert_counts = alert_counts(false) + haml :events_calendar end @@ -529,25 +539,27 @@ EOF query[:history][:created_at.lt] = finish @events = find_events(query) + @alert_counts = alert_counts(false) haml :events_list end get '/search' do @alerts = [] - haml :search - end - - get '/search/results' do - query = {} - allowed = %w(source subject alert_id summary) + @alert_counts = alert_counts(false) + @q = params[:q] || nil + @title += " Search:" + @min_length = 3 - params.each do |k,v| - next if v.to_s.empty? - query[k.to_sym.send("like")] = v.to_s if allowed.include?(k) - end + @q = @q.to_s.strip unless @q.nil? - @alerts = Alert.all(query) + unless @q.nil? or @q.length < @min_length + %w(source subject alert_id summary).each do |field| + @alerts += Alert.all(field.to_sym.send("like") => "%#{@q}%") + end + + @title += " #{@alerts.count} records found." + end haml :search end @@ -578,30 +590,20 @@ EOF end end - def alerts_table(params) - if %w(raised cleared acknowledged).include?(params[:alert_type]) - @alert_type = params[:alert_type] - else - @alert_type = "raised" + def alerts_table(alert_type, group_by) + unless %w(subject source summary id alert_id level).include?(group_by) + group_by = "subject" end - if %w(subject source summary id alert_id level).include?(params[:group_by]) - @group_by = params[:group_by] - else - @group_by = "subject" - end - - @title += " Alerts " - - case @alert_type + case alert_type when "raised" - @alerts = Alert.all_unacknowledged - @grouped_alerts = group_by(@alerts, @group_by) + alerts = Alert.all_unacknowledged + group_by(alerts, group_by) when "acknowledged" - @alerts = Alert.all_acknowledged - @grouped_alerts = group_by(@alerts, @group_by) + alerts = Alert.all_acknowledged + group_by(alerts, group_by) else - haml(:not_implemented) + [] end end @@ -611,6 +613,40 @@ EOF list[@cycle] end + # + # Returns a hash which contains the counts of: + # + # * all raised alerts (:raised) + # * all cleared alerts (:cleared) + # * all raised and acknowledged alerts (:acknowledged) + # * all raised and unacknowledged alerts (:unacknowledged) + # + # If by_level is true, then alerts are counted up by level too. + # + # * all raised and unacknowledged alerts by level (:urgent, :normal, :low) + # + # + def alert_counts(by_level = false) + counts = Hash.new + counts[:raised] = Alert.all_raised.count + counts[:cleared] = Alert.all.count - counts[:raised] + counts[:acknowledged] = Alert.all_acknowledged.count + counts[:unacknowledged] = counts[:raised] - counts[:acknowledged] + + if by_level + # + # Now we need to work out the levels + # + [:urgent, :normal, :low].each{|k| counts[k] = 0} + Alert.all_unacknowledged.each do |a| + counts[a.level] += 1 + end + end + + counts + end + + def find_events(query = Hash.new) if params["history"] diff --git a/views/_alerts_table_alert_summary.haml b/views/_alerts_table_alert_summary.haml index 3b03cb0..4159cf7 100644 --- a/views/_alerts_table_alert_summary.haml +++ b/views/_alerts_table_alert_summary.haml @@ -7,10 +7,10 @@ %label{ :for => "alerts[#{alert.id}]" } %strong= alert.subject = alert.summary + - if alert.suppressed? + (suppressed) %a{ :id => ["a","detail", alert.id], | :href => "/alert/#{alert.id}", | :onclick => "fetchDetail('#{alert.id}'); return false;"} - - if alert.suppressed? - (suppressed) Details ↓ %td= (alert.raised_at || alert.cleared_at || Time.now).to_s_relative diff --git a/views/_head.haml b/views/_head.haml index 642d408..5bcd6ae 100644 --- a/views/_head.haml +++ b/views/_head.haml @@ -1,5 +1,10 @@ %head - %title= @title + %title + = @title + - if[:urgent, :normal, :low].all?{|k| @alert_counts.has_key?(k) } + [ + = [:urgent, :normal, :low].collect{|l| @alert_counts[l]}.join(" / ") + ] %meta{:name => "viewport", :content => "width=device-width, initial-scale=1.0, maximum-scale=2.0, user-scalable=yes"}/ %link{:rel => "stylesheet", :href => "/stylesheets/bytemark.css"}/ %link{:rel => "stylesheet", :href => "/stylesheets/mauve.css", :media => "all", :type => "text/css"}/ diff --git a/views/_navbar.haml b/views/_navbar.haml index 8b16c55..bd23308 100644 --- a/views/_navbar.haml +++ b/views/_navbar.haml @@ -6,18 +6,15 @@ %li{:class => [ @alert_type == "raised" && "nav_selected"]} %a{:href => '/alerts/raised/'+@group_by} Raised ( - %span#count_raised><= @alerts_raised.length + %span#count_raised><= @alert_counts[:unacknowledged] ) %li{:class => [ @alert_type == "acknowledged" && "nav_selected"]} %a{:href => '/alerts/acknowledged/'+@group_by} Ack'd ( - %span#count_ackd><= @alerts_ackd.length - ) - %li{:class => [ @alert_type == "cleared" && "nav_selected"]} - %a{:href => '/alerts/cleared/'+@group_by} - Cleared ( - %span#count_cleared><= @alerts_cleared.length + %span#count_ackd><= @alert_counts[:acknowledged] ) + %li{:class => [ request.path_info =~ /^\/search/ && "nav_selected"]} + %a{:href => '/search'} Search %li{:class => [ request.path_info =~ /^\/events/ && "nav_selected"]} %a{:href => '/events/calendar'} Events %li |