Example Perl Script - List Information and Shutdown
Here is an example Perl script which uses the API to print some information about the gateway and shut it down. The completed script (with shutdown code commented out for safety) is available as an attachment on this page.
- 1 Requirements
- 2 Code
Requirements
Perl
OpenSSL
Perl Modules
LWP::UserAgent
Crypt::SSLeay
HTTP::Cookies
JSON or JSON::XS
Code
Download the full source code:
Start a new perl script.
#!/usr/bin/perl  use strict; use HTTP::Cookies; use LWP::UserAgent; use Data::Dumper; use JSON;
Create a new LWP::UserAgent object, and disable SSL certificate hostname verification, which is on by default in recent versions. Create a new HTTP::Cookies object and tell your user agent about it.
# Must set this *before* creation of LWP::UserAgent object $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0; my $ua = new LWP::UserAgent; Â # Sometimes both this and the VERIFY_HOSTNAME environment variable are required $ua->ssl_opts({'verify_hostname' => 0}); Â my $cookies = new HTTP::Cookies(); $ua->cookie_jar($cookies);
Configure the script for your particular gateway
my $GATEWAY_IP = 'CHANGEME'; my $USERNAME = 'admin'; my $PASSWORD = 'admin';
Log in to your gateway. This will save your authentication cookies in your HTTP::Cookies object so that subsequent calls will be allowed.
Build a call to the gateway.list method to get information about the gateway.
Shut the gateway down remotely using system_shutdown.save.