Class: TCellAgent::PolicyPolling
- Inherits:
-
Object
- Object
- TCellAgent::PolicyPolling
- Includes:
- ModuleLoggerAccess
- Defined in:
- lib/tcell_agent/policies/policy_polling.rb
Instance Method Summary collapse
-
#initialize(policies_manager, native_agent) ⇒ PolicyPolling
constructor
A new instance of PolicyPolling.
- #policy_polling_running? ⇒ Boolean
- #start_policy_polling(native_agent) ⇒ Object
- #start_policy_polling_loop(native_agent) ⇒ Object
- #stop_policy_polling ⇒ Object
Methods included from ModuleLoggerAccess
Constructor Details
#initialize(policies_manager, native_agent) ⇒ PolicyPolling
Returns a new instance of PolicyPolling.
5 6 7 8 9 10 11 |
# File 'lib/tcell_agent/policies/policy_polling.rb', line 5 def initialize(policies_manager, native_agent) @policies_manager = policies_manager @policy_polling_worker_mutex = Mutex.new @policy_polling_thread = nil start_policy_polling(native_agent) end |
Instance Method Details
#policy_polling_running? ⇒ Boolean
27 28 29 |
# File 'lib/tcell_agent/policies/policy_polling.rb', line 27 def policy_polling_running? @policy_polling_thread && @policy_polling_thread.alive? end |
#start_policy_polling(native_agent) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/tcell_agent/policies/policy_polling.rb', line 13 def start_policy_polling(native_agent) configuration = TCellAgent.configuration return unless configuration.should_start_policy_poll? return unless configuration.tcell_api_url && configuration.app_id && configuration.api_key return if policy_polling_running? @policy_polling_worker_mutex.synchronize do return if policy_polling_running? start_policy_polling_loop(native_agent) end end |
#start_policy_polling_loop(native_agent) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/tcell_agent/policies/policy_polling.rb', line 36 def start_policy_polling_loop(native_agent) module_logger.debug('Starting policy polling thread') @policy_polling_thread = Thread.new do loop do begin result = native_agent.poll_new_policies policies_and_enablements = result['new_policies_and_enablements'] || {} @policies_manager.process_policy_json( policies_and_enablements['enablements'], policies_and_enablements['policies'] ) rescue StandardError => standard_error module_logger.error("Error in polling policies: #{standard_error.}") module_logger.exception(standard_error) end # TODO(ralba): this might need to be changed to see how it affects performance sleep 0.1 end end end |
#stop_policy_polling ⇒ Object
31 32 33 34 |
# File 'lib/tcell_agent/policies/policy_polling.rb', line 31 def stop_policy_polling module_logger.debug('Stopping policy polling thread') @policy_polling_thread.exit if policy_polling_running? end |