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
19 def self.from_data_hash(data)
20   obj = self.allocate
21   obj.initialize_from_hash(data)
22   obj
23 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
25 def initialize(audited: false,
26                corrective_change: false,
27                desired_value: nil,
28                file: nil,
29                historical_value: nil,
30                invalidate_refreshes: nil,
31                line: nil,
32                message: nil,
33                name: nil,
34                previous_value: nil,
35                property: nil,
36                redacted: false,
37                resource: nil,
38                source_description: nil,
39                status: nil,
40                tags: nil)
41 
42   @audited = audited
43   @corrective_change = corrective_change
44   @desired_value = desired_value
45   @file = file
46   @historical_value = historical_value
47   @invalidate_refreshes = invalidate_refreshes
48   @line = line
49   @message = message
50   @name = name
51   @previous_value = previous_value
52   @redacted = redacted
53   @source_description = source_description
54   @tags = tags
55 
56   self.property = property if property
57   self.resource = resource if resource
58   self.status = status if status
59 
60   @time = Time.now
61 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
139 def calculate_corrective_change(old_system_value)
140   # Only idempotent properties, and cases where we have an old system_value
141   # are corrective_changes.
142   if @property_instance.idempotent? &&
143      !@property_instance.sensitive &&
144      !old_system_value.nil?
145 
146     # If the values aren't insync, we have confirmed a corrective_change
147     insync = @property_instance.insync_values?(old_system_value, previous_value)
148 
149     # Preserve the nil state, but flip true/false
150     @corrective_change = insync.nil? ? nil : !insync
151   else
152     @corrective_change = false
153   end
154 end
eql?(event) click to toggle source
   # File lib/puppet/transaction/event.rb
63 def eql?(event)
64   self.class == event.class && ATTRIBUTES.all? { |attr| send(attr).eql?(event.send(attr)) }
65 end
Also aliased as: ==
initialize_from_hash(data) click to toggle source
   # File lib/puppet/transaction/event.rb
68 def initialize_from_hash(data)
69   data = Puppet::Pops::Serialization::FromDataConverter.convert(data, {
70     :allow_unresolved => true,
71     :loader => Puppet::Pops::Loaders.static_loader
72   })
73   @audited = data['audited']
74   @property = data['property']
75   @previous_value = data['previous_value']
76   @desired_value = data['desired_value']
77   @historical_value = data['historical_value']
78   @message = data['message']
79   @name = data['name'].intern if data['name']
80   @status = data['status']
81   @time = data['time']
82   @time = Time.parse(@time) if @time.is_a? String
83   @redacted = data.fetch('redacted', false)
84   @corrective_change = data['corrective_change']
85 end
inspect() click to toggle source
    # File lib/puppet/transaction/event.rb
132 def inspect
133   %Q(#<#{self.class.name} @name="#{@name.inspect}" @message="#{@message.inspect}">)
134 end
property=(prop) click to toggle source
    # File lib/puppet/transaction/event.rb
106 def property=(prop)
107   @property_instance = prop
108   @property = prop.to_s
109 end
resource=(res) click to toggle source
    # File lib/puppet/transaction/event.rb
111 def resource=(res)
112   level = res[:loglevel] if res.respond_to?(:[])
113   if level
114     @default_log_level = level
115   end
116   @resource = res.to_s
117 end
send_log() click to toggle source
Calls superclass method Puppet::Util::Logging#send_log
    # File lib/puppet/transaction/event.rb
119 def send_log
120   super(log_level, message)
121 end
status=(value) click to toggle source
    # File lib/puppet/transaction/event.rb
123 def status=(value)
124   raise ArgumentError, _("Event status can only be %{statuses}") % { statuses: EVENT_STATUSES.join(', ') } unless EVENT_STATUSES.include?(value)
125   @status = value
126 end
to_data_hash() click to toggle source
    # File lib/puppet/transaction/event.rb
 87 def to_data_hash
 88   hash = {
 89     'audited' => @audited,
 90     'property' => @property,
 91     'previous_value' => @previous_value,
 92     'desired_value' => @desired_value,
 93     'historical_value' => @historical_value,
 94     'message' => @message,
 95     'name' => @name.nil? ? nil : @name.to_s,
 96     'status' => @status,
 97     'time' => @time.iso8601(9),
 98     'redacted' => @redacted,
 99     'corrective_change' => @corrective_change,
100   }
101   # Use the stringifying converter since rich data is not possible downstream.
102   # (This will destroy some data type information, but this is expected).
103   Puppet::Pops::Serialization::ToStringifiedConverter.convert(hash, :message_prefix => 'Event')
104 end
to_s() click to toggle source
    # File lib/puppet/transaction/event.rb
128 def to_s
129   message
130 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
160 def log_level
161   status == "failure" ? :err : (@default_log_level || :notice)
162 end
log_source() click to toggle source

Used by the Logging module

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