Class: ZabbixSender::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/zabbix_sender/request.rb

Overview

Zabbix Sender protocol:

www.zabbix.org/wiki/Docs/protocols www.zabbix.com/documentation/2.4/manual/appendix/items/activepassive

<HEADER><DATA LENGTH><DATA>

HEADER - “ZBXDx01” DATA LENGTH - data length (8 bytes, little endian) DATA - JSON, see data method

Constant Summary collapse

HEADER =
"ZBXD\x01"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, key, value) ⇒ Request

Returns a new instance of Request.



19
20
21
22
23
# File 'lib/zabbix_sender/request.rb', line 19

def initialize(host, key, value)
  @host  = host
  @key   = key
  @value = value
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



17
18
19
# File 'lib/zabbix_sender/request.rb', line 17

def host
  @host
end

#keyObject (readonly)

Returns the value of attribute key.



17
18
19
# File 'lib/zabbix_sender/request.rb', line 17

def key
  @key
end

#valueObject (readonly)

Returns the value of attribute value.



17
18
19
# File 'lib/zabbix_sender/request.rb', line 17

def value
  @value
end

Instance Method Details

#responseObject



31
32
33
# File 'lib/zabbix_sender/request.rb', line 31

def response
  @response ||= JSON.parse(@raw_response[13..-1])
end

#send(socket) ⇒ Object



25
26
27
28
29
# File 'lib/zabbix_sender/request.rb', line 25

def send(socket)
  socket.puts(encoded_data)
  @raw_response = socket.gets
  response
end