Raritan EMX JSON-RPC API
Perl JSON-RPC Client Binding

Pre-Requirements

Raritan's JSON-RPC Perl bindings require the following perl packages:

Linux

In yum-based Linux distributions the following command will install the required packages:

1 yum install "perl(LWP::Protocol::https)" "perl(LWP::UserAgent)" \
2  "perl(HTTP::Request::Common)" "perl(JSON)" \
3  "perl(JSON::RPC::Common::Marshal::HTTP)" "perl(Error)" \
4  "perl(Data::Dumper)" "perl(parent)"

Windows

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:

1 ppm install LWP::Protocol::https LWP::UserAgent HTTP::Request::Common \
2  JSON JSON::RPC::Common::Marshal::HTTP Error Data::Dumper parent

Examples

Getting device information:

Code:

1 use Raritan::RPC;
2 use Data::Dumper;
3 
4 my $agent = new Raritan::RPC::Agent('https://my-emx.example.com', 'admin', 'raritan');
5 my $emx = $agent->createProxy('/model/emd');
6 my $metadata = $emx->getMetaData();
7 print Dumper($metadata);

Result:

1 $VAR1 = {
2  'hwRevision' => '0x01',
3  'ctrlBoardSerial' => 'PNW1691120',
4  'fwRevision' => '2.2.0.5-0',
5  'nameplate' => {
6  'model' => 'EMX2-888-v0',
7  'imageFileURL' => '',
8  'manufacturer' => 'Raritan',
9  'rating' => {
10  'voltage' => '100-240V',
11  'current' => '0.7A',
12  'power' => '70VA',
13  'frequency' => '50/60Hz'
14  },
15  'partNumber' => 'emx2-888',
16  'serialNumber' => 'PH81234567'
17  },
18  'macAddress' => 'fe:00:10:42:00:67'
19  };

Configuring the SNMP agent:

1 use Raritan::RPC;
2 
3 my $agent = new Raritan::RPC::Agent('https://my-device.example.com', 'admin', 'raritan');
4 my $snmp_proxy = $agent->createProxy('/snmp');
5 my $config = $snmp_proxy->getConfiguration();
6 $config->{v2enable} = 0;
7 $config->{readComm} = 'public';
8 $config->{writeComm} = 'private';
9 $snmp_proxy->setConfiguration($config);

IDL-to-Perl Mapping

IDL Modules and Perl Package Names

All classes dealing with Raritan 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.

Interfaces and Methods

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:

1 # no parameters, no return value
2 $firmware->reboot();
3 
4 # two input parameters, integer return value
5 $ret = $user_manager->createAccount('newuser', 'newpassword');
6 
7 # one output parameter, integer return value
8 my $results;
9 $ret = $diagnostics->listTcpConnections(\$results);

Structures

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:

1 $ssh_settings = {
2  'allowPasswordAuth' => 1,
3  'allowPublicKeyAuth' => 0
4 };
5 $security->setSSHSettings($ssh_settings);

Enumerations

Enumerated values are referenced by their fully-qualified name:

1 $ret = $outlet->setPowerState(Raritan::RPC::pdumodel::Outlet::PowerState::PS_ON);

Vectors

Vectors are mapped as scalar references to Perl lists. Each list entry must be a scalar.

1 $recipients = [ 'somebody@invalid.com', 'somebody.else@invalid.com' ];
2 $smtp->testConfiguration($cfg, $recipients);

Maps

Maps are mapped as scalar references to Perl hashes:

1 $priorities = {
2  'important_client' => Raritan::RPC::webcam::Priority::VERY_HIGH,
3  'other_client' => Raritan::RPC::webcam::Priority::LOW
4 };
5 $ret = $webcam->setClientTypePriorities($priorities);

Exceptions

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:

Example for catching an exception:

1 use Raritan::RPC;
2 use Error qw(:try);
3 
4 try {
5  print "Querying firmware version ... ";
6  my $agent = new Raritan::RPC::Agent('https://my-device.example.com', 'admin', 'raritan');
7  my $firmware_proxy = $agent->createProxy('/firmware');
8  my $version = $firmware_proxy->getVersion();
9  print "Success\n";
10  print "Firmware version: $version\n";
11 } catch Raritan::RPC::HttpException with {
12  my $e = shift;
13  print "ERROR: ", $e;
14 };

Raritan::RPC::Agent Method Reference

Constructor: new Raritan::RPC::Agent($url, $user, $password)

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.

set_auth_basic($user, $password)

This method enables HTTP basic authentication using username and password.

Parameters:

set_auth_token($token)

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:

timeout($seconds)

Returns the current timeout and optionally sets a new request timeout.

Parameters:

Returns:

createProxy($rid, $basetype)

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 (PX2 2.2 and earlier, EMX 2.0 and earlier) the type information of a resource ID cannot be queried. In this case the $basetype argument is required.

Parameters:

Returns:

set_verbose($verbose)

Enables request tracing. When verbose mode is enabled all JSON-RPC requests and responses will be echoed to the console.

Parameters: