This article explains how to use Stingray's REST Control API using the excellent rest-client Ruby module.
You can install rest-client with gem:
Windows: gem install rest-client Linux: sudo gem install rest-client
The REST API gives you access to the Stingray Configuration, presented in the form of resources. The format of the data exchanged using the Stingray RESTful API will depend on the type of resource being accessed:
Working with JSON and Ruby
The json module provides functions for JSON serializing and deserializing. If this is not already installed on your system it can be installed with gem:
Windows: gem install json Linux: sudo gem install json
To take a Ruby data structure and serialize it into JSON format use JSON.generate() and to deserialize a JSON formatted string into a Ruby data structure use JSON.parse().
Working with a RESTful API and Ruby
To make the programming easier, the program examples that follow utilize the rest-client package as the REST client. There are methods for GET, PUT and DELETE and each must include an authorization header, replacing <userid>, <password>, <url> and <data> with the appropriate values:
auth = 'Basic ' + Base64.encode64('<useid>:<password>') response = RestClient.get(<url>, {:authorization => auth}) response = RestClient.put(<url>, JSON.generate(<data>), {:content_type => :json, :authorization => auth}) response = RestClient.delete(<url>, {:authorization => auth})
The URL for Stingray RESTful API will be of the form:
https://<STM hostname or IP>:9070/api/tm/1.0/config/active/
followed by a resource type or a resource type and resource, so for example to get a list of all the pools from the Stingray instance, stingray.example.com, it would be:
https://stingray.example.com:9070/api/tm/1.0/config/active/pools
And to get the configuration information for the pool, “testpool” the URL would be:
https://stingray.example.com:9070/api/tm/1.0/config/active/pools/testpool
Data Structures
JSON responses from a GET or PUT are deserialized into a Ruby dictionary that always contains one element. The key to this element will be:
Please see Feature Brief: Traffic Manager's RESTful Control API for examples of these data structures and something like the Chrome REST Console can be used to see what the actual data looks like.
Read More