I use Perl and LWP::UserAgent to good effect here.
!/usr/bin/perl
use LWP::UserAgent;
use Data::Dumper;
use JSON;
use Time::HiRes;
if ( scalar(@ARGV) != 1 ) {
print "Usage: $0 JazzURI, JazzUser, JazzPass\n";
exit -1;
}
my ($JazzURI) = @ARGV;
my($JazzUser)="someid"
my($JazzPass) = "passw0rd";
my $Browser = LWP::UserAgent->new;
$Browser->timeout(15);
$Browser->cookie_jar({ file => "$ENV{HOME}/.kcookies.txt" });
$Browser->default_header('Accept' => "text/json");
push @{ $Browser->requests_redirectable }, 'POST';
# Test the connection to CLM
my ( $BeginTime ) = Time::HiRes::time();
$Response = $Browser->post( $JazzURI );
my ( $EndTime ) = Time::HiRes::time();
if ( ! $Response->is_success ) {
$date=date
; chomp($date);
print "$date|Connecting to $JazzURI FAILED!\n";
exit -1;
} else {
# my($printString) = sprintf("%s%.2f%s", "Connection to $JazzURI completed in ", $EndTime - $BeginTime, " Seconds.\n");
# print $printString;
}
# Test the Authetication to CLM
my ( $BeginTime ) = Time::HiRes::time();
$Response = $Browser->post( $JazzURI . "/j_security_check", [ j_username => $JazzUser, j_password => $JazzPass ], );
my ( $EndTime ) = Time::HiRes::time();
if ( $Response->{"headers"}{"x-com-ibm-team-repository-web-auth-msg"} eq "authfailed" ) {
print "Authenticating to $JazzURI FAILED!\n";
exit -1;
} else {
# print Dumper($Response);
$d_cookies=$Response->{_request}->{_headers}->{cookie};
$jsess=get_cookie("JSESSIONID",$d_cookies);
$Browser->default_header('X-Jazz-CSRF-Prevent'=>$jsess);
#my($printString) = sprintf("%s%.2f%s%s", "Authentication to $JazzURI completed in ", $EndTime - $BeginTime, " Seconds.\n",$jsess);
#print STDERR $printString;
}
# Test the Database connection status to CLM
my ( $BeginTime ) = Time::HiRes::time();
$Response = $Browser->get( $JazzURI . "/service/com.ibm.team.repository.service.internal.IServerStatusRestService/ActiveServiceInfo");
my ( $EndTime ) = Time::HiRes::time();
my($json) = new JSON;
my($jsonResponse) = $json->decode($Response->content);
# print Dumper($jsonResponse);
# print $json->pretty->encode($jsonResponse);
if ( !exists( $jsonResponse->{"soapenv:Body"}{response}{returnValue}{value}{currentTime} )) {
exit -1;
} else {
$current_time=$jsonResponse->{"soapenv:Body"}{response}{returnValue}{value}{currentTime}/1000;
$ct = scalar localtime($current_time);
$services=$jsonResponse->{"soapenv:Body"}{response}{returnValue}{value}{services};
for ($i=0; exists($services->[$i]); $i++) {
$start_time=$services->[$i]{startTime}/1000;
$st = scalar localtime ($start_time);
$et = int($current_time - $start_time);
print "$ct|$services->[$i]{service}|$services->[$i]{userId}|$services->[$i]{method}|$st|$et\n";
#if ($services->[$i]{method} =~ m/postRenderReport/) {
# print $services->[$i]{stacktrace};
#}
}
# my($printString) = sprintf("%s|%s|%s|%s|%s|%s|%s\n",$url,$sversion,$ut,$tm,$fm,$mm,$db);
# print $printString;
exit 0;
}
sub get_cookie {
my ($name,$cookies)=@;
@cookees=split /\;/,$cookies;
@which=grep (/$name/,@cookees);
# print join "\n",@which;
($ckey,$cval) = split /=/,$which[0];
$cval
}
This writes out delimitted data to standard out. Hand the program the uri of the server
e.g. https://server.com:port/ctx