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:

Attributes

data[R]

This is an array of all the ItemData and Discovery instances that have been added to this discovery since instantiation.

Public Class Methods

new(timestamp: Time.now, hostname: Zabbix::AgentConfiguration.zabbixHostname) click to toggle source

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

addDiscovery(aDiscovery) click to toggle source

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
addItemData(key: nil,value: nil,timestamp: @time, hostname: @hostname) click to toggle source

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
appendBatch(aBatch) click to toggle source

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
to_senderline() click to toggle source

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
to_senderstruct() click to toggle source

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