Skip to content

Commit

Permalink
Merge pull request #13991 from agrare/bz_1419872_snapshot_failure_not…
Browse files Browse the repository at this point in the history
…ifications

Create a notification when a snapshot operation fails
  • Loading branch information
blomquisg authored Apr 24, 2017
2 parents fbf1f4d + 6f68389 commit 571fca1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/models/vm_or_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1855,6 +1855,14 @@ def check_feature_support(message_prefix)
[true, nil]
end

def create_notification(type, options)
Notification.create!(
:type => type,
:subject => self,
:options => options
)
end

# this is verbose, helper for generating arel
def self.arel_coalesce(values)
Arel::Nodes::NamedFunction.new('COALESCE', values)
Expand Down
3 changes: 3 additions & 0 deletions app/models/vm_or_template/operations/snapshot.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ module VmOrTemplate::Operations::Snapshot

def raw_create_snapshot(name, desc = nil, memory)
run_command_via_parent(:vm_create_snapshot, :name => name, :desc => desc, :memory => memory)
rescue => err
create_notification(:vm_snapshot_failure, :error => err.to_s, :snapshot_op => "create")
raise MiqVmSnapshotError, err.to_s
end

def create_snapshot(name, desc = nil, memory = false)
Expand Down
5 changes: 5 additions & 0 deletions db/fixtures/notification_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,8 @@
:expires_in: 24.hours
:level: :success
:audience: global
- :name: vm_snapshot_failure
:message: 'Failed to %{snapshot_op} snapshot of %{subject}: %{error}'
:expires_in: 24.hours
:level: :warning
:audience: global

0 comments on commit 571fca1

Please sign in to comment.