Class: XymonClient::Service

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

Overview

Manage a Service, can contains multiple items to monitor

Constant Summary collapse

DEFAULT_DETAILS_TEMPLATE =
"Generated at <%= @timestamp %> for <%= @lifetime %> \n" \
'<% @items.each do |item| %>' \
"&<%= item['status'] %> <%= item['label'] %>: <%= item['value'] %>\n" \
"<% end %>\n".freeze

Instance Attribute Summary collapse

Attributes inherited from Client

#retry_count, #retry_interval, #servers

Instance Method Summary collapse

Methods inherited from Client

#drop

Constructor Details

#initialize(servers, config) ⇒ Service

Returns a new instance of Service.



22
23
24
25
26
27
# File 'lib/xymonclient/service.rb', line 22

def initialize(servers, config)
  super(servers)
  @items = {}
  @current_state = 'purple'
  update_config(config)
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



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

def enabled
  @enabled
end

#itemsObject (readonly)

Returns the value of attribute items.



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

def items
  @items
end

#lifetimeObject

Returns the value of attribute lifetime.



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

def lifetime
  @lifetime
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#ack(duration, message) ⇒ Object



91
92
93
# File 'lib/xymonclient/service.rb', line 91

def ack(duration, message)
  super(@host, @name, duration, message)
end

#board(fields = []) ⇒ Object



87
88
89
# File 'lib/xymonclient/service.rb', line 87

def board(fields = [])
  super(@host, @name, fields)
end

#disable(duration, message) ⇒ Object



83
84
85
# File 'lib/xymonclient/service.rb', line 83

def disable(duration, message)
  super(@host, @name, duration, message)
end

#enableObject



79
80
81
# File 'lib/xymonclient/service.rb', line 79

def enable
  super(@host, @name)
end

#update_config(config) ⇒ Object

Raises:



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/xymonclient/service.rb', line 29

def update_config(config)
  raise InvalidService if config.fetch('name', '') == ''
  raise InvalidService if config.fetch('host', '') == ''
  @name = config['name']
  @host = config['host']
  @details_template = config.fetch(
    'details_template',
    DEFAULT_DETAILS_TEMPLATE
  )
  @lifetime = config.fetch('lifetime', '30m')
  @enabled = config.fetch('enabled', true)
  if config.fetch('items', {}).empty?
    @items = {}
  else
    _update_items_config(config['items'])
  end
  @purple_item_status = config.fetch('purple_item_status', 'red')
end

#update_item(name, value, attrs = {}) ⇒ Object

Raises:



48
49
50
51
52
# File 'lib/xymonclient/service.rb', line 48

def update_item(name, value, attrs = {})
  raise InvalidServiceItem unless @items.include?(name)
  @items[name].value = value
  @items[name].attributes.merge!(attrs)
end