1
require 'puppet/transaction'
2
require 'puppet/util/tagging'
3
require 'puppet/util/logging'
5
# A simple struct for storing what happens on the system.
6
class Puppet::Transaction::Event
7
include Puppet::Util::Tagging
8
include Puppet::Util::Logging
10
ATTRIBUTES = [:name, :resource, :property, :previous_value, :desired_value, :historical_value, :status, :message, :file, :line, :source_description, :audited]
11
YAML_ATTRIBUTES = %w{@audited @property @previous_value @desired_value @historical_value @message @name @status @time}
12
attr_accessor *ATTRIBUTES
15
attr_reader :default_log_level
17
EVENT_STATUSES = %w{noop success failure audit}
19
def initialize(options = {})
21
options.each { |attr, value| send(attr.to_s + "=", value) }
31
if res.respond_to?(:[]) and level = res[:loglevel]
32
@default_log_level = level
38
super(log_level, message)
42
raise ArgumentError, "Event status can only be #{EVENT_STATUSES.join(', ')}" unless EVENT_STATUSES.include?(value)
50
def to_yaml_properties
51
(YAML_ATTRIBUTES.map {|ya| ya.to_s} & instance_variables.map{|iv| iv.to_s}).sort
56
# If it's a failure, use 'err', else use either the resource's log level (if available)
59
status == "failure" ? :err : (@default_log_level || :notice)
62
# Used by the Logging module
64
source_description || property || resource