Skip to content

Commit

Permalink
fix: send audit success event for each attempt for remote invocation …
Browse files Browse the repository at this point in the history
…separetly
  • Loading branch information
yrudman committed Mar 20, 2019
1 parent 6601a1f commit 41a17eb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions app/models/mixins/process_tasks_mixin.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
require 'manageiq-api-client'
module ProcessTasksMixin
extend ActiveSupport::Concern
include RetirementMixin
Expand Down Expand Up @@ -94,9 +95,6 @@ def invoke_tasks_remote(options)
MiqQueue.submit_job(q_hash)
next
end

msg = "'#{options[:task]}' successfully initiated for remote VMs: #{ids.sort.inspect}"
task_audit_event(:success, options, :message => msg)
end
end

Expand All @@ -123,16 +121,26 @@ def invoke_api_tasks(api_client, remote_options)
obj = collection.find(id)
_log.info("Invoking task #{action} on collection #{collection_name}, object #{obj.id}, with args #{post_args}")
obj.send(action, post_args)
rescue NoMethodError, ManageIQ::API::Client::ResourceNotFound => err
msg = "'#{remote_options[:task]}' successfully initiated on remote object #{obj.class}: #{id} for collection #{collection_name}"
task_audit_event(:success, remote_options, :message => msg)
rescue StandardError => err
msg = "'#{remote_options[:task]}' failed on remote object #{id} for collection #{collection_name}"
task_audit_event(:failure, remote_options, :target_id => id, :message => msg)
_log.error(err.message)
raise err unless err.is_a?(NoMethodError) || err.is_a?(ManageIQ::API::Client::ResourceNotFound)
end
end
else
_log.info("Invoking task #{action} on collection #{collection_name}, with args #{post_args}")
begin
collection.send(action, post_args)
rescue NoMethodError => err
msg = "'#{remote_options[:task]}' successfully initiated on collection #{collection_name}, with args #{post_args}"
task_audit_event(:success, remote_options, :message => msg)
rescue StandardError => err
msg = "'#{remote_options[:task]}' failed on remote collection #{collection_name}, with args #{post_args}"
task_audit_event(:failure, remote_options, :message => msg)
_log.error(err.message)
raise err unless err.is_a?(NoMethodError)
end
end
end
Expand Down

0 comments on commit 41a17eb

Please sign in to comment.