Class: Vayacondios::ZabbixClient

Inherits:
Object
  • Object
show all
Includes:
Gorillib::Builder
Defined in:
lib/vayacondios/client/zabbix_client.rb

Overview

Used for sending events to a Zabbix server.

An ‘event’ from Vayacondios’ perspective is an arbitrary Hash.

An ‘event’ from Zabbix’s perspective is a tuple of values:

  • time

  • host

  • key

  • value

This client will accept a Vayacondios event and internally translate it into a set of Zabbix events.

would get turned into the following events when written to Zabbix:

[

{ host: "foo-server.example.com", key: "cpu.util.user", value: 0.20 }
{ host: "foo-server.example.com", key: "cpu.util.idle", value: 0.70 },
{ host: "foo-server.example.com", key: "cpu.util.sys",  value: 0.10 },
{ host: "foo-server.example.com", key: "cpu.load",      value: 1.3  }

]

Zabbix will interpret the time as the time it receives each event.

The following links provide details on the protocol used by Zabbix to receive events:

Examples:

A CPU monitoring notification


notify "foo-server.example.com", cpu: {
  util: {
    user: 0.20,
    idle: 0.70,
    sys:  0.10
  },
  load: 1.3
}

The CPU monitoring notification translated to Zabbix events

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#socketObject

Returns the value of attribute socket.



52
53
54
# File 'lib/vayacondios/client/zabbix_client.rb', line 52

def socket
  @socket
end

Instance Method Details

#insert(topic, cargo = {}) ⇒ Object

Insert events to a Zabbix server.

The ‘topic` will be used as the name of the Zabbix host to associate event data to.

As per the documentation for the [Zabbix sender protocol](www.zabbix.com/wiki/doc/tech/proto/zabbixsenderprotocol), a new TCP connection will be created for each event.

Array<Hash>] text

Parameters:

  • topic (String)
  • cargo (Hash) (defaults to: {})


69
70
71
72
73
74
# File 'lib/vayacondios/client/zabbix_client.rb', line 69

def insert topic, cargo={}
  self.socket = TCPSocket.new(host, port)
  send_request(topic, cargo)
  handle_response
  self.socket.close
end