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
31
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 25

def initialize
  super
  require 'socket'
  require 'zabbix_protocol'
  require 'json'
  require 'open-uri'
end

Instance Method Details

#configure(conf) ⇒ Object



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
60
61
62
63
64
65
66
67
68
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 33

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 = {}

    files = Dir.glob(@items_file)

    if files.empty?
      file = open(@items_file, &:read)
      json = JSON.load(file)
      @items.update(json) if json
    else
      Dir.glob(@items_file) do |path|
        file = File.read(path)
        json = JSON.load(file)
        @items.update(json) if json
      end
    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



79
80
81
82
83
84
85
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 79

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

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

#startObject



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

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