One can send a bunch of key => values to zabbix with the zabbix-trapper items.
Using this nice article as a base I have packed everthing in a class so that you can use it:
Example usage:
values = {
total_ram: 0,
wrong_data_center: 0,
linode_hosts: 0,
missing_from_zabbix: 0,
missing_from_graylog: 0,
}
zabbix_sender = ZabbixSender.new(Figaro['zabbix_server'])
zabbix_sender.message('super_druper_hostname', values)
require 'json'
class ZabbixSender
def initialize zabbix_host
@zabbix_host = zabbix_host
end
def message hostname, values
values_with_host = with_host(hostname, values)
params = {
"request" => "sender data",
"data" => values_with_host,
}
body = JSON.generate params
data_length = body.bytesize
data_header = "ZBXD\1".encode("ascii") + \
[data_length].pack("i") + \
"\x00\x00\x00\x00"
data_to_send = data_header + body
send data_to_send
end
private
def with_host hostname, hash
values = []
hash.each_pair do |key, value|
values << {
key: key,
value: value,
host: hostname,
}
end
values
end
def send data_to_send
socket = TCPSocket.new(@zabbix_host, 10051)
socket.write data_to_send.to_s
response_header = socket.recv(5)
if not response_header == "ZBXD\1"
puts "response: #{response_header}"
raise 'Got invalid response'
end
response_data_header = socket.recv(8)
response_length = response_data_header[0,4].unpack("i")[0]
response_raw = socket.recv(response_length)
socket.close
response = JSON.load(response_raw)
end
end