Class: LogStash::Filters::Zabbix::Cache

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/filters/zabbix/cache.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(logger, options) ⇒ Cache

Returns a new instance of Cache.



10
11
12
13
14
# File 'lib/logstash/filters/zabbix/cache.rb', line 10

def initialize(logger, options)
  @logger = logger
  @options = options
  @items = {}
end

Instance Attribute Details

#itemsObject

Returns the value of attribute items.



8
9
10
# File 'lib/logstash/filters/zabbix/cache.rb', line 8

def items
  @items
end

Instance Method Details

#endObject



27
28
29
# File 'lib/logstash/filters/zabbix/cache.rb', line 27

def end
  @wt.kill
end

#fetchObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/logstash/filters/zabbix/cache.rb', line 31

def fetch()
  zbx = ZabbixApi.connect(@options)
  response = zbx.query(
    method: 'host.get',
    params: {
        groupids: @options[:group_id],
        output: ['hostid', 'host'],
        selectItems: ['itemid', 'key_', 'formula'],
        selectInterfaces: ['ip'],
    });

  @items = parse(response, @options[:keys])
  @logger.info("Got zabbix items", :size => @items.keys.size)
  @items
end

#startObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/logstash/filters/zabbix/cache.rb', line 16

def start
  self.fetch()
  @wt = Thread.new do
    # update zabbix hosts every 6 hours
    while true
      sleep(@options[:interval] || REFRSH_INTERVAL)
      self.fetch()
    end
  end
end