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.



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

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

Instance Method Details

#configure(conf) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 32

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 Fluent::ConfigError, %!It isn't possible to specify both of items" and "items_file"!
  end

  if @items_file
    @items = {}

    Dir.glob(@items_file) do |path|
      file = File.read(path)
      json = JSON.load(file)
      @items.update(json) if json
    end
  end

  if @items.empty?
    raise Fluent::ConfigError, '"items" or "items_file" is empty'
  end

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

#shutdownObject



70
71
72
73
74
75
76
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 70

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

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

#startObject



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

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