Guest User

Untitled

a guest
Jan 23rd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. # cookbooks/chef_notifier/libraries/chef_notifier.rb
  2. #
  3. # This monkeypatches Chef::Runner to report the result of run_action calls via MCollective
  4.  
  5. require 'mcollective'
  6.  
  7. class MRPC
  8. include MCollective::RPC
  9. def report_action(resource, action)
  10. options = MCollective::Util.default_options
  11. mc = rpcclient("chef_reporter", {:options => options})
  12. reqid = mc.log_action(
  13. :msg => {
  14. :resource => "#{resource}",
  15. :action => "#{action}",
  16. :updated? => "#{resource.updated_by_last_action?}",
  17. },
  18. :process_results => false)
  19. Chef::Log.debug "Sent status to MCollective with reqid #{reqid}"
  20. mc.disconnect
  21. end
  22. end
  23.  
  24. class Chef
  25. class Runner
  26. alias_method :run_action_original, :run_action
  27. def run_action(resource, action)
  28. Chef::Log.debug "Wrapping run_action on #{resource} with MRPC.report_action"
  29. run_action_original(resource, action)
  30. MRPC.new.report_action(resource, action)
  31. end
  32. end
  33. end
Add Comment
Please, Sign In to add comment