Class: Inspec::Telemetry::HTTP

Inherits:
Base
  • Object
show all
Defined in:
lib/inspec/utils/telemetry/http.rb

Constant Summary collapse

TELEMETRY_JOBS_PATH =
"v1/job"
TELEMETRY_URL =

Allow dev/CI to override the telemetry URL to a staging service

ENV["CHEF_TELEMETRY_URL"] || "https://services.chef.io/telemetry/"

Constants inherited from Base

Base::JOB_TYPE, Base::TYPE, Base::VERSION

Instance Attribute Summary

Attributes inherited from Base

#scratch

Instance Method Summary collapse

Methods inherited from Base

#create_wrapper, #fetch_license_ids, #format_control_tags, #note_all_invoked_features, #note_feature_usage, #note_gem_dependency_usage, #note_per_run_features, #obscure, #run_starting

Instance Method Details

#connectionObject



29
30
31
32
33
34
# File 'lib/inspec/utils/telemetry/http.rb', line 29

def connection
  Faraday.new(url: TELEMETRY_URL) do |config|
    config.request :json
    config.response :json
  end
end

#run_ending(opts) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/inspec/utils/telemetry/http.rb', line 11

def run_ending(opts)
  payload = super
  response = connection.post(TELEMETRY_JOBS_PATH) do |req|
    req.body = payload.to_json
  end
  if response.success?
    Inspec::Log.debug "HTTP connection with Telemetry Client successful."
    Inspec::Log.debug "HTTP response from Telemetry Client -> #{response.to_hash}"
    true
  else
    Inspec::Log.debug "HTTP connection with Telemetry Client faced an error."
    Inspec::Log.debug "HTTP error -> #{response.to_hash[:body]["error"]}" if response.to_hash[:body] && response.to_hash[:body]["error"]
    false
  end
rescue Faraday::ConnectionFailed
  Inspec::Log.debug "HTTP connection failure with telemetry url -> #{TELEMETRY_URL}"
end