class TCellAgent::PolicyPolling
Public Class Methods
new(policies_manager, native_agent)
click to toggle source
# 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
Public Instance Methods
policy_polling_running?()
click to toggle source
# File lib/tcell_agent/policies/policy_polling.rb, line 28 def policy_polling_running? @policy_polling_thread && @policy_polling_thread.alive? end
start_policy_polling(native_agent)
click to toggle source
# 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)
click to toggle source
# File lib/tcell_agent/policies/policy_polling.rb, line 37 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 => e module_logger.error("Error in polling policies: #{e.message}") module_logger.exception(e) end # TODO(ralba): this might need to be changed to see how it affects performance sleep 0.1 end end end
stop_policy_polling()
click to toggle source
# File lib/tcell_agent/policies/policy_polling.rb, line 32 def stop_policy_polling module_logger.debug('Stopping policy polling thread') @policy_polling_thread.exit if policy_polling_running? end