1
0

manual_event_agent.rb 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. module Agents
  2. class ManualEventAgent < Agent
  3. cannot_be_scheduled!
  4. cannot_receive_events!
  5. description <<-MD
  6. The Manual Event Agent is used to manually create Events for testing or other purposes.
  7. Do not set options for this Agent. Instead, connect it to other Agents and create Events
  8. using the UI provided on this Agent's Summary page.
  9. MD
  10. event_description "User determined"
  11. def default_options
  12. { "no options" => "are needed" }
  13. end
  14. def handle_details_post(params)
  15. if params['payload']
  16. json = interpolate_options(JSON.parse(params['payload']))
  17. if json['payloads'] && (json.keys - ['payloads']).length > 0
  18. { :success => false, :error => "If you provide the 'payloads' key, please do not provide any other keys at the top level." }
  19. else
  20. [json['payloads'] || json].flatten.each do |payload|
  21. create_event(:payload => payload)
  22. end
  23. { :success => true }
  24. end
  25. else
  26. { :success => false, :error => "You must provide a JSON payload" }
  27. end
  28. end
  29. def working?
  30. true
  31. end
  32. def validate_options
  33. end
  34. end
  35. end