class TCellAgent::Agent
Attributes
route_table[RW]
stop_agent[RW]
Public Class Methods
get_database_discovery_identifier(database, schema, table, fields)
click to toggle source
# File lib/tcell_agent/agent/route_manager.rb, line 8 def self.get_database_discovery_identifier(database, schema, table, fields) [ database, schema, table, fields.join(',') ].join(',').hash end
new()
click to toggle source
# File lib/tcell_agent/agent.rb, line 29 def initialize @stop_agent = false @native_agent = nil @route_table = TCellAgent::Routes::RouteTable.new @policies_manager = PoliciesManager.new(nil) end
Public Instance Methods
discover_database_fields(route_id, database, schema, table, fields)
click to toggle source
# File lib/tcell_agent/agent/route_manager.rb, line 17 def discover_database_fields(route_id, database, schema, table, fields) return if route_id.nil? || database.nil? || schema.nil? || table.nil? || fields.nil? query_hash = TCellAgent::Agent.get_database_discovery_identifier(database, schema, table, fields) return if @route_table.routes[route_id].database_queries_discovered.fetch(query_hash, false) @route_table.routes[route_id].database_queries_discovered[query_hash] = true event = TCellAgent::SensorEvents::DiscoveryEvent.new(route_id).for_database_fields(database, schema, table, fields) TCellAgent.send_event(event) # discovered_fields = fields.select { |field| # @route_table.routes[route_id].database_queries_discoverd[database][schema][table][field].discovered != true # } # if (discovered_fields.length > 0) # discovered_fields.each { |field| # @route_table.routes[route_id].database[database][schema][table][field].discovered = true # } # event = (TCellAgent::SensorEvents::DiscoveryEvent.new(route_id)).for_database_fields(database, schema, table, fields) # TCellAgent.send_event(event) # end end
instrument_auth_frameworks()
click to toggle source
# File lib/tcell_agent/agent.rb, line 36 def instrument_auth_frameworks if defined?(Devise) && TCellAgent.configuration.should_instrument?('devise') module_logger.info('Instrumenting Devise authentication framework') require 'tcell_agent/rails/auth/devise' require 'tcell_agent/rails/auth/devise_helper' end if defined?(Authlogic) && TCellAgent.configuration.should_instrument?('authlogic') module_logger.info('Instrumenting Authlogic authentication framework') require 'tcell_agent/rails/auth/authlogic' require 'tcell_agent/rails/auth/authlogic_helper' end if defined?(Doorkeeper) && TCellAgent.configuration.should_instrument?('doorkeeper') # rubocop:disable Style/GuardClause module_logger.info('Instrumenting Doorkeeper authentication framework') require 'tcell_agent/rails/auth/doorkeeper' end end
instrument_built_ins()
click to toggle source
# File lib/tcell_agent/agent.rb, line 55 def instrument_built_ins require 'tcell_agent/instrumentation/cmdi' require 'tcell_agent/instrumentation/lfi' variant = if RUBY_VERSION.start_with?('3') 'ruby_3' else 'ruby_2' end if TCellAgent.configuration.should_instrument?('io') module_logger.info('Instrumenting Ruby Class: IO') require "tcell_agent/instrumentation/monkey_patches/#{variant}/io" end if TCellAgent.configuration.should_instrument?('file') module_logger.info('Instrumenting Ruby Class: File') require "tcell_agent/instrumentation/monkey_patches/#{variant}/file" end if TCellAgent.configuration.should_instrument?('kernel') # rubocop:disable Style/GuardClause module_logger.info('Instrumenting Ruby Module: Kernel') require "tcell_agent/instrumentation/monkey_patches/#{variant}/kernel" end end
manage_policies()
click to toggle source
# File lib/tcell_agent/agent.rb, line 81 def manage_policies @policies_manager = PoliciesManager.new(@native_agent) result = {} unless TCellAgent.configuration.should_start_policy_poll? result = @native_agent.poll_new_policies end policies_and_enablements = result['new_policies_and_enablements'] || {} @policies_manager.process_policy_json( policies_and_enablements['enablements'], policies_and_enablements['policies'] ) @policy_polling = PolicyPolling.new(@policies_manager, @native_agent) end
policies()
click to toggle source
# File lib/tcell_agent/agent.rb, line 99 def policies @policies_manager.policies end
queue_sensor_event(event)
click to toggle source
# File lib/tcell_agent/agent.rb, line 103 def queue_sensor_event(event) return unless @native_agent @native_agent.send_sanitized_events( [event] ) rescue StandardError => e module_logger.error("Error sending event: (#{e.class}) #{e.message}") module_logger.exception(e) end
report_metrics(request_time, tcell_context)
click to toggle source
# File lib/tcell_agent/agent.rb, line 114 def report_metrics(request_time, tcell_context) @native_agent.report_metrics( request_time, tcell_context ) rescue StandardError => e module_logger.error("Error reporting metric: (#{e.class}) #{e.message}") module_logger.exception(e) end
start(server_name)
click to toggle source
# File lib/tcell_agent/agent.rb, line 123 def start(server_name) @native_agent = TCellAgent::Rust::NativeAgent.create_agent( TCellAgent.initializer_configuration || TCellAgent.configuration ) if @native_agent.nil? TCellAgent.configuration.enabled = false return end TCellAgent.native_logger = @native_agent module_logger.info('Rails initializer overriding default agent configuration') unless TCellAgent.initializer_configuration.nil? instrument_auth_frameworks instrument_built_ins manage_policies module_logger.info("Started thread agent: #{server_name}") TCellAgent.report_settings TCellAgent::Instrumentation::Rails.send_settings rescue StandardError => e TCellAgent.configuration.enabled = false module_logger.error("Error starting agent: (#{e.class}) #{e.message}") module_logger.exception(e) end