aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/mauve/web_interface.rb188
-rw-r--r--views/_acknowledge_input.haml34
-rw-r--r--views/_alert_actions.haml61
-rw-r--r--views/alert.haml19
-rw-r--r--views/alerts.haml4
-rw-r--r--views/search.haml4
6 files changed, 186 insertions, 124 deletions
diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb
index 3eedaea..9cc6352 100644
--- a/lib/mauve/web_interface.rb
+++ b/lib/mauve/web_interface.rb
@@ -208,14 +208,30 @@ EOF
@grouped_alerts = alerts_table(@alert_type, params[:group_by])
@title += " #{@alert_type.capitalize}: "
+ @permitted_actions = []
+ @permitted_actions << "clear"
+
+ unless @alert_type == "acknowledged"
+ @permitted_actions << "acknowledge"
+ else
+ @permitted_actions << "unacknowledge"
+ end
+
+ #
+ # Always allow suppress and unsuppress
+ #
+ @permitted_actions << "suppress"
+ @permitted_actions << "unsuppress"
+
haml(:alerts)
end
- post '/alerts/acknowledge' do
+ post '/alerts' do
#
# TODO: error check inputs
#
# ack_until is in milliseconds!
+ function = params[:function] || "acknowledge"
ack_until = params[:ack_until]
n_hours = params[:n_hours] || 2
type_hours = params[:type_hours] || "daytime"
@@ -224,15 +240,17 @@ EOF
n_hours = (n_hours.to_f > 188 ? 188 : n_hours.to_f)
type_hours = "daytime" unless %w(daytime working wallclock).include?(type_hours)
-
- if ack_until.to_s.empty?
- now = Time.now
- ack_until = now.in_x_hours(n_hours, type_hours.to_s)
- else
- ack_until = Time.at(ack_until.to_i)
+ function = "acknowledge" unless %w(raise clear acknowledge unacknowledge unsuppress suppress).include?(function)
+
+ if %w(suppress acknowledge).include?(function)
+ if ack_until.to_s.empty?
+ now = Time.now
+ ack_until = now.in_x_hours(n_hours, type_hours.to_s)
+ else
+ ack_until = Time.at(ack_until.to_i)
+ end
end
- succeeded = []
failed = []
alerts.each do |k,v|
@@ -244,8 +262,25 @@ EOF
end
begin
- a.acknowledge!(@person, ack_until)
- succeeded << a
+ result = case function
+ when "raise"
+ a.raise!
+ when "clear"
+ a.clear!
+ when "acknowledge"
+ a.acknowledge!(@person, ack_until)
+ when "unacknowledge"
+ a.unacknowledge!
+ when "suppress"
+ a.suppress_until = ack_until
+ a.save
+ when "unsuppress"
+ a.suppress_until = nil
+ a.save
+ end
+ unless result
+ failed << a
+ end
rescue StandardError => ex
logger.error "Caught #{ex.to_s} when trying to save #{a.inspect}"
logger.debug ex.backtrace.join("\n")
@@ -261,10 +296,9 @@ EOF
logger.debug h.errors unless h.save
end
- flash["error"] = "Failed to acknowledge #{failed.length} alerts." if failed.length > 0
- flash["notice"] = "Successfully acknowledged #{succeeded.length} alerts" if succeeded.length > 0
+ flash["error"] = "Failed to #{function} #{failed.length} alerts." if failed.length > 0
- redirect "/alerts/raised"
+ redirect back
end
######################################################
@@ -356,76 +390,85 @@ EOF
@alert = Alert.get!(params['id'])
@alert_counts = alert_counts(false)
+ @permitted_actions = []
+ unless @alert.raised?
+ @permitted_actions << "raise"
+ else
+ @permitted_actions << "clear"
+
+ unless @alert.acknowledged?
+ @permitted_actions << "acknowledge"
+ else
+ @permitted_actions << "unacknowledge"
+ end
+ end
+
+ unless @alert.suppressed?
+ @permitted_actions << "suppress"
+ else
+ @permitted_actions << "unsuppress"
+ end
+
+
haml :alert
end
- post '/alert/:id/acknowledge' do
+ post '/alert/:id' do
alert = Alert.get(params[:id])
+ function = params[:function]
ack_until = params[:ack_until].to_i
n_hours = params[:n_hours].to_f
type_hours = params[:type_hours].to_s
note = params[:note] || nil
type_hours = "daytime" unless %w(daytime working wallclock).include?(type_hours)
+ function = "acknowledge" unless %w(raise clear acknowledge unacknowledge suppress unsuppress).include?(function)
+
+ if %w(suppress acknowledge).include?(function)
+ if ack_until == 0
+ now = Time.now
+ ack_until = now.in_x_hours(n_hours, type_hours)
+ else
+ ack_until = Time.at(ack_until)
+ end
+ end
- if ack_until == 0
- now = Time.now
- ack_until = now.in_x_hours(n_hours, type_hours)
- else
- ack_until = Time.at(ack_until)
+ result = case function
+ when "raise"
+ alert.raise!
+ when "clear"
+ alert.clear!
+ when "acknowledge"
+ alert.acknowledge!(@person, ack_until)
+ when "unacknowledge"
+ alert.unacknowledge!
+ when "suppress"
+ alert.suppress_until = ack_until
+ alert.save
+ when "unsuppress"
+ alert.suppress_until = nil
+ alert.save
end
- alert.acknowledge!(@person, ack_until)
+ if result
+ #
+ # Add the note
+ #
+ unless note.to_s.empty?
+ h = History.new(:alerts => [alert], :type => "note", :event => note.to_s, :user => session['username'])
+ logger.debug h.errors unless h.save
+ end
- #
- # Add the note
- #
- unless note.to_s.empty?
- h = History.new(:alerts => [alert], :type => "note", :event => note.to_s, :user => session['username'])
- logger.debug h.errors unless h.save
+ else
+ flash['warning'] = "Failed to #{function} alert <em>#{alert.alert_id}</em> from source #{alert.source}."
end
-
- flash['notice'] = "Successfully acknowledged alert <em>#{alert.alert_id}</em> from source #{alert.source} until #{alert.will_unacknowledge_at.to_s_human}."
- redirect "/alert/#{alert.id}"
- end
-
- post '/alert/:id/unacknowledge' do
- alert = Alert.get!(params[:id])
- alert.unacknowledge!
- flash['notice'] = "Successfully raised alert #{alert.alert_id} from source #{alert.source}."
- redirect "/alert/#{alert.id}"
- end
- post '/alert/:id/raise' do
- alert = Alert.get!(params[:id])
- alert.raise!
- flash['notice'] = "Successfully raised alert #{alert.alert_id} from source #{alert.source}."
- redirect "/alert/#{alert.id}"
- end
-
- post '/alert/:id/clear' do
- alert = Alert.get(params[:id])
- alert.clear!
- flash['notice'] = "Successfully cleared alert #{alert.alert_id} from source #{alert.source}."
- redirect "/alert/#{alert.id}"
- end
-
- post '/alert/:id/destroy' do
- alert = Alert.get(params[:id])
- alert.destroy
- flash['notice'] = "Successfully destroyed alert #{alert.alert_id} from source #{alert.source}."
- redirect "/"
+ redirect back
end
########################################################################
- get '/preferences' do
- haml :preferences
- end
-
- ########################################################################
-
get '/events/alert/:id' do
query = {:alert => {}, :history => {}}
query[:alert][:id] = params[:id]
@@ -433,7 +476,7 @@ EOF
query[:history][:type] = ["update", "notification"]
@alert = Alert.get!(params['id'])
- @title += " Events: Alert #{alert.alert_id} from #{alert.source}"
+ @title += " Events: Alert #{@alert.alert_id} from #{@alert.source}"
@alert_counts = alert_counts(false)
@events = find_events(query)
@@ -554,21 +597,26 @@ EOF
@q = @q.to_s.strip unless @q.nil?
unless @q.nil? or @q.length < @min_length
+ alerts = []
%w(source subject alert_id summary).each do |field|
- @alerts += Alert.all(field.to_sym.send("like") => "%#{@q}%")
+ alerts += Alert.all(field.to_sym.send("like") => "%#{@q}%")
end
- @alerts = @alerts.sort
+
+ @alerts = alerts.sort.uniq
@title += " #{@alerts.count} records found."
end
- haml :search
- end
+ @permitted_actions = []
+ @permitted_actions << "clear" if @alerts.any?{|a| a.raised?}
+ @permitted_actions << "raise" if @alerts.any?{|a| a.cleared?}
+ @permitted_actions << "acknowledge" if @alerts.any?{|a| !a.acknowledged?}
+ @permitted_actions << "unacknowledge" if @alerts.any?{|a| a.acknowledged?}
+ @permitted_actions << "unsuppress" if @alerts.any?{|a| a.suppressed? }
+ @permitted_actions << "suppress" if @alerts.any?{|a| !a.suppressed? }
- post '/suppress' do
- haml :suppress
+ haml :search
end
-
########################################################################
helpers do
diff --git a/views/_acknowledge_input.haml b/views/_acknowledge_input.haml
deleted file mode 100644
index 82f3044..0000000
--- a/views/_acknowledge_input.haml
+++ /dev/null
@@ -1,34 +0,0 @@
-Acknowledge these alerts for
-%input#n_hours{ :name => 'n_hours', :type => "number", :min => 0, :max => 48, :value => 2, :style => "min-width: 6ex;"}
-%select#type_hours{:name => 'type_of_hours' }
- -# Default to daytime hours
- %option{ :value => "working" } working
- %option{ :value => "daytime", :selected => "selected"} daytime
- %option{ :value => "wallclock" } wall-clock
-hours
-%span#ack_until_text
-%input#ack_until{ :value => '', :type => :hidden, :name => 'ack_until' }
-%br
-with the note
-%input#note{ :name => 'note', :type => "text"}
-%input{ :type => 'submit', :value => 'Go!' }
-:javascript
- // Change of value in the hours box
- $('#n_hours').change( function() {
- updateDate();
- });
- // As above, but on keypress, with a delay
- $('#n_hours').keyup( function() {
- clearTimeout($.data(this, 'timer'));
- var wait = setTimeout(updateDate, 500);
- $(this).data('timer', wait);
- });
- // Same as the n_hours change function
- $('#type_hours').change( function() {
- $('#n_hours').change();
- });
- // Setup the ack text on load.
- $(document).ready( function() {
- $('#n_hours').change();
- });
-
diff --git a/views/_alert_actions.haml b/views/_alert_actions.haml
new file mode 100644
index 0000000..2f4eb57
--- /dev/null
+++ b/views/_alert_actions.haml
@@ -0,0 +1,61 @@
+%select#function{ :name => 'function'}
+ - if @permitted_actions.include?("acknowledge")
+ %option{:value => "acknowledge"} Acknowledge
+ - if @permitted_actions.include?("suppress")
+ %option{:value => "suppress"} Suppress notifications about
+ - if @permitted_actions.include?("raise")
+ %option{:value => "raise"} Raise
+ - if @permitted_actions.include?("unacknowledge")
+ %option{:value => "unacknowledge"} Unacknowledge
+ - if @permitted_actions.include?("clear")
+ %option{:value => "clear"} Clear
+ - if @permitted_actions.include?("unsuppress")
+ %option{:value => "unsuppress"} Unsuppress notifications about
+- if defined? @alert
+ this alert
+- else
+ these alerts
+%span#hours_input
+ for
+ %input#n_hours{ :name => 'n_hours', :type => "number", :min => 0, :max => 48, :value => 2, :style => "min-width: 6ex;"}
+ %select#type_hours{:name => 'type_of_hours' }
+ -# Default to daytime hours
+ %option{ :value => "working" } working
+ %option{ :value => "daytime", :selected => "selected"} daytime
+ %option{ :value => "wallclock" } wall-clock
+ hours
+ %span#ack_until_text
+ %input#ack_until{ :value => '', :type => :hidden, :name => 'ack_until' }
+%br
+with the note
+%input#note{ :name => 'note', :type => "text"}
+%input{ :type => 'submit', :value => 'Go!' }
+:javascript
+ // Make the hours bit disappear when clearing alerts.
+ $('#function').change( function() {
+ if( $('#function').val() == "acknowledge" || $('#function').val() == "suppress" ) {
+ $('#hours_input').show();
+ } else {
+ $('#hours_input').hide();
+ }
+ });
+ // Change of value in the hours box
+ $('#n_hours').change( function() {
+ updateDate();
+ });
+ // As above, but on keypress, with a delay
+ $('#n_hours').keyup( function() {
+ clearTimeout($.data(this, 'timer'));
+ var wait = setTimeout(updateDate, 500);
+ $(this).data('timer', wait);
+ });
+ // Same as the n_hours change function
+ $('#type_hours').change( function() {
+ $('#n_hours').change();
+ });
+ // Setup the ack text on load.
+ $(document).ready( function() {
+ $('#n_hours').change();
+ $('#function').change();
+ });
+
diff --git a/views/alert.haml b/views/alert.haml
index 6aa2e23..ef8d0f6 100644
--- a/views/alert.haml
+++ b/views/alert.haml
@@ -1,4 +1,4 @@
-%h1 Alert detail
+%h2 Alert detail
%table
%tr
%th.summary{:title => "Text for humans describing the nature of the alert, first 100 characters are only ones guaranteed to make it to pagers, twitter, SMS etc."} Summary
@@ -60,19 +60,6 @@
%a{:href => "/events/alert/#{@alert.id}"}
View full event history
%h2 Actions
-- if !@alert.acknowledged?
- %form{:method => :post, :action => "/alert/#{@alert.id}/acknowledge"}
- =partial("acknowledge_input")
-- else
- %form.hidden{:method => :post, :action => "/alert/#{@alert.id}/unacknowledge"}
- %input{:type => :submit, :value => "Unacknowledge this alert"}
-%a#hide{:onclick => "$('form.hidden').toggle(); return false", :href=>"#"} Show other actions
-- if @alert.cleared?
- %form.hidden{:method => :post, :action => "/alert/#{@alert.id}/raise"}
- %input{:type => :submit, :value => "Raise this alert"}
-- if @alert.raised?
- %form.hidden{:method => :post, :action => "/alert/#{@alert.id}/clear"}
- %input{:type => :submit, :value => "Clear this alert"}
-%form.hidden{:method => :post, :action => "/alert/#{@alert.id}/destroy"}
- %input{:type => :submit, :value => "Destroy this alert"}
+%form{:method => :post, :action => "/alert/#{@alert.id}"}
+ =partial("alert_actions")
diff --git a/views/alerts.haml b/views/alerts.haml
index 88cb82c..9d3b7fc 100644
--- a/views/alerts.haml
+++ b/views/alerts.haml
@@ -1,7 +1,7 @@
-%form#alerts{:method => :post, :action => '/alerts/acknowledge'}
+%form#alerts{:method => :post, :action => '/alerts'}
= partial('alerts_table')
%h2 Actions
- %p= partial('acknowledge_input')
+ %p= partial('alert_actions')
:javascript
// Do the magic updates..
setTimeout("updateAlertsTable('#{@alert_type}','#{@group_by}');", 120000)
diff --git a/views/search.haml b/views/search.haml
index dec227a..27c59ec 100644
--- a/views/search.haml
+++ b/views/search.haml
@@ -13,9 +13,9 @@
=@min_length
characters long.
- else
- %form#alerts{:method => :post, :action => '/alerts/acknowledge'}
+ %form#alerts{:method => :post, :action => '/alerts'}
= partial('search_table')
- unless @alerts.empty?
%h2 Actions
- %p= partial('acknowledge_input')
+ %p= partial('alert_actions')