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.
255 256 257 258 259 260 |
# File 'lib/zabbix_sender_api/api.rb', line 255 def initialize(key: nil,value: nil, timestamp: nil, hostname: nil) @key = key @value = value @timestamp = @hostname = hostname end |
Instance Attribute Details
#hostname ⇒ Object
The name of the zabbix host that owns the item key
248 249 250 |
# File 'lib/zabbix_sender_api/api.rb', line 248 def hostname @hostname end |
#key ⇒ Object
The item key that'll get the new value
242 243 244 |
# File 'lib/zabbix_sender_api/api.rb', line 242 def key @key end |
#timestamp ⇒ Object
The timestamp for this datapoint
251 252 253 |
# File 'lib/zabbix_sender_api/api.rb', line 251 def @timestamp end |
#value ⇒ Object
The value that the item will get
245 246 247 |
# File 'lib/zabbix_sender_api/api.rb', line 245 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
264 265 266 267 268 269 270 |
# 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 ⇒ Object
Render the ItemData instance as an object suitable for conversion to json, for socket transmission
273 274 275 276 277 278 279 280 281 282 283 284 285 |
# 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 |