Class: NewRelic::Security::Agent::Agent
- Inherits:
-
Object
- Object
- NewRelic::Security::Agent::Agent
- Defined in:
- lib/newrelic_security/agent/agent.rb
Instance Attribute Summary collapse
-
#error_reporting ⇒ Object
Returns the value of attribute error_reporting.
-
#event_drop_count ⇒ Object
Returns the value of attribute event_drop_count.
-
#event_processed_count ⇒ Object
Returns the value of attribute event_processed_count.
-
#event_processor ⇒ Object
Returns the value of attribute event_processor.
-
#event_sent_count ⇒ Object
Returns the value of attribute event_sent_count.
-
#exit_event_stats ⇒ Object
Returns the value of attribute exit_event_stats.
-
#http_request_count ⇒ Object
Returns the value of attribute http_request_count.
-
#iast_client ⇒ Object
Returns the value of attribute iast_client.
-
#iast_event_stats ⇒ Object
Returns the value of attribute iast_event_stats.
-
#rasp_event_stats ⇒ Object
Returns the value of attribute rasp_event_stats.
-
#route_map ⇒ Object
Returns the value of attribute route_map.
-
#scan_scheduler ⇒ Object
Returns the value of attribute scan_scheduler.
-
#websocket_client ⇒ Object
Returns the value of attribute websocket_client.
Class Method Summary collapse
Instance Method Summary collapse
- #add_instrumentation ⇒ Object
- #create_agent_home ⇒ Object
- #find_or_create_file_path(path) ⇒ Object
- #init ⇒ Object
-
#initialize ⇒ Agent
constructor
A new instance of Agent.
- #reconnect(sleep_time = 15) ⇒ Object
- #shutdown_security_agent ⇒ Object
- #start_event_processor ⇒ Object
- #start_iast_client ⇒ Object
- #start_websocket_client ⇒ Object
- #stop_websocket_client_if_open ⇒ Object
Constructor Details
#initialize ⇒ Agent
Returns a new instance of Agent.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/newrelic_security/agent/agent.rb', line 31 def initialize NewRelic::Security::Agent.config create_agent_home NewRelic::Security::Agent::Utils.enable_object_space_in_jruby NewRelic::Security::Agent.config.save_uuid @started = false @event_subscriber = NewRelic::Security::Agent::Control::EventSubscriber.new @started = true @route_map = ::Set.new @http_request_count = NewRelic::Security::Agent::Control::EventCounter.new @event_processed_count = NewRelic::Security::Agent::Control::EventCounter.new @event_sent_count = NewRelic::Security::Agent::Control::EventCounter.new @event_drop_count = NewRelic::Security::Agent::Control::EventCounter.new @iast_event_stats = NewRelic::Security::Agent::Control::EventStats.new @rasp_event_stats = NewRelic::Security::Agent::Control::EventStats.new @exit_event_stats = NewRelic::Security::Agent::Control::EventStats.new @error_reporting = NewRelic::Security::Agent::Control::ErrorReporting.new @scan_scheduler = NewRelic::Security::Agent::Control::ScanScheduler.new end |
Instance Attribute Details
#error_reporting ⇒ Object
Returns the value of attribute error_reporting.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def error_reporting @error_reporting end |
#event_drop_count ⇒ Object
Returns the value of attribute event_drop_count.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def event_drop_count @event_drop_count end |
#event_processed_count ⇒ Object
Returns the value of attribute event_processed_count.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def event_processed_count @event_processed_count end |
#event_processor ⇒ Object
Returns the value of attribute event_processor.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def event_processor @event_processor end |
#event_sent_count ⇒ Object
Returns the value of attribute event_sent_count.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def event_sent_count @event_sent_count end |
#exit_event_stats ⇒ Object
Returns the value of attribute exit_event_stats.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def exit_event_stats @exit_event_stats end |
#http_request_count ⇒ Object
Returns the value of attribute http_request_count.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def http_request_count @http_request_count end |
#iast_client ⇒ Object
Returns the value of attribute iast_client.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def iast_client @iast_client end |
#iast_event_stats ⇒ Object
Returns the value of attribute iast_event_stats.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def iast_event_stats @iast_event_stats end |
#rasp_event_stats ⇒ Object
Returns the value of attribute rasp_event_stats.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def rasp_event_stats @rasp_event_stats end |
#route_map ⇒ Object
Returns the value of attribute route_map.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def route_map @route_map end |
#scan_scheduler ⇒ Object
Returns the value of attribute scan_scheduler.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def scan_scheduler @scan_scheduler end |
#websocket_client ⇒ Object
Returns the value of attribute websocket_client.
29 30 31 |
# File 'lib/newrelic_security/agent/agent.rb', line 29 def websocket_client @websocket_client end |
Class Method Details
Instance Method Details
#add_instrumentation ⇒ Object
103 104 105 |
# File 'lib/newrelic_security/agent/agent.rb', line 103 def add_instrumentation end |
#create_agent_home ⇒ Object
107 108 109 110 111 112 |
# File 'lib/newrelic_security/agent/agent.rb', line 107 def create_agent_home log_dir = ::File.join(NewRelic::Security::Agent.config[:log_file_path], SEC_HOME_PATH, LOGS_DIR) find_or_create_file_path(log_dir) tmp_dir = ::File.join(NewRelic::Security::Agent.config[:log_file_path], SEC_HOME_PATH, TMP_DIR) find_or_create_file_path(tmp_dir) end |
#find_or_create_file_path(path) ⇒ Object
114 115 116 117 118 119 120 |
# File 'lib/newrelic_security/agent/agent.rb', line 114 def find_or_create_file_path(path) ::FileUtils.mkdir_p(path) unless ::File.directory?(path) ::File.directory?(path) rescue => e ::NewRelic::Agent.notice_error(e) return false end |
#init ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/newrelic_security/agent/agent.rb', line 51 def init NewRelic::Security::Agent.logger.info "Initializing Security Agent with config : #{NewRelic::Security::Agent::Utils.filtered_log(NewRelic::Security::Agent.config.inspect)}\n" @ready = false start_event_processor start_websocket_client NewRelic::Security::Instrumentation::InstrumentationLoader.add_instrumentation() NewRelic::Security::Agent.logger.info "Security Agent ready.\n" NewRelic::Security::Agent.init_logger.info "Security Agent ready.\n" @ready = true rescue Exception => exception NewRelic::Security::Agent.logger.error "Exception in security agent init: #{exception.inspect} #{exception.backtrace}\n" end |
#reconnect(sleep_time = 15) ⇒ Object
122 123 124 125 126 127 |
# File 'lib/newrelic_security/agent/agent.rb', line 122 def reconnect(sleep_time = 15) NewRelic::Security::Agent::Control::WebsocketClient.instance.close(false) if NewRelic::Security::Agent::Control::WebsocketClient.instance.is_open? NewRelic::Security::Agent.logger.info "Trying to reconnect to websocket connection in #{sleep_time} sec..." sleep sleep_time NewRelic::Security::Agent.agent.start_websocket_client end |
#shutdown_security_agent ⇒ Object
64 65 66 67 68 69 70 71 72 73 |
# File 'lib/newrelic_security/agent/agent.rb', line 64 def shutdown_security_agent NewRelic::Security::Agent.logger.info "Flushing eventQ (#{NewRelic::Security::Agent.agent.event_processor.eventQ.size} events) and closing websocket connection" NewRelic::Security::Agent.agent.event_processor&.eventQ&.clear @iast_client&.fuzzQ&.clear @iast_client&.completed_requests&.clear @iast_client&.pending_request_ids&.clear @iast_client&.iast_data_transfer_request_processor_thread&.kill NewRelic::Security::Agent.config.disable_security stop_websocket_client_if_open end |
#start_event_processor ⇒ Object
84 85 86 87 88 89 |
# File 'lib/newrelic_security/agent/agent.rb', line 84 def start_event_processor @event_processor&.event_dequeue_threads&.each { |t| t&.kill } @event_processor&.healthcheck_thread&.kill @event_processor = nil @event_processor = NewRelic::Security::Agent::Control::EventProcessor.new end |
#start_iast_client ⇒ Object
91 92 93 94 95 96 97 |
# File 'lib/newrelic_security/agent/agent.rb', line 91 def start_iast_client @iast_client&.iast_dequeue_threads&.each { |t| t&.kill } @iast_client&.iast_data_transfer_request_processor_thread&.kill @iast_client = nil NewRelic::Security::Agent.logger.info "Starting IAST client now at current time: #{Time.now}" @iast_client = NewRelic::Security::Agent::Control::IASTClient.new end |
#start_websocket_client ⇒ Object
75 76 77 78 |
# File 'lib/newrelic_security/agent/agent.rb', line 75 def start_websocket_client stop_websocket_client_if_open @websocket_client = NewRelic::Security::Agent::Control::WebsocketClient.instance.connect end |
#stop_websocket_client_if_open ⇒ Object
80 81 82 |
# File 'lib/newrelic_security/agent/agent.rb', line 80 def stop_websocket_client_if_open NewRelic::Security::Agent::Control::WebsocketClient.instance.close(false) if NewRelic::Security::Agent::Control::WebsocketClient.instance.is_open? end |