summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oxidized')
-rw-r--r--lib/oxidized/api/rest.rb12
-rw-r--r--lib/oxidized/nodes.rb6
-rw-r--r--lib/oxidized/output/file.rb15
3 files changed, 33 insertions, 0 deletions
diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb
index 783b445..d1bd7dc 100644
--- a/lib/oxidized/api/rest.rb
+++ b/lib/oxidized/api/rest.rb
@@ -41,6 +41,18 @@ module Oxidized
# /nodes/show/node - returns data about node
when /show\/(.*)/
send res, @nodes.show($1)
+ # /nodes/fetch/<node> or /nodes/fetch/group/<group>/<node> - returns json formatted configuration file for <node>
+ when /fetch\/(.*)/
+ begin
+ if $1.include? '/'
+ group, node = $1.split("/")[1..2]
+ else
+ group, node = 0, $1
+ end
+ send res, @nodes.fetch(node, group)
+ rescue Oxidized::NotSupported => e
+ send res, e
+ end
end
end
end
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb
index e5e87e5..d878d89 100644
--- a/lib/oxidized/nodes.rb
+++ b/lib/oxidized/nodes.rb
@@ -1,5 +1,6 @@
module Oxidized
require 'oxidized/node'
+ class Oxidized::NotSupported < StandardError; end
class Nodes < Array
attr_accessor :source
alias :put :unshift
@@ -26,6 +27,11 @@ module Oxidized
i = find_index node
self[i].serialize if i
end
+ def fetch node, group
+ raise Oxidized::NotSupported unless Oxidized.mgr.output.respond_to? :fetch
+ i = find_index node
+ self[i].output.new.fetch node, group
+ end
def del node
i = find_index node
delete_at i if i
diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb
index 66ad178..2ea2302 100644
--- a/lib/oxidized/output/file.rb
+++ b/lib/oxidized/output/file.rb
@@ -25,5 +25,20 @@ class OxFile < Output
open(file, 'w') { |fh| fh.write data }
end
+
+ 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? File.join(cfg_dir, node) # node configuration file is stored on base directory
+ IO.readlines File.join(cfg_dir, node)
+ else
+ path = Dir.glob File.join(cfg_dir, '**', node) # fetch node in all groups
+ open(path[0], 'r').readlines
+ end
+ end
+ end
+
end
end