# Copyright (c) 2021 Contrast Security, Inc. See https://www.contrastsecurity.com/enduser-terms-0317a for more details. # frozen_string_literal: true require 'contrast/utils/metrics_hash' require 'contrast/agent/metric_telemetry_event' require 'contrast/agent/version' require 'contrast/utils/os' module Contrast module Agent # This class will hold the Startup Metrics Telemetry Event # The class will include initialization of the agent version, language version # os type, arch and version # application framework and version and server framework # It will be initialized and send in Middleware#agent_startup_routine class StartupMetricsTelemetryEvent < Contrast::Agent::MetricTelemetryEvent include Contrast::Utils::OS APP_AND_SERVER_DATA = ::Contrast::APP_CONTEXT.app_and_server_information.cs__freeze SAAS_DEFAULT = { addr: 'app.contrastsecuirty.com', type: 'SAAS_DEFAULT' }.cs__freeze SAAS_CE = { addr: 'ce.contrastsecurity.com', type: 'SAAS_CE' }.cs__freeze SAAS_CUSTOM = { addr: 'contrastsecurite.com', type: 'SAAS_CUSTOM' }.cs__freeze SAAS_POV = { addr: 'eval.contrastsecuirty.com', type: 'SAAS_POV' }.cs__freeze EOP = 'EOP' def initialize super add_tags end def path '/startup' end def add_tags @tags['teamserver'] = teamserver_type @tags['agent_version'] = VERSION @tags['ruby_version'] = RUBY_VERSION @tags['os_type'] = sys_info['os_type'] == 'Darwin' ? 'MacOS' : 'Linux' @tags['os_arch'] = sys_info['os_arch'] @tags['os_version'] = sys_info['os_version'] @tags['app_framework_and_version'] = APP_AND_SERVER_DATA[:application_info].to_s @tags['server_framework_and_version'] = APP_AND_SERVER_DATA[:server_info].to_s end def sys_info @sys_info ||= get_system_information if @sys_info.nil? @sys_info end private # Here we extract the Teamserver url type # # @return[String] type, it could be SAAS_DEFAULT, SAAS_POV, SAAS_CE, SAAS_CUSTOM, or EOP def teamserver_type @_teamserver_type ||= if Contrast::API.api_url.include?(SAAS_DEFAULT[:addr]) SAAS_DEFAULT[:type] elsif Contrast::API.api_url.include?(SAAS_POV[:addr]) SAAS_POV[:type] elsif Contrast::API.api_url.include?(SAAS_CE[:addr]) SAAS_CE[:type] elsif Contrast::API.api_url.end_with? SAAS_CUSTOM[:addr] SAAS_CUSTOM[:type] else EOP end end end end end