class Zabbix::Sender::Discovery

Discovery instances are a special type of ItemData that you will typically create and hang on to as you accumulate (discover) related entities. You then pass the discover instance into a Batch via addDiscovery(), which includes it in the batch of data just like an ordinary ItemData instance.

Attributes

entities[R]

Public Class Methods

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

The only required parameter is key:, which is the discovery rule key.

Calls superclass method Zabbix::Sender::ItemData::new
# File lib/zabbix_sender_api/api.rb, line 298
def initialize(key: nil,value: nil, timestamp:  nil, hostname: nil)
  super
  @entities = Set.new
end

Public Instance Methods

add_entity(aHash) click to toggle source

This is how you pass data to zabbix that you use to construct items from item templates. Pass in as many key-value pairs as you need. You'll reference these in the item prototype like {#MYKEY}

Note that the keys (which you can pass as symbols if you want) are forced to uppercase. This is here because the author once spent way too much time trying to figure out why discovery wasn't working right one day. All caps seems to fix the issue.

# File lib/zabbix_sender_api/api.rb, line 310
def add_entity(aHash)
  # just send in key value pairs - these will be the variables you can use in the discovery item prototypes
  zabbified = Hash.new
  aHash.each_pair { |key,value|
    zabbified[%Q({##{key.to_s.upcase}})] = value
  }
  @entities.add(zabbified)
end
to_discodata() click to toggle source

Render this discovery as the structure an external discovery script should return. You can use this if you're writing custom external discovery logic

# File lib/zabbix_sender_api/api.rb, line 322
def to_discodata
  disco = { 'data'=>Array.new }
  disco['data'] = @entities.to_a
  return disco
end
to_senderline() click to toggle source

Render this discovery instance as a zabbix_sender line.

Calls superclass method Zabbix::Sender::ItemData#to_senderline
# File lib/zabbix_sender_api/api.rb, line 330
def to_senderline
  @value = self.to_discodata.to_json
  super
end
to_senderstruct() click to toggle source

Render this discovery instance as an object suitable for conversion to json for socket transmission

# File lib/zabbix_sender_api/api.rb, line 336
def to_senderstruct
  @value = self.to_discodata
  super
end