Class: ZabbixSender::Sender

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(zabbix_host: "127.0.0.1", zabbix_port: 10051) ⇒ Sender

Returns a new instance of Sender.



9
10
11
12
# File 'lib/zabbix_sender/sender.rb', line 9

def initialize(zabbix_host: "127.0.0.1", zabbix_port: 10051)
  @zabbix_host = zabbix_host
  @zabbix_port = zabbix_port
end

Instance Attribute Details

#zabbix_hostObject (readonly)

Returns the value of attribute zabbix_host.



7
8
9
# File 'lib/zabbix_sender/sender.rb', line 7

def zabbix_host
  @zabbix_host
end

#zabbix_portObject (readonly)

Returns the value of attribute zabbix_port.



7
8
9
# File 'lib/zabbix_sender/sender.rb', line 7

def zabbix_port
  @zabbix_port
end

Instance Method Details

#post(host, key, value) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/zabbix_sender/sender.rb', line 14

def post(host, key, value)
  request = Request.new(host, key, value)
  begin
    socket = TCPSocket.new(zabbix_host, zabbix_port)
    request.send(socket)
  ensure
    socket.close if socket
  end
end