summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2013-10-24 02:18:00 -0700
committerytti <saku@ytti.fi>2013-10-24 02:18:00 -0700
commit1b4cf651d5b7e9e032a7bc0636c569d0419f2ded (patch)
treec94da76aee2709a2808a113115fa34b188a5a34c
parentd7d490077ce16e76367773f5a5fe8bca4f84f366 (diff)
parentfeba4c2b9e0faeb40cad32f16d7b024a2d4327ae (diff)
Merge pull request #7 from nopedial/master
finalize fetch API call
-rw-r--r--README.md3
-rw-r--r--lib/oxidized/api/rest.rb8
-rw-r--r--lib/oxidized/nodes.rb6
-rw-r--r--lib/oxidized/output/file.rb17
-rw-r--r--oxidized.gemspec2
5 files changed, 27 insertions, 9 deletions
diff --git a/README.md b/README.md
index ea521fc..15da1fe 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,11 @@
# Pitch
* automatically adds/removes threads to meet configured retrieval interval
* restful API to move node immediately to head-of-queue
- * syslog udp+file example to catch config changg event (ios/junos) and trigger config fetch
+ * syslog udp+file example to catch config change event (ios/junos) and trigger config fetch
* will signal ios/junos user who made change, which output module can (git does) use
* 'git blame' will show for each line who and when the change was made
* restful API to reload list of nodes (GET /nodes/reload)
+ * restful API to fetch configurations (/nodes/fetch/[NODE] or /nodes/fetch/group/[NODE])
# Install
* early days, but try:
diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb
index d876917..d1bd7dc 100644
--- a/lib/oxidized/api/rest.rb
+++ b/lib/oxidized/api/rest.rb
@@ -41,9 +41,15 @@ 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
- send res, @nodes.fetch($1)
+ 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
diff --git a/lib/oxidized/nodes.rb b/lib/oxidized/nodes.rb
index dcebe08..d878d89 100644
--- a/lib/oxidized/nodes.rb
+++ b/lib/oxidized/nodes.rb
@@ -27,10 +27,10 @@ module Oxidized
i = find_index node
self[i].serialize if i
end
- def fetch node
- i = find_index node
+ def fetch node, group
raise Oxidized::NotSupported unless Oxidized.mgr.output.respond_to? :fetch
- self[i].output.new.fetch node
+ i = find_index node
+ self[i].output.new.fetch node, group
end
def del node
i = find_index node
diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb
index 8aaae0e..2ea2302 100644
--- a/lib/oxidized/output/file.rb
+++ b/lib/oxidized/output/file.rb
@@ -25,9 +25,20 @@ 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? 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
diff --git a/oxidized.gemspec b/oxidized.gemspec
index 38a2e41..53e12c9 100644
--- a/oxidized.gemspec
+++ b/oxidized.gemspec
@@ -1,6 +1,6 @@
Gem::Specification.new do |s|
s.name = 'oxidized'
- s.version = '0.0.14'
+ s.version = '0.0.15'
s.platform = Gem::Platform::RUBY
s.authors = [ 'Saku Ytti' ]
s.email = %w( saku@ytti.fi )