diff options
author | nopedial <shafez@ike-2.local> | 2013-10-15 00:13:03 +0200 |
---|---|---|
committer | nopedial <shafez@ike-2.local> | 2013-10-15 00:13:03 +0200 |
commit | e9ec48a85006b481007db28d0b1fb7344f1d1224 (patch) | |
tree | 6af63a41d40e60622d00af83e37e14c983e88d9b /lib/oxidized/output | |
parent | fb4bc13364624bd8d78659de52bb5180c040cb0e (diff) |
enhance fetch support
Diffstat (limited to 'lib/oxidized/output')
-rw-r--r-- | lib/oxidized/output/file.rb | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 8aaae0e..08272a5 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -25,9 +25,28 @@ class OxFile < Output open(file, 'w') { |fh| fh.write data } end - def fetch node - IO.readlines File.join(@cfg[:directory], node) + + def fetch node, group + cfg_dir = @cfg[:directory] + if group != 0 # group is explicitly defined by user + IO.readlines File.join(cfg_dir, group, node) + else + if File.exists?("#{cfg_dir}/#{node}") # node configuration file is stored on base directory + IO.readlines File.join(cfg_dir, node) + else + Dir.foreach(cfg_dir) do |sub_dir| + next if sub_dir == '.' or sub_dir == '..' + if File.directory?("#{cfg_dir}/#{sub_dir}") + files = Dir.entries("#{cfg_dir}/#{sub_dir}") + files.each do |f| + next if File.directory?("#{cfg_dir}/#{sub_dir}/#{f}") or f == '.' or f == '..' + IO.readlines File.join(cfg_dir, sub_dir, f) if f == node # node configuration file found on sub directory + end + end + end + end + end end - + end end |