From a85509f5e288c9ccc70400f2ce93842e57a1af23 Mon Sep 17 00:00:00 2001 From: nopedial Date: Sat, 26 Oct 2013 00:16:19 +0200 Subject: add fetch API to git output --- lib/oxidized/output/git.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/oxidized/output') diff --git a/lib/oxidized/output/git.rb b/lib/oxidized/output/git.rb index 202893c..f23b35a 100644 --- a/lib/oxidized/output/git.rb +++ b/lib/oxidized/output/git.rb @@ -37,6 +37,15 @@ class Git < Output end end + def fetch node, group + begin + repo = Repo.new(@cfg[:repo]) + (repo.tree / node).data + rescue + 'node not found' + end + end + private def update_repo repo, file, data, msg, actor -- cgit v1.2.3 From 52c5c00326d723c4649f862dde66fdaf331f7250 Mon Sep 17 00:00:00 2001 From: nopedial Date: Sat, 26 Oct 2013 11:23:48 +0200 Subject: cleanup ascii API output --- lib/oxidized/api/rest.rb | 8 ++++---- lib/oxidized/output/file.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/oxidized/output') diff --git a/lib/oxidized/api/rest.rb b/lib/oxidized/api/rest.rb index f1a7ef5..1a426f5 100644 --- a/lib/oxidized/api/rest.rb +++ b/lib/oxidized/api/rest.rb @@ -4,9 +4,9 @@ module Oxidized module API class Rest module Helpers - def send res, json, msg='OK', status=200 + def send res, msg='OK', ascii=false, status=200 res.body = msg - if not json + if ascii msg = {:result => msg} res['Content-Type'] = 'application/json' res.status = status @@ -52,10 +52,10 @@ module Oxidized else group, node = 0, $1 end - json = if node[-4..-1] == '.txt' + ascii = if node[-4..-1] == '.txt' node = node[0..-5] end - send res, json, @nodes.fetch(node, group) + send res, @nodes.fetch(node, group), ascii rescue Oxidized::NotSupported => e send res, e end diff --git a/lib/oxidized/output/file.rb b/lib/oxidized/output/file.rb index 2ea2302..da778ff 100644 --- a/lib/oxidized/output/file.rb +++ b/lib/oxidized/output/file.rb @@ -28,7 +28,7 @@ class OxFile < Output def fetch node, group cfg_dir = @cfg[:directory] - if group != 0 # group is explicitly defined by user + if group # 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 -- cgit v1.2.3