Module: Chef::DataCollector::Messages

Extended by:
Helpers
Defined in:
lib/chef/data_collector/messages.rb,
lib/chef/data_collector/messages/helpers.rb

Defined Under Namespace

Modules: Helpers

Class Method Summary collapse

Methods included from Helpers

chef_server_fqdn, chef_server_organization, collector_source, data_collector_organization, generate_node_uuid, metadata, metadata_filename, node_uuid, organization, read_node_uuid, solo_run?, update_metadata

Class Method Details

.run_end_message(reporter_data) ⇒ Hash

Message payload that is sent to the DataCollector server at the end of a Chef run.

Parameters:

  • reporter_data (Hash)

    Data supplied by the Reporter, such as run_status, resource counts, etc.

Returns:

  • (Hash)

    A hash containing the run end message data.


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/chef/data_collector/messages.rb', line 60

def self.run_end_message(reporter_data)
  run_status = reporter_data[:run_status]

  message = {
    "chef_server_fqdn"       => chef_server_fqdn(run_status),
    "entity_uuid"            => node_uuid,
    "expanded_run_list"      => reporter_data[:expanded_run_list],
    "id"                     => run_status.run_id,
    "message_version"        => "1.1.0",
    "message_type"           => "run_converge",
    "node"                   => run_status.node,
    "node_name"              => run_status.node.name,
    "organization_name"      => organization,
    "resources"              => reporter_data[:resources].map(&:report_data),
    "run_id"                 => run_status.run_id,
    "run_list"               => run_status.node.run_list.for_json,
    "policy_name"            => run_status.node.policy_name,
    "policy_group"           => run_status.node.policy_group,
    "start_time"             => run_status.start_time.utc.iso8601,
    "end_time"               => run_status.end_time.utc.iso8601,
    "source"                 => collector_source,
    "status"                 => reporter_data[:status],
    "total_resource_count"   => reporter_data[:resources].count,
    "updated_resource_count" => reporter_data[:resources].select { |r| r.report_data["status"] == "updated" }.count,
    "deprecations"           => reporter_data[:deprecations],
  }

  if run_status.exception
    message["error"] = {
      "class"       => run_status.exception.class,
      "message"     => run_status.exception.message,
      "backtrace"   => run_status.exception.backtrace,
      "description" => reporter_data[:error_descriptions],
    }
  end

  message
end

.run_start_message(run_status) ⇒ Hash

Message payload that is sent to the DataCollector server at the start of a Chef run.

Parameters:

  • run_status (Chef::RunStatus)

    The RunStatus instance for this node/run.

Returns:

  • (Hash)

    A hash containing the run start message data.


37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/chef/data_collector/messages.rb', line 37

def self.run_start_message(run_status)
  {
    "chef_server_fqdn"  => chef_server_fqdn(run_status),
    "entity_uuid"       => node_uuid,
    "id"                => run_status.run_id,
    "message_version"   => "1.0.0",
    "message_type"      => "run_start",
    "node_name"         => run_status.node.name,
    "organization_name" => organization,
    "run_id"            => run_status.run_id,
    "source"            => collector_source,
    "start_time"        => run_status.start_time.utc.iso8601,
  }
end