Maybe you can try to put each line in an array and use the strsearch function for each entries.
That sounds promissing... but I will fall back in the my actual problem... how to read the txt file line by line.
I went to the Micro Focus site and searched on FRead. I got these two hits that may help:
Thanks for the help... after I submit this question... I hit, by my self, a result very close to the first example you found.
But I'm still trying to read the file line by line...
The second example is very interesting... would be perfect if I could set the split to the CRLF (ASCII code 13) and do that multiple times until the EOF.
you can check also the strRegexFind..... functions.
I made a quick script :
nPos1 := StrSearch(sData, "\r", STR_SEARCH_FIRST);
writeln("line1:" + substr(sData,test,1,nPos1));
cpt := 1;
while (nPos1 < strlen(sData)-1) do
cpt := cpt + 1;
nPos := StrSearch(sData, "\r", STR_SEARCH_NEXT);
writeln("line" + string(cpt) + ":" + substr(sData,test,nPos1+2,nPos-nPos1-2));
nPos1 := nPos;
the limitation is to have a break line at the end of the file, if not the script never stop...but the script is made to be enhanced
Christophe... I don't have words to describe the size of the smile that your code bring to my life!!!
I will work now enhanced the code and work to analize every line of my file to raise the alerts when I found the string I'm looking for...
I will post the code here later when I finish!
Thank you very much!!!
Glad to hear that
With Christophe collaboration I was able to come up with a custom script that allows you to verify a text file and look for a specific string. The monitor will Raise a Custom Error returning the entire line where the error was found.
Singles TRY SCRIPT in workbench works fine. I will start the testing phase in TMART and I'm wondering what will happend if I schedule the monitor to run every 5 minutes... pretty sure the monitor will "find" the same error over and over again until the log file changes... but it's a starting point and I'm looking for the Comunity assistance to overcame that
For some reason that I don't understand the FOpen doesn't work when I use the AttributeGetString. But that can be solved with some research.
WebUser-Profile1_1 localhost 22 00:00:00 Function AttributeGetString "attLogFile" = "\\\\ARAdminDev\\ARLogs\\arerror.log" WebUser-Profile1_1 localhost 23 00:00:00 Function AttributeGetString "attSearch" = "AR System server terminated when a signal/exception was received by the server" WebUser-Profile1_1 localhost 25 00:00:00 Info Print \\\\ARAdminDev\\ARLogs\\arerror.log WebUser-Profile1_1 localhost 33 00:00:00 Error FOpen RESERR: 1016 - Cannot find data file, File: \\\\ARAdminDev\\ARLogs\\arerror.log, Reason: The system cannot find the file specified. WebUser-Profile1_1 localhost 37 00:00:00 Error FSizeGet RT: 58 - Invalid file handle: The parameter provided as a file handle is not valid. WebUser-Profile1_1 localhost 38 00:00:00 Info Print file size = 0 WebUser-Profile1_1 localhost 41 00:00:00 Error FRead RT: 58 - Invalid file handle: The parameter provided as a file handle is not valid. WebUser-Profile1_1 localhost 42 00:00:00 Info Print 0 bytes read WebUser-Profile1_1 localhost 53 00:00:00 Error Substr RT: 100 - Invalid Usage, Position is beyond string length WebUser-Profile1_1 localhost 53 00:00:00 Info Print line1: WebUser-Profile1_1 localhost 92 00:00:00 Error FClose RT: 58 - Invalid file handle: The parameter provided as a file handle is not valid. WebUser-Profile1_1 localhost 94 00:00:00 Transaction Exec: 0.01; Busy: 0.01 TMain
Where is the code...
benchmark WebBenchmarkName use"WebAPI.bdh" use"Kernel.bdh" dcluser user WebUser transactions TMain : 1; dcltrans transaction TMain var hFile, nRead, nSize,nPos1,cpt,nPos : number; sData,sFile,sSearch,sSearch1,sLine : string; begin // open text file for reading sFile:="\\\\ARAdminDev\\ARLogs\\arerror.log"; FOpen(hFile, sFile); // calculate and display the number of bytes in the file FSizeGet(hFile, nSize); print("file size = "+string(nSize)); // read nSize number of bytes into sData FRead(hFile, sData, nSize, nRead); print(string(nRead)+" bytes read"); // string to search in every line sSearch:="AR System server terminated when a signal/exception was received by the server"; // breakes every line into a variable nPos1 := StrSearch(sData, "\r", STR_SEARCH_FIRST); print("line1:" + substr(sData,sLine,1,nPos1)); cpt := 1; while (nPos1 < strlen(sData)-1) do cpt := cpt + 1; nPos := StrSearch(sData, "\r", STR_SEARCH_NEXT); print("line" + string(cpt) + ": " + substr(sData,sLine,nPos1+2,nPos-nPos1-2)); sLine:=substr(sData,sLine,nPos1+2,nPos-nPos1-2); nPos1 := nPos; // perform the search in the line for the string defined sSearch1 := Strstr(sLine, sSearch); print("String Found: "+sSearch1); print("Len sSearch1: "+string(strlen(sSearch1))); // if the Strstr function return a lenght of ZERO it didn't find the string if strlen(sSearch1) > 0 then Print(sLine); // Raise a CUSTOM ERROR with the LINE where the string was found. RaiseError(CUSTOM_MESSAGE,sLine,SEVERITY_ERROR); end; end; // close file FClose(hFile); end TMain;
Once again.. the "CORE" for this script is the collaboration of Christophe that developed the read line by line routine.
About the issue with the FOpen function, you can look at the antislashes thing, I remember there is a subtility with the use of the projects attributtes. Try without double antislashes.
About the problem that the script will detect the same error, again and again, you can try to save somewhere the last line detected and ignore it in the script. You can save it in a text file if you use only one execution server or maybe something else like create a project attribute and insert the value inside...but you will have to use the web services of TMART to update the value in the script.
Yeah... thanks again Chris... when I come up with the solution I will post a new version of the code here...