Class: Zabbix::Sender::ItemData
- Inherits:
-
Object
- Object
- Zabbix::Sender::ItemData
- Defined in:
- lib/zabbix_sender_api/api.rb
Overview
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
Direct Known Subclasses
Instance Attribute Summary collapse
-
#hostname ⇒ Object
The name of the zabbix host that owns the item key.
-
#key ⇒ Object
The item key that’ll get the new value.
-
#timestamp ⇒ Object
The timestamp for this datapoint.
-
#value ⇒ Object
The value that the item will get.
Instance Method Summary collapse
-
#initialize(key: nil, value: nil, timestamp: nil, hostname: nil) ⇒ ItemData
constructor
All values must be provided.
-
#to_senderline ⇒ Object
Render the ItemData instance as a line of text that can be piped into zabbix_sender.
-
#to_senderstruct ⇒ Object
Render the ItemData instance as an object suitable for conversion to json, for socket transmission.
Constructor Details
#initialize(key: nil, value: nil, timestamp: nil, hostname: nil) ⇒ ItemData
All values must be provided.
264 265 266 267 268 269 |
# File 'lib/zabbix_sender_api/api.rb', line 264 def initialize(key: nil,value: nil, timestamp: nil, hostname: nil) @key = key @value = value = @hostname = hostname end |
Instance Attribute Details
#hostname ⇒ Object
The name of the zabbix host that owns the item key
257 258 259 |
# File 'lib/zabbix_sender_api/api.rb', line 257 def hostname @hostname end |
#key ⇒ Object
The item key that’ll get the new value
251 252 253 |
# File 'lib/zabbix_sender_api/api.rb', line 251 def key @key end |
#timestamp ⇒ Object
The timestamp for this datapoint
260 261 262 |
# File 'lib/zabbix_sender_api/api.rb', line 260 def end |
#value ⇒ Object
The value that the item will get
254 255 256 |
# File 'lib/zabbix_sender_api/api.rb', line 254 def value @value end |
Instance Method Details
#to_senderline ⇒ Object
Render the ItemData instance as a line of text that can be piped into zabbix_sender
273 274 275 276 277 278 279 |
# File 'lib/zabbix_sender_api/api.rb', line 273 def to_senderline if .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 ⇒ Object
Render the ItemData instance as an object suitable for conversion to json, for socket transmission
282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/zabbix_sender_api/api.rb', line 282 def to_senderstruct if .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: .to_i } end end |