26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/chef/resource_reporter.rb', line 26
def for_json(action_record)
new_resource = action_record.new_resource
current_resource = action_record.current_resource
as_hash = {}
as_hash["type"] = new_resource.resource_name.to_sym
as_hash["name"] = new_resource.name.to_s
as_hash["id"] = new_resource.identity.to_s
as_hash["after"] = new_resource.state_for_resource_reporter
as_hash["before"] = current_resource ? current_resource.state_for_resource_reporter : {}
as_hash["before"] = {} if as_hash["before"].to_s.bytesize > 657920
as_hash["duration"] = ( action_record.elapsed_time * 1000 ).to_i.to_s
as_hash["delta"] = new_resource.diff if new_resource.respond_to?(:diff)
as_hash["delta"] = "" if as_hash["delta"].nil?
as_hash["result"] = action_record.action.to_s
if new_resource.cookbook_name
as_hash["cookbook_name"] = new_resource.cookbook_name
as_hash["cookbook_version"] = new_resource.cookbook_version&.version
end
as_hash
end
|