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{|l| l.chomp}
20 # this plugin only supports identity filters, do regex matches etc against
21 # the list found in the flatfile
22 unless filter["identity"].empty?
23 filter["identity"].each do |identity|
24 identity = Regexp.new(identity.gsub("\/", "")) if identity.match("^/")
26 if identity.is_a?(Regexp)
27 discovered = hosts.grep(identity)
28 elsif hosts.include?(identity)
29 discovered << identity