class Zabbix::Sender::Batch
Batch
instances hold all the data and discovery that you collect as your program does its thing with source data. Once you've done all your data collection, you can:
-
Send the batch instance to an instance of
Pipe
to have it transmitted to zabbix -
puts mybatch.to_senderline to output the zabbix_sender input text
-
Use it to help feed data into zabbix by whatever other mechanism you might be using, e.g. a ruby implementation of the zabbix sender protocol
Attributes
Public Class Methods
Both parameters are optional - reasonable defaults are provided.
Bear in mind that the hostname and timestamp values you provide here will be applied to all the ItemData
and Discovery
objects you add via the addItemData() and addDiscovery() methods by default (unless you override them when you add them)
# File lib/zabbix_sender_api/api.rb, line 364 def initialize(timestamp: Time.now, hostname: Zabbix::AgentConfiguration.zabbixHostname) @time = timestamp @hostname = hostname @data = Array.new end
Public Instance Methods
Add a discovery object to this batch of data. The object will be added to the top of the item list.
If you did not specifically provide a hostname or a timestamp when you instantiated the Discovery
, they'll given the ones provided when this instance of Batch
was constructed.
# File lib/zabbix_sender_api/api.rb, line 387 def addDiscovery(aDiscovery) # It doesn't matter right now really as zabbix has to digest the disco # and won't do it before it tries to process the data, but it makes logical # sense to put discos first. aDiscovery.timestamp = @time if not aDiscovery.timestamp aDiscovery.hostname = @hostname if not aDiscovery.hostname @data.unshift(aDiscovery) end
Create a new instance of ItemData
and add that instance to the list of data that this batch contains. You must provide a key and a value. You can provide a timestamp and a hostname. If you do not provide a timestamp or hostname, they will be given the timestamp and hostname associated with the instance of Batch
that you're working with
# File lib/zabbix_sender_api/api.rb, line 375 def addItemData(key: nil,value: nil,timestamp: @time, hostname: @hostname) @data.push(ItemData.new(key: key,value: value,timestamp: timestamp,hostname: hostname)) end
Append another batch's data into this one.
# File lib/zabbix_sender_api/api.rb, line 398 def appendBatch(aBatch) @data.append(*aBatch.data) end
Render this batch of data as a sequence of lines of text appropriate for sending into zabbix_sender
# File lib/zabbix_sender_api/api.rb, line 406 def to_senderline @data.collect {|line| line.to_senderline}.join end
Render this batch as a json object
# File lib/zabbix_sender_api/api.rb, line 412 def to_senderstruct return batch = { request: "sender data", data: @data.collect {|item| item.to_senderstruct}, clock: @time.to_i } end