1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
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
|
module Puppet
class Resource
class Status
include Puppet::Util::Tagging
include Puppet::Util::Logging
attr_accessor :resource, :node, :file, :line, :current_values, :status, :evaluation_time
STATES = [:skipped, :failed, :failed_to_restart, :restarted, :changed, :out_of_sync, :scheduled]
attr_accessor *STATES
attr_reader :source_description, :default_log_level, :time, :resource
attr_reader :change_count, :out_of_sync_count, :resource_type, :title
YAML_ATTRIBUTES = %w{@resource @file @line @evaluation_time @change_count @out_of_sync_count @tags @time @events @out_of_sync @changed @resource_type @title @skipped @failed}
# Provide a boolean method for each of the states.
STATES.each do |attr|
define_method("#{attr}?") do
!! send(attr)
end
end
def <<(event)
add_event(event)
self
end
def add_event(event)
@events << event
if event.status == 'failure'
self.failed = true
elsif event.status == 'success'
@change_count += 1
@changed = true
end
if event.status != 'audit'
@out_of_sync_count += 1
@out_of_sync = true
end
end
def events
@events
end
def initialize(resource)
@source_description = resource.path
@resource = resource.to_s
@change_count = 0
@out_of_sync_count = 0
@changed = false
@out_of_sync = false
@skipped = false
@failed = false
[:file, :line].each do |attr|
send(attr.to_s + "=", resource.send(attr))
end
tag(*resource.tags)
@time = Time.now
@events = []
@resource_type = resource.type.to_s.capitalize
@title = resource.title
end
def to_yaml_properties
(YAML_ATTRIBUTES & instance_variables).sort
end
private
def log_source
source_description
end
end
end
end
|