Class: Zabbix::Sender::Pipe

Inherits:
Connection show all
Defined in:
lib/zabbix_sender_api/api.rb

Overview

Pipe instances utilize communication to a running instance of zabbix_sender via a pipe to STDIN. If you want your program to send data itself (as opposed to say printing stdin lines that you can then pipe to zabbix_sender yourself), you’ll want to make an instance of this

Instance Attribute Summary

Attributes inherited from Connection

#pipe, #targetHost

Instance Method Summary collapse

Methods inherited from Connection

#sendBatchAtomic

Constructor Details

#initialize(proxy: Zabbix::AgentConfiguration.zabbixProxy, path: 'zabbix_sender') ⇒ Pipe

Create a new Pipe object. Both proxy: and path: 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



192
193
194
195
196
# File 'lib/zabbix_sender_api/api.rb', line 192

def initialize(proxy: Zabbix::AgentConfiguration.zabbixProxy, path: 'zabbix_sender')
  super(proxy: proxy)
  @wait_thr = @stdout = @stderr = nil
  @exePath = path
end

Instance Method Details

#flushObject

Closes the open3 pipe stuff. We need this override method as closing an open3 pipe requires some extra work.



213
214
215
216
217
218
219
220
221
222
# File 'lib/zabbix_sender_api/api.rb', line 213

def flush
  if @pipe and not @pipe.closed?
    @pipe.close
    stdout = @stdout.read
    stderr = @stderr.read
    @stdout.close
    @stderr.close
    return {stdout: stdout, stderr: stderr, success: @wait_thr.value.success?}
  end
end

#openObject

Opens a pipe to the zabbix_sender command with appropriate options specified. If the pipe is already opened when this command is called, it is first closed via a call to flush



203
204
205
206
207
208
# File 'lib/zabbix_sender_api/api.rb', line 203

def open
  self.flush
  #@pipe = IO.popen(%Q(#{@exePath} -z #{@targetHost} -vv -T -i-),'w')
  cmd = %Q(#{@exePath} -z #{@targetHost} -vv -T -i-)
  @pipe,@stdout,@stderr,@wait_thr = Open3.popen3(cmd)
end

#sendBatch(aBatch) ⇒ Object

Send a Batch instance to zabbix (via zabbix_sender). This assumes that the pipe is already open.



227
228
229
230
# File 'lib/zabbix_sender_api/api.rb', line 227

def sendBatch(aBatch)
  # Assumes that the pipe is open
  @pipe.puts(aBatch.to_senderline)
end