Class: XymonClient::Client
- Inherits:
-
Object
- Object
- XymonClient::Client
- Defined in:
- lib/xymonclient.rb
Overview
Client object for interacting with Xymon server(s) Params:
-
servers: array of string ‘hostname’ or ‘hostname:port’
(port default to 1984)
Direct Known Subclasses
Instance Attribute Summary collapse
-
#servers ⇒ Object
readonly
Returns the value of attribute servers.
Instance Method Summary collapse
- #ack(host, service, duration, message) ⇒ Object
- #board(host, service, fields = []) ⇒ Object
- #disable(host, service, duration, message) ⇒ Object
- #drop(host, service = '') ⇒ Object
- #enable(host, service) ⇒ Object
-
#initialize(servers = []) ⇒ Client
constructor
A new instance of Client.
- #status(host, service, status, message, lifetime = '30m') ⇒ Object
Constructor Details
#initialize(servers = []) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 |
# File 'lib/xymonclient.rb', line 16 def initialize(servers = []) @servers = \ if servers.empty? XymonClient::ServerDiscovery.find_from_file else _parse_servers(servers) end end |
Instance Attribute Details
#servers ⇒ Object (readonly)
Returns the value of attribute servers.
14 15 16 |
# File 'lib/xymonclient.rb', line 14 def servers @servers end |
Instance Method Details
#ack(host, service, duration, message) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/xymonclient.rb', line 63 def ack(host, service, duration, ) raise XymonClient::InvalidDuration, duration \ unless XymonClient.valid_duration?(duration) = board(host, service, ['cookie']) @servers.each do |server| _send( server, "xymondack #{[server].to_i} #{duration} #{}" ) if [server].to_i != -1 end end |
#board(host, service, fields = []) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/xymonclient.rb', line 52 def board(host, service, fields = []) response = {} @servers.each do |server| response[server] = _send( server, "xymondboard host=#{host} test=#{service} fields=#{fields.join(';')}" ) end response end |
#disable(host, service, duration, message) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/xymonclient.rb', line 36 def disable(host, service, duration, ) raise XymonClient::InvalidDuration, duration \ unless XymonClient.valid_duration?(duration) _send_to_all( "disable #{XymonClient.hostsvc(host, service)} #{duration} #{}" ) end |
#drop(host, service = '') ⇒ Object
48 49 50 |
# File 'lib/xymonclient.rb', line 48 def drop(host, service = '') _send_to_all("drop #{host} #{service}") end |
#enable(host, service) ⇒ Object
44 45 46 |
# File 'lib/xymonclient.rb', line 44 def enable(host, service) _send_to_all("enable #{XymonClient.hostsvc(host, service)}") end |
#status(host, service, status, message, lifetime = '30m') ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/xymonclient.rb', line 25 def status(host, service, status, , lifetime = '30m') raise XymonClient::InvalidDuration, lifetime \ unless XymonClient.valid_duration?(lifetime) raise XymonClient::InvalidStatus, status \ unless XymonClient.valid_status?(status) _send_to_all( "status+#{lifetime} " \ "#{XymonClient.hostsvc(host, service)} #{status} #{}" ) end |