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<%= @header %>\n" \
'<% @items.each do |item| %>' \
"&<%= item['status'] %> <%= item['label'] %>: <%= item['value'] %>\n" \
"<% end %>\n" \
"<%= @footer %>\n".freeze

Instance Attribute Summary collapse

Attributes inherited from Client

#servers

Instance Method Summary collapse

Methods inherited from Client

#drop

Constructor Details

#initialize(servers, config) ⇒ Service

Returns a new instance of Service.



20
21
22
23
24
# File 'lib/xymonclient/service.rb', line 20

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

Instance Attribute Details

#detailsObject (readonly)

Returns the value of attribute details.



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

def details
  @details
end

#nameObject (readonly)

Returns the value of attribute name.



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

def name
  @name
end

#statusObject

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



95
96
97
# File 'lib/xymonclient/service.rb', line 95

def ack(duration, message)
  super(@info['host'], @info['name'], duration, message)
end

#board(fields = []) ⇒ Object



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

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

#disable(duration, message) ⇒ Object



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

def disable(duration, message)
  super(@info['host'], @info['name'], duration, message)
end

#enableObject



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

def enable
  super(@info['host'], @info['name'])
end

#update_config(config) ⇒ Object

Raises:



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

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

#update_item(name, value) ⇒ Object

Raises:



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

def update_item(name, value)
  raise InvalidServiceItem unless @info['items'].include?(name)
  @info['items'][name].value = value
end