Class: Chef::Telemetry::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/telemetry/event.rb

Constant Summary collapse

SKELETON =
{
  instance_id: "00000000-0000-0000-0000-000000000000",
  message_version: 1.0,
  payload_version: 1.0,
  license_id: "00000000-0000-0000-0000-000000000000",
  type: "track",
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(product, session, origin = "command-line", install_context = "omnibus", product_version = "0.0.0") ⇒ Event

Returns a new instance of Event.



15
16
17
18
19
20
21
22
# File 'lib/chef/telemetry/event.rb', line 15

def initialize(product, session, origin = "command-line",
               install_context = "omnibus", product_version = "0.0.0")
  @product = product
  @session = session
  @origin = origin
  @product_version = product_version
  @install_context = install_context
end

Instance Attribute Details

#install_contextObject (readonly)

Returns the value of attribute install_context.



13
14
15
# File 'lib/chef/telemetry/event.rb', line 13

def install_context
  @install_context
end

#originObject (readonly)

Returns the value of attribute origin.



13
14
15
# File 'lib/chef/telemetry/event.rb', line 13

def origin
  @origin
end

#productObject (readonly)

Returns the value of attribute product.



13
14
15
# File 'lib/chef/telemetry/event.rb', line 13

def product
  @product
end

#product_versionObject (readonly)

Returns the value of attribute product_version.



13
14
15
# File 'lib/chef/telemetry/event.rb', line 13

def product_version
  @product_version
end

#sessionObject (readonly)

Returns the value of attribute session.



13
14
15
# File 'lib/chef/telemetry/event.rb', line 13

def session
  @session
end

Instance Method Details

#prepare(event) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chef/telemetry/event.rb', line 24

def prepare(event)
  time = timestamp
  event[:properties][:timestamp] = time
  body = SKELETON.dup
  body.tap do |b|
    b[:session_id] = session.id
    b[:origin] = origin
    b[:product] = product
    b[:product_version] = product_version
    b[:install_context] = install_context
    b[:timestamp] = time
    b[:payload] = event
  end
end

#timestampObject



39
40
41
# File 'lib/chef/telemetry/event.rb', line 39

def timestamp
  Time.now.utc.strftime("%FT%TZ")
end