oxidized-web icon indicating copy to clipboard operation
oxidized-web copied to clipboard

conf_search JSON output

Open Alexanderis opened this issue 8 years ago • 9 comments

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?

Alexanderis avatar Sep 29 '16 16:09 Alexanderis

It should produce json if you add .json to the query

ytti avatar Sep 29 '16 18:09 ytti

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 &#x27;&#x2F;nodes&#x2F;conf_search.json&#x27; do
    &quot;Hello World&quot;
  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"}]

Alexanderis avatar Sep 29 '16 19:09 Alexanderis

We're missing .?:format? in the route, can you check if adding that fixes it?

ytti avatar Sep 29 '16 19:09 ytti

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/

Alexanderis avatar Sep 29 '16 19:09 Alexanderis

grumble, you probably need to add @data = @nodes_match before out is called

ytti avatar Sep 29 '16 19:09 ytti

:+1: wohoooo!!!! Works as advertised!! Thanks!

Alexanderis avatar Sep 29 '16 19:09 Alexanderis

@FlorianDoublet I believe you wrote this? Want to refactor the posts which do not support JSON?

ytti avatar Sep 29 '16 19:09 ytti

@ytti that's right I wrote this. But I don't really have the time for the moment to refactor it, sorry :/

FlorianDoublet avatar Sep 30 '16 14:09 FlorianDoublet

no worries, thanks.

ytti avatar Sep 30 '16 15:09 ytti