Cisco Prime Infrastructure API
Prime Infrastructure API Documentation

Scripting (Ruby)

When using Ruby, there are many options for what client to use. The one demonstrated below uses the rest-client gem.

			require 'rest-client'
			#!/usr/bin/env ruby
			require "rubygems"
			require 'rest_client'
			require 'json'
			
			#$base_uri = 'https://192.168.138.154/webacs/api/v1/'
			$base_uri = 'https://ncs-xmp-build-2/webacs/api/v1/'
			$ap ='data/AccessPoints'
			#$user, $pass = 'prime', 'Prime123$'
			$user, $pass = 'root', 'Public123'
			
			# wrap resource access
			class NcsResource 
				def initialize(url, query, user, password)
					@resource = RestClient::Resource.new url+URI.encode(query), :user => user, :password => password
					@options =  {:accept => 'application/json' };
				end	
				def get()
					 res = @resource.get  @options
					 if (res.code != 200) 
					 	raise "Bad response received:",res.to_str
					 	exit
					 end
					last_res = JSON.parse(res)
					return last_res;
				end
			end
			 
			# Get some APs..
            apRes = NcsResource.new $base_uri + $ap, '?.full=true &.maxResults=50',$user, $pass;
    		
    		aps = apRes.get();
			#puts( JSON.pretty_generate(aps))
			
			aps['queryResponse']['entity'].each do | ent| 
			#   puts( JSON.pretty_generate(ent))
			   ap = ent['accessPointsDTO']
			   print "-------------------\n"
			   print "Access Point: #{ap['name']}\n"
			   print "MacAddress: #{ap['macAddress']}\n"
			   print "Model:  #{ap['model']}\n"
			   print "Serial Number: #{ap['serialNumber']} #{ap['clientClount']}\n"
			   print "Client Count: #{ap['clientCount']}\n"
			end
    		

For full documentation on the rest-client gem, please visit http://rubydoc.info/gems/rest-client/1.6.1