Class: Fluent::SpecinfraInventoryInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_specinfra_inventory.rb

Constant Summary collapse

KEY_DELIMITER =
"."

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSpecinfraInventoryInput

Returns a new instance of SpecinfraInventoryInput.



22
23
24
25
26
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 22

def initialize
  super
  require 'specinfra'
  require 'specinfra/host_inventory'
end

Instance Attribute Details

#inventoryObject

Returns the value of attribute inventory.



20
21
22
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 20

def inventory
  @inventory
end

Instance Method Details

#configure(conf) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 28

def configure(conf)
  super

  Specinfra.configuration.send(:backend, @backend.to_sym)
  Specinfra.configuration.send(:path, @path) if @path
  Specinfra.configuration.send(:host, @host) if @host
  Specinfra.configuration.send(:env, @env) if @env

  opt = {}
  opt[:family]  = @family  if @family
  opt[:release] = @release if @release
  opt[:arch]    = @arch    if @arch
  Specinfra.configuration.send(:os, opt) if opt.length > 0

  opt = {}
  opt[:user] = @ssh_user  if @ssh_user
  opt[:port] = @ssh_port  if @ssh_port
  Specinfra.configuration.send(:ssh_options, opt) if opt.length > 0

  @inventory = Specinfra::HostInventory.instance
end

#record(key) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 74

def record(key)
  inv = @inventory
  key.split(KEY_DELIMITER).each do |k|
    inv = inv[k]
  end
  inv
end

#runObject



60
61
62
63
64
65
66
67
68
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 60

def run
  loop do
    time = Engine.now
    @inventory_keys.each do |key|
      Engine.emit(tag(key), time, record(key))
    end
    sleep @timespan
  end
end

#shutdownObject



55
56
57
58
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 55

def shutdown
  @finished = true
  @thread.join
end

#startObject



50
51
52
53
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 50

def start
  @finished = false
  @thread = Thread.new(&method(:run))
end

#tag(key) ⇒ Object



70
71
72
# File 'lib/fluent/plugin/in_specinfra_inventory.rb', line 70

def tag(key)
  "#{@tag_prefix}.#{key}"
end