Class: XymonClient::Service
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
-
#details ⇒ Object
readonly
Returns the value of attribute details.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
Returns the value of attribute status.
Attributes inherited from Client
Instance Method Summary collapse
- #ack(duration, message) ⇒ Object
- #board(fields = []) ⇒ Object
- #disable(duration, message) ⇒ Object
- #enable ⇒ Object
-
#initialize(servers, config) ⇒ Service
constructor
A new instance of Service.
- #update_config(config) ⇒ Object
- #update_item(name, value) ⇒ Object
Methods inherited from Client
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
#details ⇒ Object (readonly)
Returns the value of attribute details.
12 13 14 |
# File 'lib/xymonclient/service.rb', line 12 def details @details end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/xymonclient/service.rb', line 10 def name @name end |
#status ⇒ Object
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, ) super(@info['host'], @info['name'], duration, ) 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, ) super(@info['host'], @info['name'], duration, ) end |
#enable ⇒ Object
83 84 85 |
# File 'lib/xymonclient/service.rb', line 83 def enable super(@info['host'], @info['name']) end |
#update_config(config) ⇒ Object
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
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 |