5 Replies Latest reply on Feb 19, 2014 10:35 AM by Flavio Bonacordi

    Recording Script to alert for specific string on a webpage

    Sameer Salve

      Has anyone recorded any script in TMART 4.2 to create an alert if it finds any specific string on a webpage ?

      If yes, then please share the procedure.

      Thanks !!

        • 1. Re: Recording Script to alert for specific string on a webpage
          Flavio Bonacordi

          I have one script that do exactly what you want... 

           

          The HTML that I visit provide me this result

           

          1-Emails in Queue: 14.
          2-CAI Events: 23097.
          3-FTS Pending Records: 175.
          4-Application Pending: 22.
          5-SYS Action: 26981.
          6-CAI Parameters: 194718.
          7-NTE Notifier Log: 8119642.
          8-OBJSTR Pending: 0.
          9-NumbOfPendingCIChanges: 0.
          10-StaleCI: 0.
          


          and the code is to check the value right after one specific string ( in this case... 3-FTS Pending Records:)

           

          The code will check what is the string that reside between "3-FTS Pending Records: " and the "." in this example... it will return 175.

           

          //----------------------------------------------------------------------
          // Recorded 7/19/2013 by BMC TM ART Recorder v4.1.0.4553
          //----------------------------------------------------------------------
          @codepage(1252)
          benchmark BMCTMARTRecorder
          use "WebAPI.bdh"
          dcluser
            user
              VUser
            transactions
              TInit          : begin;
              TMain          : 1;
          var
          dclrand
          dcltrans
            transaction TInit
            begin
              WebSetBrowser(WEB_BROWSER_MSIE7);
              WebModifyHttpHeader("Accept-Language", "en-US");
            end TInit;
            transaction TMain
            var
              sFTSPendingRecords : string;
              sFTSThreshold      : string;
              fValue            : float;
              sErrorMessage      : string;
            begin
              AttributeGetString("attFTSRecords", sFTSThreshold, sizeof(sFTSThreshold));    
              SetEncoding("UTF-8");
              WebIgnoreServerError(404, SEVERITY_INFORMATIONAL, 1);
              WebParseHtmlBound(sFTSPendingRecords,STRING_COMPLETE,"3-FTS Pending Records: ",".",WEB_FLAG_IGNORE_WHITE_SPACE);    
              WebPageUrl("http://server.domain/TMART.aspx", "TMART Monitors");
              if number(sFTSPendingRecords)>number(sFTSThreshold) then
                  sErrorMessage:="FTS Pending Records is "+sFTSPendingRecords;
                  RaiseError(CUSTOM_MESSAGE,sErrorMessage,SEVERITY_ERROR);
              end;
              MeasureSet("FTS Pending Records",MEASURE_COUNTER_CUSTOMCOUNTER,number(sFTSPendingRecords));
              MeasureGet("FTS Pending Records",MEASURE_COUNTER_CUSTOMCOUNTER,MEASURE_KIND_LAST,fValue);
            end TMain;
           
          
          

           

          Let me know if you need any help on that...

           

          Some explanation about the code...

           

          This code check the value and raise and error in case of the value is greather than a expected threshold...

          • 2. Re: Recording Script to alert for specific string on a webpage
            Sameer Salve

            Thanks Flavio !!

            I have couple of queries

            1. Did you write the script or record this particular transaction ?

            2. How does the variable sFTSThreshold get populated ?

             

            Its too much to ask, but if you have recorded this particular transaction, will you be able to provide me the screenshots of the same, so I can test it in my dev env. my email id is sameersalve@gmail.com.

             

            Thanks again for the info.

            • 3. Re: Recording Script to alert for specific string on a webpage
              Flavio Bonacordi

              sFTSThreshold is a PROJECT ATTRIBUTE... you define that and "call" this variable using AttributeGetString.

               

              I recorded the script with the basic action... only visit the URL... after that I add my code to perform the actions that I was looking for.. basically the recording feature just gave me the

              WebPageUrl("http://server.domain/TMART.aspx", "TMART Monitors"); command and some definitions in the beginning of the code like these...

               

              @codepage(1252)  

              benchmark BMCTMARTRecorder  

              use "WebAPI.bdh"  

              dcluser  

                user  

                  VUser  

                transactions  

                  TInit          : begin;  

                  TMain          : 1;  

              var  

              dclrand  

              dcltrans  

                transaction TInit  

                begin  

                  WebSetBrowser(WEB_BROWSER_MSIE7);  

                  WebModifyHttpHeader("Accept-Language", "en-US");  

                end TInit;  

                transaction TMain  

                var  

              • 4. Re: Recording Script to alert for specific string on a webpage
                Hal DeVore

                Great discussion and example!

                 

                Flavio, did you use the TrueLog Explorer wizard to parse the sFTSPendingRecords value?  Or hand code that?  Results would be the same, of course.  The wizard is a handy way to do such parsing.

                 

                --Hal

                • 5. Re: Recording Script to alert for specific string on a webpage
                  Flavio Bonacordi

                  Hi Hal,

                   

                  True... TrueLog Explorer wizard would be handy... but in this case I create the code. I don't like use wizards after I learn how to do it... False impression of be in the control of the thing! :-) LOL! Make me fell good about it! :-)