1 # discovers against a flatfile instead of the traditional network discovery
2 # the flat file must have a node name per line which should match identities
7 def self.discover(filter, timeout, limit=0, client=nil)
8 unless client.options[:discovery_options].empty?
9 file = client.options[:discovery_options].first
11 raise "The flatfile discovery method needs a path to a text file"
14 raise "Cannot read the file %s specified as discovery source" % file unless File.readable?(file)
18 hosts = File.readlines(file).map do |host|
20 raise 'Identities can only match /\w\.\-/' unless host.match(/^[\w\.\-]+$/)
24 # this plugin only supports identity filters, do regex matches etc against
25 # the list found in the flatfile
26 unless filter["identity"].empty?
27 filter["identity"].each do |identity|
28 identity = Regexp.new(identity.gsub("\/", "")) if identity.match("^/")
30 if identity.is_a?(Regexp)
31 discovered = hosts.grep(identity)
32 elsif hosts.include?(identity)
33 discovered << identity