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" \ '<% @items.each do |item| %>' \ "&<%= item['status'] %> <%= item['label'] %>: <%= item['value'] %>\n" \ "<% end %>\n".freeze
Instance Attribute Summary collapse
-
#enabled ⇒ Object
Returns the value of attribute enabled.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#lifetime ⇒ Object
Returns the value of attribute lifetime.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Attributes inherited from Client
#retry_count, #retry_interval, #servers
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, attrs = {}) ⇒ Object
Methods inherited from Client
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
#enabled ⇒ Object
Returns the value of attribute enabled.
13 14 15 |
# File 'lib/xymonclient/service.rb', line 13 def enabled @enabled end |
#items ⇒ Object (readonly)
Returns the value of attribute items.
12 13 14 |
# File 'lib/xymonclient/service.rb', line 12 def items @items end |
#lifetime ⇒ Object
Returns the value of attribute lifetime.
14 15 16 |
# File 'lib/xymonclient/service.rb', line 14 def lifetime @lifetime 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 (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, ) super(@host, @name, duration, ) 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, ) super(@host, @name, duration, ) end |
#enable ⇒ Object
79 80 81 |
# File 'lib/xymonclient/service.rb', line 79 def enable super(@host, @name) end |
#update_config(config) ⇒ Object
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
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 |