Class: Reacter::RunnerAgent

Inherits:
Agent
  • Object
show all
Defined in:
lib/reacter/agents/runner.rb

Instance Attribute Summary

Attributes inherited from Agent

#config, #type

Instance Method Summary collapse

Methods inherited from Agent

create, #initialize

Constructor Details

This class inherits a constructor from Reacter::Agent

Instance Method Details

#received(message) ⇒ Object



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
# File 'lib/reacter/agents/runner.rb', line 8

def received(message)
  general =  (Reacter[%W{agents decider sources any #{message.metric}}] || {})
  specific = (Reacter[%W{agents decider sources #{message.source} #{message.metric}}] || {}) if message.source
  decider_config = specific.deep_merge!(general)

  unless decider_config.empty?
    actions = [*decider_config.get('actions.exec', [])]

    actions.each do |action|
      if action.is_a?(String)
        action = {
          'command' => action
        }
      end

      xenv = action.get('environment', {}).collect{|k,v|
        ["REACTER_#{k.upcase}", v]
      }

      message.to_h.reject{|k,v| k.to_sym == :raw }.each_recurse{|k,v,path|
        xenv << ["REACTER_#{path.collect{|i| i.upcase }.join('_')}", v.to_s]
      }
      xenv = Hash[xenv]

      puts xenv.inspect
    end
  end

  return message
end