Class: XymonClient::ServerDiscovery

Inherits:
Object
  • Object
show all
Defined in:
lib/xymonclient/discovery.rb

Overview

static methods of servers discovery

Instance Method Summary collapse

Instance Method Details

#find_from_file(file = '/etc/xymon/xymonclient.cfg') ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# 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