Module: Chef::DataCollector::RunEndMessage

Extended by:
MessageHelpers
Defined in:
lib/chef/data_collector/run_end_message.rb

Class Method Summary collapse

Class Method Details

.construct_message(data_collector, status) ⇒ Hash

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

Parameters:

Returns:

  • (Hash)

    A hash containing the run end message data.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/chef/data_collector/run_end_message.rb', line 42

def construct_message(data_collector, status)
  action_collection = data_collector.action_collection
  run_status = data_collector.run_status
  node = data_collector.node

  message = {
    "chef_server_fqdn" => URI(Chef::Config[:chef_server_url]).host,
    "entity_uuid" => Chef::Config[:chef_guid],
    "expanded_run_list" => data_collector.expanded_run_list,
    "id" => run_status&.run_id,
    "message_version" => "1.1.0",
    "message_type" => "run_converge",
    "node" => node&.data_for_save || {},
    "node_name" => node&.name || data_collector.node_name,
    "organization_name" => organization,
    "resources" => all_action_records(action_collection),
    "run_id" => run_status&.run_id,
    "run_list" => node&.run_list&.for_json || [],
    "cookbooks" => ( node && node["cookbooks"] ) || {},
    "policy_name" => node&.policy_name,
    "policy_group" => node&.policy_group,
    "start_time" => run_status&.start_time&.utc&.iso8601,
    "end_time" => run_status&.end_time&.utc&.iso8601,
    "source" => solo_run? ? "chef_solo" : "chef_client",
    "status" => status,
    "total_resource_count" => all_action_records(action_collection).count,
    "updated_resource_count" => updated_resource_count(action_collection),
    "deprecations" => data_collector.deprecations.to_a,
  }

  if run_status&.exception
    message["error"] = {
      "class" => run_status.exception.class,
      "message" => run_status.exception.message,
      "backtrace" => run_status.exception.backtrace,
      "description" => data_collector.error_description,
    }
  end

  message
end