3 # A very simple demonstration of writing a REST server
4 # for Simple RPC clients that takes requests over HTTP
5 # and returns results as JSON structures.
12 include MCollective::RPC
14 # http://<your box>/mcollective/rpctest/echo/msg=hello%20world
16 # Creates a new Simple RPC client for the 'rpctest' agent, calls
17 # the echo action with a message 'hello world'.
19 # Returns all the answers as a JSON data block
20 get '/mcollective/:agent/:action/*' do
21 mc = rpcclient(params[:agent])
26 # split up the wildcard params into key=val pairs and
27 # build the arguments hash
28 params[:splat].each do |arg|
29 arguments[$1.to_sym] = $2 if arg =~ /^(.+?)=(.+)$/
32 JSON.dump(mc.send(params[:action], arguments).map{|r| r.results})