oxidized-web
oxidized-web copied to clipboard
conf_search JSON output
Hi team,
Quick question about the following piece of code from oxidized-web-0.7.1/lib/oxidized/web/webapp.rb
post '/nodes/conf_search' do @to_research = Regexp.new params[:search_in_conf_textbox] nodes_list = nodes.list.map @nodes_match = [] nodes_list.each do |n| node, @json = route_parse n[:name] config = nodes.fetch node, n[:group] if config[@to_research] @nodes_match.push({ node: n[:name], full_name: n[:full_name] }) end end out :conf_search end
From what I understand the @nodes_match is a JSON structure and its parsed via conf_search.haml to create the nice table.
If I do a "curl -F search_in_conf_textbox=some_string oxidized.host/nodes/conf_search" I get the full page.
Is there a way to get only the JSON result of that query?
It should produce json if you add .json to the query
I tried this versions when doing the query but they error out:
curl -F search_in_conf_textbox=cisco http://oxidized.arahant.net/nodes/conf_search.json
curl -F search_in_conf_textbox=cisco http://oxidized.arahant.net/nodes.json/conf_search
Try this:
<pre># in webapp.rb
class Oxidized::API::WebApp
post '/nodes/conf_search.json' do
"Hello World"
end
end
When I do curl -F search_in_conf_textbox=cisco http://oxidized.arahant.net/nodes/conf_search
I get the full HTML page.
What I'd like is the json with only the nodes that match the conf_search query like [{"name":"192.168.88.233", "href":"/node/fetch/192.168.88.233"}, {"name":"192.168.88.230", "href":"/node/fetch/192.168.88.230"}, {"name":"192.168.88.231", "href":"/node/fetch/192.168.88.231"}]
We're missing .?:format?
in the route, can you check if adding that fixes it?
Added the post '/nodes/conf_search.?:format?' do
and it doesn't error out anymore but it prints a "null" result if I try the query/
grumble, you probably need to add @data = @nodes_match
before out
is called
:+1: wohoooo!!!! Works as advertised!! Thanks!
@FlorianDoublet I believe you wrote this? Want to refactor the posts which do not support JSON?
@ytti that's right I wrote this. But I don't really have the time for the moment to refactor it, sorry :/
no worries, thanks.