Class: Coral::PuppetEvent

Inherits:
Event show all
Defined in:
lib/coral_core/event/puppet_event.rb

Constant Summary collapse

TYPE =

Properties

:puppet

Instance Attribute Summary

Attributes inherited from Event

#name

Attributes inherited from Core

#ui

Instance Method Summary collapse

Methods inherited from Event

build_info, build_info!, create, instance, instance!, #property, #set_properties, #set_property, split_event_string, #type

Methods inherited from Core

#inspect, logger, #logger, logger=, ui

Methods inherited from Config

#[], #[]=, array, #array, #clear, #defaults, #delete, ensure, filter, #filter, #get, #get_array, #get_hash, hash, #hash, #import, #init, init, init_flat, #set, string, #string, string_map, #string_map, #symbol, symbol, #symbol_map, symbol_map, test, #test

Methods included from Mixin::ConfigOptions

#clear_options, #contexts, #get_options, #set_options

Methods included from Mixin::ConfigCollection

#all_properties, #clear_properties, #delete_property, #get_property, #save_properties, #set_property

Methods included from Mixin::Lookup

#hiera, #hiera_config, #initialized?, #lookup, #lookup_array, #lookup_hash, #normalize

Methods included from Mixin::ConfigOps

#parse

Constructor Details

#initialize(options = {}) ⇒ PuppetEvent


Constructor / Destructor



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/coral_core/event/puppet_event.rb', line 12

def initialize(options = {})
  options[:type] = TYPE
  
  super(options)
  
  if options.has_key?(:string)
    items = options[:string].split(':')
    self.element = items[0]
    self.operation = items[1]
    self.message = items[2]
  end
end

Instance Method Details

#check(source) ⇒ Object


Event handling



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/coral_core/event/puppet_event.rb', line 72

def check(source)
  if source.match(/notice:\s+(.+?):\s+(.+)\s*/i)
    source_element = $1
    source_operation = ''
    source_message = $2
                  
    source_elements = source_element.split('/')
    source_operation = source_elements.pop.strip unless source_elements.last.match(/[\[\]]/)
                  
    if source_operation
      source_element = source_elements.join('/').strip
      
      logger.debug("#{source_element} includes: #{element} -- " + ( source_element.include?(element) ? 'true' : 'false' ))
      logger.debug("#{source_operation} is: #{operation} -- " + ( source_operation == operation ? 'true' : 'false' ))
      logger.debug("#{source_message} includes: #{message} -- " + ( source_message.include?(message) ? 'true' : 'false' ))
      
      if source_element.include?(element) && source_operation == operation && source_message.include?(message)
          logger.debug("MATCH! -> #{element} - #{operation} - #{message}")
          return true
      end
    end
  end
  logger.debug("nothing -> #{element} - #{operation} - #{message}")
  return false
end

#elementObject


Property accessors / modifiers



28
29
30
# File 'lib/coral_core/event/puppet_event.rb', line 28

def element
  return property(:element, '', :string)
end

#element=(element) ⇒ Object




34
35
36
# File 'lib/coral_core/event/puppet_event.rb', line 34

def element=element
  set_property(:element, string(element))
end

#exportObject


Import / Export



65
66
67
# File 'lib/coral_core/event/puppet_event.rb', line 65

def export
  return "#{type}:#{element}:#{operation}:#{message}"
end

#messageObject



52
53
54
# File 'lib/coral_core/event/puppet_event.rb', line 52

def message
  return property(:message, '', :string)
end

#message=(message) ⇒ Object




58
59
60
# File 'lib/coral_core/event/puppet_event.rb', line 58

def message=message
  set_property(:message, string(message))
end

#operationObject




40
41
42
# File 'lib/coral_core/event/puppet_event.rb', line 40

def operation
  return property(:operation, '', :string)
end

#operation=(operation) ⇒ Object




46
47
48
# File 'lib/coral_core/event/puppet_event.rb', line 46

def operation=operation
  set_property(:operation, string(operation))
end