Class: Zabbix::Sender::Discovery
- Defined in:
- lib/zabbix_sender_api/api.rb
Overview
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.
Instance Attribute Summary collapse
-
#entities ⇒ Object
readonly
Returns the value of attribute entities.
Attributes inherited from ItemData
#hostname, #key, #timestamp, #value
Instance Method Summary collapse
-
#add_entity(aHash) ⇒ Object
This is how you pass data to zabbix that you use to construct items from item templates.
-
#initialize(key: nil, value: nil, timestamp: nil, hostname: nil) ⇒ Discovery
constructor
The only required parameter is key:, which is the discovery rule key.
-
#to_discodata ⇒ Object
Render this discovery as the structure an external discovery script should return.
-
#to_senderline ⇒ Object
Render this discovery instance as a zabbix_sender line.
-
#to_senderstruct ⇒ Object
Render this discovery instance as an object suitable for conversion to json for socket transmission.
Constructor Details
#initialize(key: nil, value: nil, timestamp: nil, hostname: nil) ⇒ Discovery
The only required parameter is key:, which is the discovery rule key.
339 340 341 342 |
# File 'lib/zabbix_sender_api/api.rb', line 339 def initialize(key: nil,value: nil, timestamp: nil, hostname: nil) super @entities = Set.new end |
Instance Attribute Details
#entities ⇒ Object (readonly)
Returns the value of attribute entities.
335 336 337 |
# File 'lib/zabbix_sender_api/api.rb', line 335 def entities @entities end |
Instance Method Details
#add_entity(aHash) ⇒ Object
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.
351 352 353 354 355 356 357 358 |
# File 'lib/zabbix_sender_api/api.rb', line 351 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 ⇒ Object
Render this discovery as the structure an external discovery script should return. You can use this if you’re writing custom external discovery logic
363 364 365 366 367 |
# File 'lib/zabbix_sender_api/api.rb', line 363 def to_discodata disco = { 'data'=>Array.new } disco['data'] = @entities.to_a return disco.to_json end |
#to_senderline ⇒ Object
Render this discovery instance as a zabbix_sender line.
371 372 373 374 |
# File 'lib/zabbix_sender_api/api.rb', line 371 def to_senderline @value = self.to_discodata.to_json super end |
#to_senderstruct ⇒ Object
Render this discovery instance as an object suitable for conversion to json for socket transmission
377 378 379 380 |
# File 'lib/zabbix_sender_api/api.rb', line 377 def to_senderstruct @value = self.to_discodata super end |