manual_event_agent.rb 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. Connect this Agent to other Agents and create Events using the UI provided on this Agent's Summary page.
  8. You can set the default event payload via the "payload" option.
  9. MD
  10. event_description do
  11. "Events are editable in the UI. The default value is this:\n\n " +
  12. Utils.pretty_print(options["payload"].presence || {})
  13. end
  14. def default_options
  15. { "payload" => {} }
  16. end
  17. def handle_details_post(params)
  18. if params['payload']
  19. json = interpolate_options(JSON.parse(params['payload']))
  20. if json['payloads'] && (json.keys - ['payloads']).length > 0
  21. { success: false,
  22. error: "If you provide the 'payloads' key, please do not provide any other keys at the top level." }
  23. else
  24. [json['payloads'] || json].flatten.each do |payload|
  25. create_event(payload:)
  26. end
  27. { success: true }
  28. end
  29. else
  30. { success: false, error: "You must provide a JSON payload" }
  31. end
  32. end
  33. def working?
  34. true
  35. end
  36. def validate_options
  37. end
  38. end
  39. end