class Zabbix::Sender::ItemData

ItemData instances hold the k-v pair of a value and its timestamp along with the hostname to which the data belongs. It handles formatting that data appropriately as input to zabbix_sender

Attributes

hostname[RW]

The name of the zabbix host that owns the item key

key[RW]

The item key that'll get the new value

timestamp[RW]

The timestamp for this datapoint

value[RW]

The value that the item will get

Public Class Methods

new(key: nil,value: nil, timestamp: nil, hostname: nil) click to toggle source

All values must be provided.

# File lib/zabbix_sender_api/api.rb, line 255
def initialize(key: nil,value: nil, timestamp:  nil, hostname: nil)
  @key = key
  @value = value
  @timestamp = timestamp
  @hostname = hostname
end

Public Instance Methods

to_senderline() click to toggle source

Render the ItemData instance as a line of text that can be piped into zabbix_sender

# File lib/zabbix_sender_api/api.rb, line 264
def to_senderline
  if @timestamp.to_i == 0
    puts %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@value}\n)
    abort("Attempt was made to render a timestamp of zero.  You DO NOT want this - it can kill db performance. Fix it.")
  end
  return %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@value}\n)
end
to_senderstruct() click to toggle source

Render the ItemData instance as an object suitable for conversion to json, for socket transmission

# File lib/zabbix_sender_api/api.rb, line 273
def to_senderstruct
  if @timestamp.to_i == 0
    puts %Q("#{@hostname}" #{@key} #{@timestamp.to_i} #{@value}\n)
    abort("Attempt was made to render a timestamp of zero.  You DO NOT want this - it can kill db performance. Fix it.")
  else
    return item = {
      host: @hostname,
      key: @key,
      value: @value,
      clock: @timestamp.to_i
    }
  end
end