Class: Fluent::ZabbixAgentInput

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

Defined Under Namespace

Classes: TimerWatcher

Instance Method Summary collapse

Constructor Details

#initializeZabbixAgentInput

Returns a new instance of ZabbixAgentInput.



23
24
25
26
27
28
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 23

def initialize
  super
  require 'socket'
  require 'zabbix_protocol'
  require 'json'
end

Instance Method Details

#configure(conf) ⇒ Object



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

def configure(conf)
  super

  if @items.nil? and @items_file.nil?
    raise Fluent::ConfigError, 'One of "items" or "items_file" is required'
  elsif @items and @items_file
    raise %!It isn't possible to specify both of items" and "items_file"!
  end

  if @items_file
    @items = File.read(@items_file)
    @items = JSON.load(@items)
  end

  @items.keys.each do |key|
    value = @items[key]
    @items[key] = key if value.nil?
  end
end

#shutdownObject



59
60
61
62
63
64
65
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 59

def shutdown
  @loop.watchers.each(&:detach)
  @loop.stop

  # XXX: Comment out for exit soon. Is it OK?
  #@thread.join
end

#startObject



50
51
52
53
54
55
56
57
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 50

def start
  super

  @loop = Coolio::Loop.new
  timer = TimerWatcher.new(@interval, true, log, &method(:fetch_items))
  @loop.attach(timer)
  @thread = Thread.new(&method(:run))
end