Class: Zabbix::Sender
- Inherits:
-
Object
- Object
- Zabbix::Sender
- Defined in:
- lib/zabbix/sender.rb
Direct Known Subclasses
Defined Under Namespace
Constant Summary collapse
- DEFAULT_SERVER_PORT =
10051
Instance Attribute Summary collapse
-
#configured ⇒ Object
readonly
Returns the value of attribute configured.
Instance Method Summary collapse
- #configured? ⇒ Boolean
- #connect ⇒ Object
- #disconnect ⇒ Object
-
#initialize(opts = {}) ⇒ Sender
constructor
A new instance of Sender.
- #send_break(key, err, opts = {}) ⇒ Object
- #send_data(key, value, opts = {}) ⇒ Object
- #send_heartbeat(key, msg = "", opts = {}) ⇒ Object
- #send_start(key, opts = {}) ⇒ Object
- #send_stop(key, opts = {}) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Sender
Returns a new instance of Sender.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/zabbix/sender.rb', line 7 def initialize(opts={}) @client_host = Socket.gethostbyname(Socket.gethostname)[0] if opts[:config_file] config = Zabbix::Agent::Configuration.read(opts[:config_file]) @server_host = config.server @server_port = config.server_port || DEFAULT_SERVER_PORT end if opts[:host] @server_host = opts[:host] @server_port = opts[:port] || DEFAULT_SERVER_PORT end end |
Instance Attribute Details
#configured ⇒ Object (readonly)
Returns the value of attribute configured.
5 6 7 |
# File 'lib/zabbix/sender.rb', line 5 def configured @configured end |
Instance Method Details
#configured? ⇒ Boolean
24 25 26 |
# File 'lib/zabbix/sender.rb', line 24 def configured? @configured ||= !(@server_host.nil? and @server_port.nil?) end |
#connect ⇒ Object
29 30 31 |
# File 'lib/zabbix/sender.rb', line 29 def connect @socket ||= TCPSocket.new(@server_host, @server_port) end |
#disconnect ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/zabbix/sender.rb', line 33 def disconnect if @socket @socket.close unless @socket.closed? @socket = nil end return true end |
#send_break(key, err, opts = {}) ⇒ Object
50 51 52 |
# File 'lib/zabbix/sender.rb', line 50 def send_break(key, err, opts={}) send_data("#{key}.break", err, opts) end |
#send_data(key, value, opts = {}) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/zabbix/sender.rb', line 58 def send_data(key, value, opts={}) return false unless configured? return send_zabbix_request([ cons_zabbix_data_element(key, value, opts) ]) end |
#send_heartbeat(key, msg = "", opts = {}) ⇒ Object
54 55 56 |
# File 'lib/zabbix/sender.rb', line 54 def send_heartbeat(key, msg="", opts={}) send_data("#{key}.heartbeat", msg, opts) end |
#send_start(key, opts = {}) ⇒ Object
41 42 43 |
# File 'lib/zabbix/sender.rb', line 41 def send_start(key, opts={}) send_data("#{key}.start", 1, opts) end |
#send_stop(key, opts = {}) ⇒ Object
46 47 48 |
# File 'lib/zabbix/sender.rb', line 46 def send_stop(key, opts={}) send_data("#{key}.stop", 1, opts) end |