Class: XymonClient::ServiceItem

Inherits:
Object
  • Object
show all
Defined in:
lib/xymonclient/serviceitem.rb

Overview

Manage an item to monitor

Direct Known Subclasses

ServiceItemGauge, ServiceItemString

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ ServiceItem

Returns a new instance of ServiceItem.

Raises:

  • (InvalidServiceItemName)


17
18
19
20
21
22
23
# File 'lib/xymonclient/serviceitem.rb', line 17

def initialize(config)
  raise InvalidServiceItemName if config.fetch('label', '') == ''
  @time = Time.at(0)
  @threshold = config.fetch('threshold', {})
  @attributes = config.fetch('attributes', {})
  update_config(config)
end

Instance Attribute Details

#attributesObject

Returns the value of attribute attributes.



9
10
11
# File 'lib/xymonclient/serviceitem.rb', line 9

def attributes
  @attributes
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/xymonclient/serviceitem.rb', line 11

def description
  @description
end

#enabledObject

Returns the value of attribute enabled.



10
11
12
# File 'lib/xymonclient/serviceitem.rb', line 10

def enabled
  @enabled
end

#labelObject

Returns the value of attribute label.



13
14
15
# File 'lib/xymonclient/serviceitem.rb', line 13

def label
  @label
end

#lifetimeObject

Returns the value of attribute lifetime.



12
13
14
# File 'lib/xymonclient/serviceitem.rb', line 12

def lifetime
  @lifetime
end

#statusObject (readonly)

Returns the value of attribute status.



14
15
16
# File 'lib/xymonclient/serviceitem.rb', line 14

def status
  @status
end

#timeObject (readonly)

Returns the value of attribute time.



15
16
17
# File 'lib/xymonclient/serviceitem.rb', line 15

def time
  @time
end

#valueObject

Returns the value of attribute value.



8
9
10
# File 'lib/xymonclient/serviceitem.rb', line 8

def value
  @value
end

Instance Method Details

#contextObject



55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xymonclient/serviceitem.rb', line 55

def context
  {
    'label' => @label,
    'description' => @description,
    'enabled' => @enabled,
    'lifetime' => @lifetime,
    'timestamp' => @timestamp,
    'threshold' => @threshold,
    'attributes' => @attributes,
    'status' => @status,
    'value' => @value
  }
end

#update_config(config) ⇒ Object

Raises:

  • (InvalidServiceItemName)


45
46
47
48
49
50
51
52
53
# File 'lib/xymonclient/serviceitem.rb', line 45

def update_config(config)
  raise InvalidServiceItemName if config.fetch('label', '') == ''
  @label = config['label']
  @description = config.fetch('description', '')
  @enabled = config.fetch('enabled', true)
  @lifetime = config.fetch('lifetime', '30m')
  @threshold = config.fetch('threshold', {})
  @attributes.merge!(config.fetch('attributes', {}))
end