class Transaction::Event

A simple struct for storing what happens on the system.

Constants

ATTRIBUTES
EVENT_STATUSES

Attributes

default_log_level[R]
time[RW]

Public Class Methods

from_data_hash(data) click to toggle source
   # File lib/puppet/transaction/event.rb
20 def self.from_data_hash(data)
21   obj = self.allocate
22   obj.initialize_from_hash(data)
23   obj
24 end
new(audited: false, corrective_change: false, desired_value: nil, file: nil, historical_value: nil, invalidate_refreshes: nil, line: nil, message: nil, name: nil, previous_value: nil, property: nil, redacted: false, resource: nil, source_description: nil, status: nil, tags: nil) click to toggle source
   # File lib/puppet/transaction/event.rb
26 def initialize(audited: false,
27                corrective_change: false,
28                desired_value: nil,
29                file: nil,
30                historical_value: nil,
31                invalidate_refreshes: nil,
32                line: nil,
33                message: nil,
34                name: nil,
35                previous_value: nil,
36                property: nil,
37                redacted: false,
38                resource: nil,
39                source_description: nil,
40                status: nil,
41                tags: nil)
42 
43   @audited = audited
44   @corrective_change = corrective_change
45   @desired_value = desired_value
46   @file = file
47   @historical_value = historical_value
48   @invalidate_refreshes = invalidate_refreshes
49   @line = line
50   @message = message
51   @name = name
52   @previous_value = previous_value
53   @redacted = redacted
54   @source_description = source_description
55   @tags = tags
56 
57   self.property = property if property
58   self.resource = resource if resource
59   self.status = status if status
60 
61   @time = Time.now
62 end

Public Instance Methods

==(event)
Alias for: eql?
calculate_corrective_change(old_system_value) click to toggle source

Calculate and set the corrective_change parameter, based on the old_system_value of the property. @param [Object] old_system_value system_value from last transaction @return [bool] true if this is a corrective_change

    # File lib/puppet/transaction/event.rb
140 def calculate_corrective_change(old_system_value)
141   # Only idempotent properties, and cases where we have an old system_value
142   # are corrective_changes.
143   if @property_instance.idempotent? &&
144      !@property_instance.sensitive &&
145      !old_system_value.nil?
146 
147     # If the values aren't insync, we have confirmed a corrective_change
148     insync = @property_instance.insync_values?(old_system_value, previous_value)
149 
150     # Preserve the nil state, but flip true/false
151     @corrective_change = insync.nil? ? nil : !insync
152   else
153     @corrective_change = false
154   end
155 end
eql?(event) click to toggle source
   # File lib/puppet/transaction/event.rb
64 def eql?(event)
65   self.class == event.class && ATTRIBUTES.all? { |attr| send(attr).eql?(event.send(attr)) }
66 end
Also aliased as: ==
initialize_from_hash(data) click to toggle source
   # File lib/puppet/transaction/event.rb
69 def initialize_from_hash(data)
70   data = Puppet::Pops::Serialization::FromDataConverter.convert(data, {
71     :allow_unresolved => true,
72     :loader => Puppet::Pops::Loaders.static_loader
73   })
74   @audited = data['audited']
75   @property = data['property']
76   @previous_value = data['previous_value']
77   @desired_value = data['desired_value']
78   @historical_value = data['historical_value']
79   @message = data['message']
80   @name = data['name'].intern if data['name']
81   @status = data['status']
82   @time = data['time']
83   @time = Time.parse(@time) if @time.is_a? String
84   @redacted = data.fetch('redacted', false)
85   @corrective_change = data['corrective_change']
86 end
inspect() click to toggle source
    # File lib/puppet/transaction/event.rb
133 def inspect
134   %Q(#<#{self.class.name} @name="#{@name.inspect}" @message="#{@message.inspect}">)
135 end
property=(prop) click to toggle source
    # File lib/puppet/transaction/event.rb
107 def property=(prop)
108   @property_instance = prop
109   @property = prop.to_s
110 end
resource=(res) click to toggle source
    # File lib/puppet/transaction/event.rb
112 def resource=(res)
113   level = res[:loglevel] if res.respond_to?(:[])
114   if level
115     @default_log_level = level
116   end
117   @resource = res.to_s
118 end
send_log() click to toggle source
Calls superclass method Puppet::Util::Logging#send_log
    # File lib/puppet/transaction/event.rb
120 def send_log
121   super(log_level, message)
122 end
status=(value) click to toggle source
    # File lib/puppet/transaction/event.rb
124 def status=(value)
125   raise ArgumentError, _("Event status can only be %{statuses}") % { statuses: EVENT_STATUSES.join(', ') } unless EVENT_STATUSES.include?(value)
126   @status = value
127 end
to_data_hash() click to toggle source
    # File lib/puppet/transaction/event.rb
 88 def to_data_hash
 89   hash = {
 90     'audited' => @audited,
 91     'property' => @property,
 92     'previous_value' => @previous_value,
 93     'desired_value' => @desired_value,
 94     'historical_value' => @historical_value,
 95     'message' => @message,
 96     'name' => @name.nil? ? nil : @name.to_s,
 97     'status' => @status,
 98     'time' => @time.iso8601(9),
 99     'redacted' => @redacted,
100     'corrective_change' => @corrective_change,
101   }
102   # Use the stringifying converter since rich data is not possible downstream.
103   # (This will destroy some data type information, but this is expected).
104   Puppet::Pops::Serialization::ToStringifiedConverter.convert(hash, :message_prefix => 'Event')
105 end
to_s() click to toggle source
    # File lib/puppet/transaction/event.rb
129 def to_s
130   message
131 end

Private Instance Methods

log_level() click to toggle source

If it's a failure, use 'err', else use either the resource's log level (if available) or 'notice'.

    # File lib/puppet/transaction/event.rb
161 def log_level
162   status == "failure" ? :err : (@default_log_level || :notice)
163 end
log_source() click to toggle source

Used by the Logging module

    # File lib/puppet/transaction/event.rb
166 def log_source
167   source_description || property || resource
168 end