Zerto Virtual Replication APIs : Resources Report API : Perl Code Example: Retrieving the First 100 Records
  
Perl Code Example: Retrieving the First 100 Records
The following example uses Perl and Json1 and can be run on both Windows and Linux operating systems.
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
use JSON;
main();
sub main {
  my $url = "https://zvm_ip:port/ZvmService/ResourcesReport/getSamples?fromTimeString=2014-01-01&toTimeString=2015-01-01 23:59:59&startIndex=0&count=100";
  print "Retrieving $url\n";
 
  my $userAgent = LWP::UserAgent->new;
  my $req = HTTP::Request->new(GET => $url);
  $req->header(Accept => 'application/json');
  my $res = $userAgent->request($req);
  if ($res->is_success) {
    my $json = new JSON;
    my @json_array = @{$json->decode($res->content)};
    my $last_timestamp = "";
    for my $elem (@json_array) {
      my $timestamp = jsonDateToString($elem->{Timestamp});
      if ($timestamp ne $last_timestamp) {
        print "\nTime: $timestamp\n";
        $last_timestamp = $timestamp;
      }
      print "VPG: $elem->{VpgName}, VM: $elem->{VmName}, Bandwidth (Bps): $elem->{BandwidthInBytes}\n";
    }
  } else {
    print $res->status_line, "\n";
  }
}
sub jsonDateToString($) {
  my $json_date = shift;
  if ($json_date =~ m{ \b (\d+) \b ([+-]\d\d\d\d\b)? }x ) {
    my ( $epoch_milliseconds, $time_zone ) = ( $1, $2 );
    return localtime($epoch_milliseconds / 1000);
  }
  return $json_date;
}
The following output is based on each VPG containing only one virtual machine.
Retrieving https://zvm_ip:port/ZvmService/ResourcesReport/getSamples?fromTimeString=2013-06-20&toTimeString=2013-06-22 23:59:59&startIndex=0&count=100
 
Time: Thu Jun 20 01:00:00 2013
VPG: HR Dallas, VM: HR Dallas, Bandwidth (Bps): 639.437
VPG: HR NY, VM: HR New York, Bandwidth (Bps): 206.335
VPG: HR London, VM: HR London, Bandwidth (Bps): 1261.204
VPG: Reporting, VM: NY Reporting, Bandwidth (Bps): 2998.503
VPG: BO Recs, VM: Reconciliation, Bandwidth (Bps): 7.988
VPG: FX Report, VM: FX, Bandwidth (Bps): 1397.885
 
Time: Fri Jun 21 01:00:00 2013
VPG: HR Dallas, VM: HR Dallas, Bandwidth (Bps): 833.524
VPG: HR NY, VM: HR New York, Bandwidth (Bps): 183.923
VPG: HR London, VM: HR London, Bandwidth (Bps): 1282.578
VPG: Reporting, VM: NY Reporting, Bandwidth (Bps): 4429.341
VPG: BO Recs, VM: Reconciliation, Bandwidth (Bps): 7.994
VPG: DC Zertolab.local, VM: DC Zertolab.local, Bandwidth (Bps): 872.078
 
Time: Sat Jun 22 01:00:00 2013
VPG: HR Dallas, VM: HR Dallas, Bandwidth (Bps): 870.926
VPG: HR NY, VM: HR New York, Bandwidth (Bps): 218.696
VPG: HR London, VM: HR London, Bandwidth (Bps): 1245.913
VPG: Reporting, VM: NY Reporting, Bandwidth (Bps): 3022.375
VPG: BO Recs, VM: Reconciliation, Bandwidth (Bps): 7.994
VPG: FX Report, VM: FX, Bandwidth (Bps): 942.535
Code Notes
The example assumes Json and Crypt::SSLeay Perl packages are installed.2
The API returns the first 100 records.
The code uses the default SSL_VERIFY_NONE verification mode for clients. The most recent Perl versions will still run this code although they will report the verification as an error.
jsonDateToString($) converts the date from its epoch format to a readable date.

1 If you prefer to use XML, you can convert the Json to XML.

2 On a Windows operating system, ActiveState Perl was used.