Skip to content

Commit

Permalink
Merge pull request ManageIQ#2280 from ZitaNemeckova/add_alert_severity
Browse files Browse the repository at this point in the history
Add severity to Alerts
  • Loading branch information
martinpovolny authored Oct 10, 2017
2 parents 9e4e576 + 5a01dea commit f777e6e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
11 changes: 10 additions & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,8 @@ def view_to_hash(view)
when "result"
new_row[:cells] << {:span => result_span_class(row[col]), :text => row[col].titleize}
when "severity"
new_row[:cells] << {:span => severity_span_class(row[col]), :text => row[col].titleize}
value = row[col] || ' '
new_row[:cells] << {:span => severity_span_class(value), :text => severity_title(value)}
when 'state'
celltext = row[col].titleize
when 'hardware.bitness'
Expand Down Expand Up @@ -1221,6 +1222,14 @@ def severity_span_class(value)
end
end

def severity_title(value)
if self.class.instance_of?(MiqPolicyController)
self.class::SEVERITIES[value]
else
value.titleize
end
end

def listicon_item(view, id = nil)
id = @id if id.nil?

Expand Down
10 changes: 9 additions & 1 deletion app/controllers/miq_policy_controller/alerts.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module MiqPolicyController::Alerts
extend ActiveSupport::Concern

SEVERITIES = {"info" => _('Info'), "warning" => _('Warning'), "error" => _('Error')}.freeze

def alert_edit_cancel
@edit = nil
@alert = session[:edit][:alert_id] ? MiqAlert.find(session[:edit][:alert_id]) : MiqAlert.new
Expand All @@ -16,9 +18,9 @@ def alert_edit_cancel
def alert_edit_save_add
id = params[:id] && params[:button] != "add" ? params[:id] : "new"
return unless load_edit("alert_edit__#{id}", "replace_cell__explorer")

alert = @alert = @edit[:alert_id] ? MiqAlert.find(@edit[:alert_id]) : MiqAlert.new
alert_set_record_vars(alert)

unless alert_valid_record?(alert) && alert.valid? && !@flash_array && alert.save
alert.errors.each do |field, msg|
add_flash("#{field.to_s.capitalize} #{msg}", :error)
Expand Down Expand Up @@ -86,6 +88,7 @@ def alert_field_changed

@edit[:new][:description] = params[:description].blank? ? nil : params[:description] if params[:description]
@edit[:new][:enabled] = params[:enabled_cb] == "1" if params.key?(:enabled_cb)
@edit[:new][:severity] = params[:miq_alert_severity] if params.key?(:miq_alert_severity)
if params[:exp_event]
@edit[:new][:exp_event] = params[:exp_event] == "_hourly_timer_" ? params[:exp_event] : params[:exp_event].to_i
@edit[:new][:repeat_time] = alert_default_repeat_time
Expand Down Expand Up @@ -301,6 +304,7 @@ def alert_build_edit_screen

@edit[:new][:description] = @alert.description
@edit[:new][:enabled] = @alert.enabled == true
@edit[:new][:severity] = @alert.severity
@edit[:new][:db] = @alert.db.nil? ? "Vm" : @alert.db
@edit[:expression_types] = MiqAlert.expression_types(@edit[:new][:db])

Expand Down Expand Up @@ -521,6 +525,7 @@ def alert_build_ems_alarms
def alert_set_record_vars(alert)
alert.description = @edit[:new][:description]
alert.enabled = @edit[:new][:enabled]
alert.severity = @edit[:new][:severity]
alert.db = @edit[:new][:db]
unless @edit[:new][:expression][:eval_method]
alert.expression = @edit[:new][:expression]["???"] ? nil : MiqExpression.new(@edit[:new][:expression])
Expand Down Expand Up @@ -561,6 +566,9 @@ def alert_valid_record?(alert)
if alert.expression.nil?
add_flash(_("A valid expression must be present"), :error)
end
if alert.severity.nil?
add_flash(_('Severity must be selected'), :error)
end
unless @edit[:new][:expression][:eval_method] && @edit[:new][:expression][:eval_method] != "nothing"
add_flash(_("A Driving Event must be selected"), :error) if alert.responds_to_events.blank?
end
Expand Down
17 changes: 17 additions & 0 deletions app/views/miq_policy/_alert_details.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,23 @@
.col-md-8
%p.form-control-static
= @alert.enabled ? _("Yes") : _("No")
.form-group
%label.control-label.col-md-2
= _("Severity")
- if @edit
.col-md-8
- options = [[_("<Choose>"), nil]]
- controller.class::SEVERITIES.each { |key, value| options.push([value, key]) }
= select_tag('miq_alert_severity',
options_for_select(options, @edit[:new][:severity]),
:class => "selectpicker")
:javascript
miqInitSelectPicker();
miqSelectPickerEvent('miq_alert_severity', '#{url}', {beforeSend: true, complete: true})
- else
.col-md-8
%p.form-control-static
= controller.class::SEVERITIES[@alert.severity]
-# Based on (model)
.form-group
%label.control-label.col-md-2
Expand Down
3 changes: 3 additions & 0 deletions product/views/MiqAlert.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cols:
- notify_snmp
- notify_evm_event
- notify_automate
- severity

# Included tables (joined, has_one, has_many) and columns
include:
Expand All @@ -41,6 +42,7 @@ col_order:
- notify_snmp
- notify_evm_event
- notify_automate
- severity

# Column titles, in order
headers:
Expand All @@ -52,6 +54,7 @@ headers:
- SNMP
- Event on Timeline
- Management Event Raised
- Severity

# Condition(s) string for the SQL query
conditions:
Expand Down
1 change: 1 addition & 0 deletions spec/views/miq_policy/_alert_details.html.haml_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
describe "miq_policy/_alert_details.html.haml" do
before do
@alert = FactoryGirl.create(:miq_alert)
SEVERITIES = MiqPolicyController::Alerts::SEVERITIES
exp = {:eval_method => 'nothing', :mode => 'internal', :options => {}}
allow(@alert).to receive(:expression).and_return(exp)
set_controller_for_view("miq_policy")
Expand Down

0 comments on commit f777e6e

Please sign in to comment.