class XymonClient::ServerDiscovery

static methods of servers discovery

Public Instance Methods

find_from_file(file = '/etc/xymon/xymonclient.cfg') click to toggle source
# File lib/xymonclient/discovery.rb, line 7
def find_from_file(file = '/etc/xymon/xymonclient.cfg')
  result = []
  open(file, 'r').read.each_line do |line|
    next unless line =~ /^XYMSRV=/ || line =~ /^XYMSERVERS=/
    ip = line.scan(/[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}/)
    if ip[0] != '0.0.0.0' && line =~ /^XYMSRV=/
      result << xymsrv_ip
      break
    else
      result = ip
    end
  end
  raise NoXymonServerDefined if result.empty?
  result.map { |ip| { host: ip, port: 1984 } }
end