Class: XymonClient::Client

Inherits:
Object
  • Object
show all
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

Service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(servers = [], retry_count = 3, retry_interval = 5) ⇒ Client

Returns a new instance of Client.



18
19
20
21
22
23
24
25
26
27
# File 'lib/xymonclient.rb', line 18

def initialize(servers = [], retry_count = 3, retry_interval = 5)
  @servers = \
    if servers.empty?
      XymonClient::ServerDiscovery.find_from_file
    else
      _parse_servers(servers)
    end
  @retry_count = retry_count
  @retry_interval = retry_interval
end

Instance Attribute Details

#retry_countObject

Returns the value of attribute retry_count.



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

def retry_count
  @retry_count
end

#retry_intervalObject

Returns the value of attribute retry_interval.



16
17
18
# File 'lib/xymonclient.rb', line 16

def retry_interval
  @retry_interval
end

#serversObject (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



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/xymonclient.rb', line 67

def ack(host, service, duration, message)
  raise XymonClient::InvalidDuration, duration \
    unless XymonClient.valid_duration?(duration)
  cookies = board(host, service, ['cookie'])
  @servers.each do |server|
    next if cookies[server].to_i == -1
    _send(
      server,
      "xymondack #{cookies[server].to_i} #{duration} #{message}"
    )
  end
end

#board(host, service, fields = []) ⇒ Object



56
57
58
59
60
61
62
63
64
65
# File 'lib/xymonclient.rb', line 56

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



40
41
42
43
44
45
46
# File 'lib/xymonclient.rb', line 40

def disable(host, service, duration, message)
  raise XymonClient::InvalidDuration, duration \
    unless XymonClient.valid_duration?(duration)
  _send_to_all(
    "disable #{XymonClient.hostsvc(host, service)} #{duration} #{message}"
  )
end

#drop(host, service = '') ⇒ Object



52
53
54
# File 'lib/xymonclient.rb', line 52

def drop(host, service = '')
  _send_to_all("drop #{host} #{service}")
end

#enable(host, service) ⇒ Object



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

def enable(host, service)
  _send_to_all("enable #{XymonClient.hostsvc(host, service)}")
end

#status(host, service, status, message, lifetime = '30m') ⇒ Object



29
30
31
32
33
34
35
36
37
38
# File 'lib/xymonclient.rb', line 29

def status(host, service, status, message, 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} #{message}"
  )
end