ITM6 perl script to show list systems info via SOAP query

iKnow-IT banner

Here is an example of a SOAP query via a perl script that give a list systems information. (agent with IP address.... connected to RTEMS .... etc)

# cat get_agent_info.pl

#!/bin/perl 
use lib "/usr/opt/perl5/lib/site_perl/5.8.8"; 
use ITMSoapAPI; 
$usr="<user>"; 
$pwd="<pw>"; 
$tems="<hostname>";  

$itmSoap = new ITMSoapAPI(); 
$itmSoap->setSoapServerUrl("http://$tems:1920///cms/soap"); 
        $soap_call="<CT_Get>". 
        "<userid>$usr</userid><password>$pwd</password>". 
        "<action>start</action><table>O4SRV.LOCALTIME</table><sql>". 
        "SELECT NODE,THRUNODE,PRODUCT,VERSION,HOSTINFO,O4ONLINE,HOSTADDR " . 
        "FROM O4SRV.INODESTS " . 
        "</sql></CT_Get>"; 

        $itmSoap->setRequest($soap_call); 
        $hostinfo=$itmSoap->getResponse(); 
        #print "$hostinfo\n"; 
        @hostinfo = split("/",$hostinfo); 

        foreach $info(@hostinfo) 
        { 
                if ( $info =~ m/\<NODE\>(.*)\</ ) { 
                        $agent=$1; 
                } 
                if ( $info =~ m/THRUNODE\>(.*)\</ ) { 
                        $thrunode=$1; 
                } 
                if ( $info =~ m/PRODUCT\>(.*)\</ ) { 
                        $product="$1"; 
                } 
                if ( $info =~ m/VERSION\>(.*)\</ ) { 
                        $vers="$1"; 
                } 
                if ( $info =~ m/HOSTINFO\>(.*)\</) { 
                        $hostinf="$1"; 
                } 
                if ( $info =~ m/O4ONLINE\>(.*)\</) { 
                        $online="$1"; 
                } 
                if ( $info =~ m/HOSTADDR.*CDATA.*\#(.*)\[/ ) { 
                        $hostaddr="$1"; 
                        print "$agent,$product,$vers,$hostinf,$hostaddr,$thrunode,$online\n"; 
                } 
        } 
 exit 0; 

 sub GetITMtimestamp 
{ 
        local($offset)=@_; 
        $offset=defined $offset ? $offset : 0; 
        local($s,$m,$h,$d,$M,$y,undef,undef,undef)=localtime(time - $offset); 
        return sprintf("\%d\%02d\%02d\%02d\%02d\%02d000",$y,$M+1,$d,$h,$m,$s); 
}  

sub get_time { 
        local($offset)=@_[0]; 
        $offset=defined $offset ? $offset : 0; 
        @months = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); 
        @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun); 
        ($second, $minute, $hour, $dayOfMonth, $month, $yearOffset, $dayOfWeek, $dayOfYear, $daylightSavings) = localtime(time - $offset); 
        $year = 1900 + $yearOffset; 
        if ( length($second) == 1 ) { $second="0".$second } 
        if ( length($minute) == 1 ) { $minute="0".$minute } 
        if ( length($hour) == 1 ) { $hour="0".$hour } 
        return "$weekDays[$dayOfWeek] $months[$month] $dayOfMonth $year $hour:$minute:$second"; 
} 

This Perl script used the following perl module:

# cat ITMSoapAPI.pm 

package ITMSoapAPI; 
use HTTP::Request; 
use HTTP::Response; 
use LWP::UserAgent; 

######################################## 
# Constructor                         # 
####################################### 

sub new { 
        my $this = (); 
        my $proto = shift; 
        my $class = ref($proto) || $proto; 
        $this->{soapServerUrl} = undef; 
        $this->{request} = undef; 
        bless ($this, $class); 
        return $this; 
}  

####################################### 
# Setter/Getter Methods               # 
####################################### 
sub setSoapServerUrl { 
        my $obj = shift; 
        $this->{soapServerUrl} = shift;  
        return $obj; 
} 

 sub setRequest { 
        my $obj = shift; 
        $this->{request} = shift; 
        return $obj; 
} 

 sub getResponse { 
        $header = HTTP::Headers->new; 
        $header->header('Content-Type' => 'text/xml'); 
        $req = HTTP::Request->new; 
        $req->uri($this->{soapServerUrl}); 
        $req->header($header); 
        $req->method("POST"); 
        $ua = LWP::UserAgent->new; 
        $req->content($this->{request}); 
        $response = $ua->request($req); 
        return $response->content; 
} 

1;