Problem
What is the syntax for ectool getJobSummaries with a greater than date time stamp filter?
We want to query using ectool for all jobs started in the last 30 minutes.
Solution
Please note that on our github site, there is a utility called "ecfind" which has a command-line version of the findObjects API that could be useful for this type of query - note that tools on our github site are supported by their creators, they are not officially supported by the Commander Support team :
The following sample code was provided by one our Professional Services Engineers as a courtesy, and can be used to return jobs run in the last 30 minutes
############################################################################# # # Copyright 2013-2015 Electric-Cloud Inc. # ############################################################################# use strict; use English; use ElectricCommander; use Data::Dumper; use DateTime; $| = 1; my $DEBUG=0; # Create a single instance of the Perl access to ElectricCommander my $ec = new ElectricCommander({'format' => "json"}); # Check for the OS Type my $osIsWindows = $^O =~ /MSWin/; my $timeLimit = 30; # 30 minutes ago # create filterList my @filterList; # only finished jobs push (@filterList, {"propertyName" => "status", "operator" => "equals", "operand1" => "completed"}); # older than push (@filterList, {"propertyName" => "createTime", "operator" => "greaterThan", "operand1" => calculateDate($timeLimit)}); my ($success, $xPath) = InvokeCommander("SuppressLog", "findObjects", "job", {filter => \@filterList}); # Loop over all returned jobs my @nodeset=$xPath->findnodes('//job'); my $nbObjs=scalar(@nodeset); printf("Search Status: %s.\n%s objects returned.\n", $success?"success":"failure", $nbObjs); JOB: foreach my $node (@nodeset) { my $jobId = $node->{jobId}; my $jobName = $node->{jobName}; print "Job: $jobName ($jobId)\n"; } ############################################################################# # # Calculate the Date based on now and the number of minutes # ############################################################################# sub calculateDate { my $nbMin=shift; return DateTime->now()->subtract(minutes => $nbMin)->iso8601() . ".000Z"; } ############################################################################# # # Invoke a API call # ############################################################################# sub InvokeCommander { my $optionFlags = shift; my $commanderFunction = shift; my $result; my $success = 1; my $errMsg; my $errCode; my $bSuppressLog = $optionFlags =~ /SuppressLog/i; my $bSuppressResult = $bSuppressLog || $optionFlags =~ /SuppressResult/i; my $bIgnoreError = $optionFlags =~ /IgnoreError/i; # Run the command # print "Request to Commander: $commanderFunction\n" unless ($bSuppressLog); $ec->abortOnError(0) if $bIgnoreError; $result = $ec->$commanderFunction(@_); $ec->abortOnError(1) if $bIgnoreError; # Check for error return if (defined ($result->{responses}->[0]->{error})) { $errCode=$result->{responses}->[0]->{error}->{code}; $errMsg=$result->{responses}->[0]->{error}->{message}; } if ($errMsg ne "") { $success = 0; } if ($result) { print "Return data from Commander:\n" . Dumper($result) . "\n" unless $bSuppressResult; } # Return the result return ($success, $result, $errMsg, $errCode); }
This code is provided as a starting point for your work, please modify it as you see fit. If you find any errors in the code, please feel free to send us your fixes and we will incorporate them to this article.