class Zabbix::Sender::Pipe
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
Public Class Methods
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
Zabbix::Sender::Connection::new
# 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
Public Instance Methods
Closes the open3 pipe stuff. We need this override method as closing an open3 pipe requires some extra work.
# 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
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
# 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
Send a Batch
instance to zabbix (via zabbix_sender). This assumes that the pipe is already open.
# File lib/zabbix_sender_api/api.rb, line 227 def sendBatch(aBatch) # Assumes that the pipe is open @pipe.puts(aBatch.to_senderline) end