Sha256: 8007af4c0d7dec952693aaeaf535520a37cf8c82eadada3f2b3f9fa5ec91aee9

Contents?: true

Size: 1.89 KB

Versions: 10

Compression:

Stored size: 1.89 KB

Contents

# Copyright (c) 2022 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details.
# frozen_string_literal: true

require 'contrast/agent/worker_thread'
require 'contrast/agent/reporting/report'
require 'contrast/agent/inventory/dependency_usage_analysis'
require 'contrast/agent/reporting/reporting_events/poll'
require 'contrast/agent/reporting/reporting_events/server_activity'

module Contrast
  module Agent
    # The ReporterHeartbeat will make sure that the process remains marked alive by TeamServer and that we periodically
    # reach out to get the latest settings for this application. It also sends out those messages which do not need to
    # be associated directly with a request, such as Server Activity and Library Observation.
    class ReporterHeartbeat < WorkerThread
      # TeamServer will mark an application offline after 5 minutes. Sending this every one should be more than enough
      # to satisfy our goals.
      REFRESH_INTERVAL_SEC = 60

      def start_thread!
        return if running?

        @_thread = Contrast::Agent::Thread.new do
          logger.info('Starting heartbeat thread.')
          loop do
            polling_events.each do |event|
              Contrast::Agent.reporter&.send_event(event)
            end
            clean_properties
            sleep(REFRESH_INTERVAL_SEC)
          end
        end
      end

      private

      def poll_message
        @_poll_message ||= Contrast::Agent::Reporting::Poll.new
      end

      # Those events which should be sent periodically, rather than on event or request.
      #
      # @return [Array<Contrast::Agent::Reporting::ReportingEvent>]
      def polling_events
        [
          Contrast::Agent::Inventory::DependencyUsageAnalysis.instance.generate_library_usage,
          Contrast::Agent::Reporting::ServerActivity.new,
          poll_message
        ].compact
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
contrast-agent-6.8.0 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.7.0 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.6.5 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.6.4 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.6.3 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.6.2 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.6.1 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.6.0 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.5.1 lib/contrast/agent/reporting/reporter_heartbeat.rb
contrast-agent-6.5.0 lib/contrast/agent/reporting/reporter_heartbeat.rb