- This topic has 2 replies, 2 voices, and was last updated November 13, 2018 by Ryan S.
API Perl Script Debugging help
-
Han WJune 6, 2018 02:34:41 PM
Just Start Perl API Program Yesterday
Could Someone help me?
Weird Error shows and couldn’t figure it out.
I have tried to directly ask to ZVM server and it worked well.
Although this script do not include login procedure(I could not figured it out yet )Thank you in advance.
———–Error————-
perl ZertoRetrieveAllvpgInfo.pl
syntax error at ZertoRetrieveAllvpgInfo.pl line 51, near “else”
Global symbol “$num_results_from_last_query” requires explicit package name at ZertoRetrieveAllvpgInfo.pl line 58.
Global symbol “$count” requires explicit package name at ZertoRetrieveAllvpgInfo.pl line 58.
syntax error at ZertoRetrieveAllvpgInfo.pl line 58, near “);”
syntax error at ZertoRetrieveAllvpgInfo.pl line 68, near “}”
Execution of ZertoRetrieveAllvpgInfo.pl aborted due to compilation errors (#1)
(F) Probably means you had a syntax error. Common reasons include:A keyword is misspelled.
A semicolon is missing.
A comma is missing.
An opening or closing parenthesis is missing.
An opening or closing brace is missing.
A closing quote is missing.Often there will be another error message associated with the syntax
error giving more information. (Sometimes it helps to turn on -w.)
The error message itself often tells you where it was in the line when
it decided to give up. Sometimes the actual error is several tokens
before this, because Perl is good at understanding random input.
Occasionally the line number may be misleading, and once in a blue moon
the only way to figure out what’s triggering the error is to call
perl -c repeatedly, chopping away half the program each time to see
if the error went away. Sort of the cybernetic version of 20 questions.Uncaught exception from user code:
syntax error at ZertoRetrieveAllvpgInfo.pl line 51, near “else”
Global symbol “$num_results_from_last_query” requires explicit package name at ZertoRetrieveAllvpgInfo.pl line 58.
Global symbol “$count” requires explicit package name at ZertoRetrieveAllvpgInfo.pl line 58.
syntax error at ZertoRetrieveAllvpgInfo.pl line 58, near “);”
syntax error at ZertoRetrieveAllvpgInfo.pl line 68, near “}”
Execution of ZertoRetrieveAllvpgInfo.pl aborted due to compilation errors.
———————
Source Code Below
————————-
#!/usr/bin/perl -w
use strict;
use diagnostics;
use LWP::UserAgent;
use JSON;
main();sub main {
my $zvm = “x.x.x.10”;
my $startIndex = 0;
my $count = 500;
my $url;
my $last_timestamp = “”;
my $json = new JSON;
my $userAgent = new LWP::UserAgent;
my $num_results_from_last_query = 0;
my $fromTimeString = “2015-01-01”;
my $toTimeString = “2020-01-01″;
do {
$url=”https://$zvm:9669/ZvmService/ResourcesReport/getSamples?fromTimeString=$fromTimeString&toTimeString=$toTimeString&startIndex=$startIndex&count=$count”;
print “Retrieving $url\n”;my $req = HTTP::Request->new(GET=>$url);
$req->header(Accept=>’application/json’);
my $res = $userAgent->request($req);
if ($res->is_success) {
my @json_array = @{$json->decode($res->content)};
$num_results_from_last_query = @json_array;
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”;
}
}
$startIndex += $count;else {
print “Error: “, $res->status_line, “\n”;
last;
}
} while ($num_results_from_last_query == $count);
}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;
}Hi Han,
I think a lot of our guys internally are more familiar with PowerShell, but I have presented this to them and will respond back when I hear anything from them
Han,
After asking around, someone mentioned that this errors look like something that might occur when using ‘strict’ and the Zerto script doesn’t. I’d try removing the ‘use strict’.
Hope this helps
The forum ‘Scripting and APIs’ is closed to new topics and replies.