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.



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

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

Instance Method Details

#configure(conf) ⇒ Object



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

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

    if @items_file =~ %r{\A(https?|ftp)://}
      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? and not @allow_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



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

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

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

#startObject



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

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