class Zabbix::Sender::Socket
Socket
instances enable TCPSocket based communication with a zabbix trapper server instance
Attributes
Public Class Methods
Create a new socket connection object. Both proxy and port are optional.
An attempt is made to provide sane default values. If you have a zabbix_agentd.conf file in one of the usual places and zabbix_sender is on your path, it'll probably just work
Zabbix::Sender::Connection::new
# File lib/zabbix_sender_api/api.rb, line 135 def initialize(proxy: Zabbix::AgentConfiguration.zabbixProxy, port: 10051) super(proxy: proxy) @port = port @lastres = nil end
Public Instance Methods
Zabbix::Sender::Connection#flush
# File lib/zabbix_sender_api/api.rb, line 171 def flush super return @lastres end
Open tcp socket to target proxy/server
# File lib/zabbix_sender_api/api.rb, line 143 def open @pipe = TCPSocket.new(@targetHost, @port) end
Send aBatch to zabbix via the socket. Note that zabbix will close the connection after you send a complete message, so you *can't* do this:
socket.open socket.sendBatch(a) socket.sendBatch(b) <– this will blow up socket.flush
…as you can with Zabbix::Sender::Pipe
. You're really best off just using sendBatchAtomic for sockets.
This assumes that the socket is already open.
# File lib/zabbix_sender_api/api.rb, line 161 def sendBatch(aBatch) header = %Q(ZBXD\x01) data = aBatch.to_senderstruct.to_json blob = %Q(#{header}#{[data.bytesize].pack("Q").force_encoding("UTF-8")}#{data}) @pipe.write(blob) respHeader = @pipe.read(header.bytesize + 8) datalen = respHeader[header.bytesize, 8].unpack("Q")[0] @lastres = JSON.parse(@pipe.read(datalen)) end