Legrand / Raritan / Server Technology Xerus™ PDU JSON-RPC API
|
The JSON-RPC Perl bindings require the following perl packages:
In dnf-based Linux distributions the following command will install the required packages:
There are various Perl distributions available for Windows (see http://perl.org/get.html). The bindings were tested with ActiveState Perl (http://www.activestate.com/activeperl/downloads). After installing ActiveState Perl, the required modules can be installed with the following command:
All Xerus devices enforce use of HTTPS when accessing the JSON-RPC service. By default, programs written with this client binding try to verify the authenticity of the server when connecting. This requires a valid SSL certificate to be installed on the device. When trying to connect to a device without a valid SSL certificate the client program will terminate with an error message.
It is possible to disable the SSL certificate verification by setting the 4th parameter of Raritan::RPC::Agent() to 1.
Code:
Code:
Result:
All classes dealing with Xerus™ JSON-RPC communication are located in Perl packages starting with Raritan::RPC
. All named sections in IDL files (module
, interface
and enumeration
) provide a scope for their included identifiers and are added as further components to the Perl package name.
IDL interfaces are mapped to Perl proxy classes which provide all methods defined by the IDL interface and its bases. Perl methods require the same number of scalar arguments as defined in the IDL signature. Simple types like integers, strings or enumerations are passed by scalar value; structures, vectors and maps are passed by reference. Output parameters are passed as references to a scalar variable which will be modified to point to the returned value. If the method is declared to have a non-void return type the Perl method will return a single scalar value.
Examples:
IDL structures are mapped as scalar references to Perl hashes. Each element of the structure results in a hash entry whose key is the element identifier and whose value is a Perl scalar. When passing a structure to a method call addtional hash entries are ignored.
Example:
Enumerated values are referenced by their fully-qualified name:
Vectors are mapped as scalar references to Perl lists. Each list entry must be a scalar.
Maps are mapped as scalar references to Perl hashes:
In case of error conditions during a proxy method call or the createProxy
funtion exceptions will be thrown. They can be caught using the try
statement from the Perl::Error
module.
The following exceptions are defined:
Raritan::RPC::HttpException
An error occurred during HTTP communication, e.g. in case the connection was refused or the authentication failed. Please check the agent URL, the resource ID and your authentication credentials.
Raritan::RPC::JsonRpcSyntaxException
The response from the server was not a valid JSON object. Please check the agent URL and the resource ID.
Raritan::RPC::JsonRpcErrorException
The method call failed. This should not happen under normal circumstances and indicates a problem on the device.
Example for catching an exception:
Creates a new agent.
Parameters:
If username or password are omitted, it is necessary to call either set_auth_basic() or set_auth_token() before the first request.
This method enables HTTP basic authentication using username and password.
Parameters:
This method enables HTTP authentication using a session token. A session token can be obtained by calling the newSession method of the session.SessionManager interface.
Parameters:
Returns the current timeout and optionally sets a new request timeout.
Parameters:
Returns:
Creates a new proxy object for the given resource id.
This method will query the type information for the specified resource ID and create a proxy object which provides all methods defined in the IDL definition.
When connecting to very old firmware versions (PDU 2.2 and earlier) the type information of a resource ID cannot be queried. In this case the $basetype argument is required.
Parameters:
Returns:
Enables request tracing. When verbose mode is enabled all JSON-RPC requests and responses will be echoed to the console.
Parameters:
true
to enable verbose mode