Class: Zabbix::Sender::Pipe
- Inherits:
-
Connection
- Object
- Connection
- Zabbix::Sender::Pipe
- 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
Instance Method Summary collapse
-
#flush ⇒ Object
Closes the open3 pipe stuff.
-
#initialize(proxy: Zabbix::AgentConfiguration.zabbixProxy, path: 'zabbix_sender', nanos: false) ⇒ Pipe
constructor
Create a new Pipe object.
-
#open ⇒ Object
Opens a pipe to the zabbix_sender command with appropriate options specified.
-
#sendBatch(aBatch) ⇒ Object
Send a Batch instance to zabbix (via zabbix_sender).
Methods inherited from Connection
Constructor Details
#initialize(proxy: Zabbix::AgentConfiguration.zabbixProxy, path: 'zabbix_sender', nanos: false) ⇒ 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
After v1.1.3 you need to pay attention to whether your pipe connection is going to be moving NanosecondItemData or not. The default behavior is as before (it’s assumed that you’re not sending ns stuff). If you toggle the nanos switch when you construct pipe though, you’ll cause an alteration in the command line switches that presumes that the item data type is the nanosecond subclass. In other words: if you want to build nanosecond item data and you want to send that through a shell pipe, you have to ensure that the shell pipe’s command is also aware of the fact that its sending ns data.
200 201 202 203 204 205 |
# File 'lib/zabbix_sender_api/api.rb', line 200 def initialize(proxy: Zabbix::AgentConfiguration.zabbixProxy, path: 'zabbix_sender', nanos: false) super(proxy: proxy) @nanos = nanos @wait_thr = @stdout = @stderr = nil @exePath = path end |
Instance Method Details
#flush ⇒ Object
Closes the open3 pipe stuff. We need this override method as closing an open3 pipe requires some extra work.
222 223 224 225 226 227 228 229 230 231 |
# File 'lib/zabbix_sender_api/api.rb', line 222 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 |
#open ⇒ Object
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
212 213 214 215 216 217 |
# File 'lib/zabbix_sender_api/api.rb', line 212 def open self.flush #@pipe = IO.popen(%Q(#{@exePath} -z #{@targetHost} -vv -T -i-),'w') cmd = %Q(#{@exePath} -z #{@targetHost} -vv #{@nanos ? '-T -N' : '-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.
236 237 238 239 |
# File 'lib/zabbix_sender_api/api.rb', line 236 def sendBatch(aBatch) # Assumes that the pipe is open @pipe.puts(aBatch.to_senderline) end |