Class: Zabbix::Sender::Buffer

Inherits:
Zabbix::Sender show all
Defined in:
lib/zabbix/sender/buffer.rb

Constant Summary

Constants inherited from Zabbix::Sender

DEFAULT_SERVER_PORT

Instance Attribute Summary

Attributes inherited from Zabbix::Sender

#configured

Instance Method Summary collapse

Methods inherited from Zabbix::Sender

#configured?, #connect, #disconnect, #send_data, #send_heartbeat, #send_start, #send_stop

Constructor Details

#initialize(opts = {}) ⇒ Buffer

Returns a new instance of Buffer.



2
3
4
5
# File 'lib/zabbix/sender/buffer.rb', line 2

def initialize(opts={})
  @buffer = [] 
  super(opts)
end

Instance Method Details

#append(key, value, opts = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/zabbix/sender/buffer.rb', line 7

def append(key, value, opts={})
  return false unless configured?
  @buffer << {
    :host  => opts[:host] || Socket.gethostname,
    :clock => opts[:ts  ] || Time.now.to_i,
    :key   => key, 
    :value => value, 
  }
end

#flushObject



17
18
19
20
21
22
# File 'lib/zabbix/sender/buffer.rb', line 17

def flush 
  return false unless @buffer.size > 0
  ret = send_zabbix_request(@buffer)
  @buffer.clear
  return ret
end