Class: Contrast::Agent::Reporting::ApplicationInventoryActivity

Inherits:
ApplicationReportingEvent show all
Defined in:
lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb

Overview

This is the new ApplicationInventoryActivity class which will include all the information about the inventory of the application which was discovered during exercise of the application during this activity period.

Instance Attribute Summary collapse

Attributes inherited from ReportingEvent

#event_endpoint, #event_method

Instance Method Summary collapse

Methods inherited from ReportingEvent

#attach_headers

Methods inherited from ReportableHash

#event_json, #valid?, #validate

Methods included from Components::Logger::InstanceMethods

#cef_logger, #logger

Constructor Details

#initializeApplicationInventoryActivity

Returns a new instance of ApplicationInventoryActivity.



21
22
23
24
25
26
# File 'lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb', line 21

def initialize
  @event_type = :application_inventory_activity
  @browsers = []
  @components = []
  super()
end

Instance Attribute Details

#browsersObject (readonly)

@ return [Array<String>] - User-Agent Header value



19
20
21
# File 'lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb', line 19

def browsers
  @browsers
end

#componentsObject (readonly)

return [Array<Contrast::Agent::Reporting::ArchitectureComponent>]



17
18
19
# File 'lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb', line 17

def components
  @components
end

Instance Method Details

#attach_data(architectures) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb', line 38

def attach_data architectures
  Array(architectures).each do |architecture|
    @components << architecture
  end
  request_headers = Contrast::Agent::REQUEST_TRACKER.current&.request&.headers
  @browsers << request_headers['USER_AGENT'] if request_headers
end

#durationObject



46
47
48
# File 'lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb', line 46

def duration
  Contrast::Utils::Timer.now_ms - (Contrast::Agent::REQUEST_TRACKER.current&.timer&.start_ms || 0)
end

#empty?Boolean

Helper method to determine if InventoryActivity has no data

Returns:

  • (Boolean)


51
52
53
# File 'lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb', line 51

def empty?
  @browsers.empty? && @components.empty?
end

#to_controlled_hashObject



28
29
30
31
32
33
34
# File 'lib/contrast/agent/reporting/reporting_events/application_inventory_activity.rb', line 28

def to_controlled_hash
  {
      activityDuration: duration,
      browsers: browsers,
      components: components.map(&:to_controlled_hash)
  }
end