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.



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

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

Instance Method Details

#configure(conf) ⇒ Object



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
69
70
71
72
73
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 36

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

  if @include_hostname
    @extra.update(@hostname_key => hostname)
  end
end

#shutdownObject



84
85
86
87
88
89
90
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 84

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

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

#startObject



75
76
77
78
79
80
81
82
# File 'lib/fluent/plugin/in_zabbix_agent.rb', line 75

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