Module: Zenoss::RESTAPI

Included in:
Connection
Defined in:
lib/zenoss/restapi.rb

Instance Method Summary collapse

Instance Method Details

#custom_rest(dev_path, req_path, callback_func = nil, callback_attr = nil) ⇒ String

Call a custom Zope method to work around some issues of unsupported or bad behaving REST methods.

Parameters:

  • req_path (String)

    the request path of the REST method ( as if it wasn’t misbehaving ) @example req_path

    getRRDValues?dsnames=['ProcessorTotalUserTime_ProcessorTotalUserTime','MemoryPagesOutputSec_MemoryPagesOutputSec']
    
  • callback_func (String) (defaults to: nil)

    the name of the function to be called on the returned object before giving it back to Ruby

  • callback_attr (String) (defaults to: nil)

    the name of the attribute to fetch on the returned object before giving it back to Ruby

Returns:

  • (String)

    the response body of the REST call

See Also:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/zenoss/restapi.rb', line 43

def custom_rest(dev_path, req_path, callback_func = nil, callback_attr=nil)
  puts "ORIGINAL: #{req_path}" if $DEBUG
  meth,args = req_path.split('?')
  meth = "callZenossMethod?methodName=#{meth}"
  unless args.nil?
    meth << '&args=['
    # Remove the named parameters because we can't dynamically call named parameters in Python.
    # This method uses positional parameters via the passed Array (Python List).
    meth << args.split('&').inject('') do |parms,arg|
      arg.gsub!(/'/, "'''") # This may cause problems if the passed argument is already triple quoted.
      parms << '===' unless parms.empty?
      parms << arg.split('=').last
    end
    meth << ']'
  end
  meth << "&filterFunc=#{callback_func}" unless callback_func.nil?
  meth << "&filterAttr=#{callback_attr}" unless callback_attr.nil?
  meth = "#{URI.encode(dev_path)}/#{URI.encode(meth)}"
  puts "METHOD: #{meth}" if $DEBUG
  rest(meth)
end

#rest(req_path) ⇒ String

Prepend the appropriate path and call the REST method on the URL set with Zenoss#uri

Parameters:

  • req_path (String)

    the request path of the REST method

Returns:

  • (String)

    the response body of the REST call



28
29
30
31
# File 'lib/zenoss/restapi.rb', line 28

def rest(req_path)
  resp = @httpcli.get "#{@zenoss_uri}#{req_path}"
  parse_rest(resp)
end