2 Replies Latest reply on Jul 8, 2017 1:21 PM by Ravinder Kumar Branched from an earlier discussion.

    IIWS using Perl

    Ravinder Kumar
      Share This:

      Thank you Charles for the efforts. Appreciate it.

       

      I am trying to integrate a tool with BEM using IIWS. In my initial attempt I tried using perl (LWP module) where I used "Connect", "SendEvent" and "Disconnect" methods. Integration was successful but it had some memory leaks leading in 100% CPU utilization.

       

      So I am looking for some alternative where I can send events from elementary layer to BEM using IIWS. I am attaching my previous script just for reference purpose.

       

      #!/usr/bin/perl

       

       

      use HTTP::Request::Common;

      use IO::Handle;

      use LWP::UserAgent;

       

       

      #hostname identification

      my $hostname = `hostname`;

       

       

      #setting time for logfile

      my $mytime=localtime;

      my ($day,$month,$date,$tm,$year)=split(/\s+/,$mytime);

      my $time=$month."_".$date."_".$year;

       

       

      # modify following variables as required

       

       

      my $webpage="http://10.33.230.85:9080/imws/services/ImpactManager?wsdl";

      our ($usrname,$password,$imname,$bufferType) = ("user","user","r1","BMCII_BUFFER_MODE_DEFAULT");

      our ($connectionId,$mcid);

      our $EventClass = MTAAS_EVENT;

      our ($input,$input1,$input2,$input3,$input4,$input5,$input6,$input7,$input8,$input9,$input10,$input11,$input12,$input13,$input14,$input15,$input16,$input17,$input18,$input19) = @ARGV;

      our ($val,$val1,$val2,$val3,$val4,$val5,$val6,$val7,$val8,$val9,$val10,$val11,$val12,$val13,$val14,$val15,$val16,$val17,$val18,$val19);

      our ($inval,$inval1,$inval2,$inval3,$inval4,$inval5,$inval6,$inval7,$inval8,$inval9,$inval10,$inval11,$inval12,$inval13,$inval14,$inval15,$inval16,$inval17,$inval18,$inval19);

      our (@outputcon,@errorCon,$errorCon,@outputdis,@errorDis,$errorDis,@outputsnd,@errorSnd,$errorSnd);

       

       

      my $logfile = "D:\\Documents\\Scripts\\SoapIntegration\\Logs\\scriptlog_".$time.".log";

       

       

      #invoking file handle

       

       

      open(LOGFILE, ">>$logfile") or die "Could not open file location- '$logfile'.$!\n";

       

       

      #parsing input variables

       

       

        print LOGFILE "$mytime || Input variables are @ARGV\n";

        $input =~ /(.*)(\=)(.*)/;

        $val = "$1";

        $inval = "$3";

       

        $input1 =~ /(.*)(\=)(.*)/;

        $val1 = "$1";

        $inval1 = "$3";

       

        $input2 =~ /(.*)(\=)(.*)/;

        $val2 = "$1";

        $inval2 = "$3";

       

        $input3 =~ /(.*)(\=)(.*)/;

        $val3 = "$1";

        $inval3 = "$3";

       

        $input4 =~ /(.*)(\=)(.*)/;

        $val4 = "$1";

        $inval4 = "$3";

       

        $input5 =~ /(.*)(\=)(.*)/;

        $val5 = "$1";

        $inval5 = "$3";

       

        $input6 =~ /(.*)(\=)(.*)/;

        $val6 = "$1";

        $inval6 = "$3";

       

        $input7 =~ /(.*)(\=)(.*)/;

        $val7 = "$1";

        $inval7 = "$3";

       

        $input8 =~ /(.*)(\=)(.*)/;

        $val8 = "$1";

        $inval8 = "$3";

       

        $input9 =~ /(.*)(\=)(.*)/;

        $val9 = "$1";

        $inval9 = "$3";

       

        $input10 =~ /(.*)(\=)(.*)/;

        $val10 = "$1";

        $inval10 = "$3";

       

        $input11 =~ /(.*)(\=)(.*)/;

        $val11 = "$1";

        $inval11 = "$3";

       

        $input12 =~ /(.*)(\=)(.*)/;

        $val12 = "$1";

        $inval12 = "$3";

       

        $input13 =~ /(.*)(\=)(.*)/;

        $val13 = "$1";

        $inval13 = "$3";

       

        $input14 =~ /(.*)(\=)(.*)/;

        $val14 = "$1";

        $inval14 = "$3";

       

        $input15 =~ /(.*)(\=)(.*)/;

        $val15 = "$1";

        $inval15 = "$3";

       

        $input16 =~ /(.*)(\=)(.*)/;

        $val16 = "$1";

        $inval16 = "$3";

       

       

        $input17 =~ /(.*)(\=)(.*)/;

        $val17 = "$1";

        $inval17 = "$3";

       

        $input18 =~ /(.*)(\=)(.*)/;

        $val18 = "$1";

        $inval18 = "$3";

       

        $input19 =~ /(.*)(\=)(.*)/;

        $val19 = "$1";

        $inval19 = "$3";

       

       

       

      #main program starts here || calling connect

       

      if (!$usrname or !$password or !$imname or !$bufferType){

        print LOGFILE "$mytime || ERROR || Mandatory input variables missing.\n";

        $message_body = "$mytime || ERROR || Mandatory input variables missing.\n";

        exit();

      }

       

       

      my $messagecon="<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:imap=\"http://blueprint.bmc.com/ImapiElems\">

         <soapenv:Header/>

         <soapenv:Body>

            <imap:Connect>

               <imap:userName>$usrname</imap:userName>

               <imap:password>$password</imap:password>

               <imap:imname>$imname</imap:imname>

               <imap:bufferType>$bufferType</imap:bufferType>

            </imap:Connect>

         </soapenv:Body>

      </soapenv:Envelope>";

       

      my $userAgentcon = LWP::UserAgent->new;

      my $responsecon = $userAgentcon->request(POST $webpage,

      Content_Type => 'text/xml',

      Content => $messagecon);

       

       

      if ($responsecon-> is_success){

        @outputcon= $responsecon->content;

      }

      else {

        @errorCon= $responsecon->content;

        foreach $errorCon(@errorCon){

        $errorCon =~ s/\n//g;

        print LOGFILE "$mytime || ERROR || '$errorCon'. Contact BMC Administrator for support. \n";

        }

        exit();

      }

       

       

      foreach $outputcon (@outputcon){

        $outputcon =~ s/</ /g;

        $outputcon =~ s/>/ /g;

        $outputcon =~ s/"/ /g;

        $outputcon =~ s/'/ /g;

        $outputcon =~ s/=/ /g;

        $outputcon =~ s/\?/ /g;

        $outputcon =~ s/\// /g;

        $outputcon =~ s/\:/ /g;

        $outputcon =~ s/1\.0/ /g;

        $outputcon =~ s/UTF\-8/ /g;

        $outputcon =~ s/\./ /g;

        if ($outputcon =~ /(imap connectionId.*)(\s\d+)/){

        $myconnectionID = $2;

        $myconnectionID =~ s/ //g;

        }

      }

       

       

      # sending event using connection ID

       

       

      my $messagesnd = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:imap=\"http://blueprint.bmc.com/ImapiElems\" xmlns:bas=\"http://blueprint.bmc.com/BasicTypes\" xmlns:even=\"http://blueprint.bmc.com/Event\">

         <soapenv:Header/>

         <soapenv:Body>

            <imap:SendEvent>

               <imap:connection>$myconnectionID</imap:connection>

               <imap:message>

                  <!--Zero or more repetitions:-->

                  <bas:NameValue_element>

                     <bas:name>$val</bas:name>

                     <bas:value>

                        <bas:string_value>$inval</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                  </bas:NameValue_element>

                  <bas:NameValue_element>

                     <bas:name>$val1</bas:name>

                     <bas:value>

                        <bas:string_value>$inval1</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                  </bas:NameValue_element>  

                  <bas:NameValue_element>

                     <bas:name>$val2</bas:name>

                     <bas:value>

                        <bas:string_value>$inval2</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                   </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val3</bas:name>

                     <bas:value>

                        <bas:string_value>$inval3</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                   </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val4</bas:name>

                     <bas:value>

                        <bas:string_value>$inval4</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                   </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val5</bas:name>

                     <bas:value>

                        <bas:string_value>$inval5</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                   </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val6</bas:name>

                     <bas:value>

                        <bas:string_value>$inval6</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                 </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val7</bas:name>

                     <bas:value>

                        <bas:string_value>$inval7</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val8</bas:name>

                     <bas:value>

                        <bas:string_value>$inval8</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val9</bas:name>

                     <bas:value>

                        <bas:string_value>$inval9</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val10</bas:name>

                     <bas:value>

                        <bas:string_value>$inval10</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val11</bas:name>

                     <bas:value>

                        <bas:string_value>$inval11</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val12</bas:name>

                     <bas:value>

                        <bas:string_value>$inval12</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val13</bas:name>

                     <bas:value>

                        <bas:string_value>$inval13</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val14</bas:name>

                     <bas:value>

                        <bas:string_value>$inval14</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val15</bas:name>

                     <bas:value>

                        <bas:string_value>$inval15</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

         <bas:NameValue_element>

                     <bas:name>$val16</bas:name>

                     <bas:value>

                        <bas:string_value>$inval16</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

        <bas:NameValue_element>

                     <bas:name>$val17</bas:name>

                     <bas:value>

                        <bas:string_value>$inval17</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

        <bas:NameValue_element>

                     <bas:name>$val18</bas:name>

                     <bas:value>

                        <bas:string_value>$inval18</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

        <bas:NameValue_element>

                     <bas:name>$val19</bas:name>

                     <bas:value>

                        <bas:string_value>$inval19</bas:string_value>

                     </bas:value>

                     <bas:value_type>STRING</bas:value_type>

                </bas:NameValue_element>

                  <even:subject></even:subject>

               </imap:message>

               <imap:timeout>60</imap:timeout>

               <imap:messageClass>$EventClass</imap:messageClass>

               <imap:messageType>MSG_TYPE_NEW_EVENT</imap:messageType>

            </imap:SendEvent>

         </soapenv:Body>

      </soapenv:Envelope>";

       

       

      my $userAgentsnd = LWP::UserAgent->new;

      my $responsesnd = $userAgentsnd->request(POST $webpage,

      Content_Type => 'text/xml',

      Content => $messagesnd);

       

       

      if ($responsesnd-> is_success){

        @outputsnd= $responsesnd->content;

      }

      else {

        print LOGFILE "$mytime || ERROR || Input values missing from send XML. Please contact BMC Administrator.\n";

        exit();

      }

       

       

      foreach $outputsnd (@outputsnd){

        $outputsnd =~ s/</ /g;

        $outputsnd =~ s/>/ /g;

        if ($outputsnd =~ /(imap\:response)(.*)(\/imap\:response)/){

        $mcid = $2;

        $mcid =~ s/ //g;

        }

      }

       

       

      print LOGFILE "$mytime || SUCCESS || Connection ID is $myconnectionID || MC_UEID is $mcid \n";

       

      Regards

      Ravinder Kumar