Text log test to sub folders ?

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
xxeejj
Posts: 19
Joined: Thu Dec 02, 2010 5:51 am

Text log test to sub folders ?

Post by xxeejj »

hi,

I have to search several sub folders and alert if files do have wrong text string in.

c:\data\???\abc.xml
c:\data\???\bcd.xml
c:\data\???\efg.xml
c:\data\???\hji.xml
c:\data\???\mno.xml

Sub folder name ??? does change randomly.

How set this up ?


using Advanced Host Monitor v 8.50

br
esko
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Do you mean you need to check specific file in newest sub-folder?
Then use Compare Files test method with path like c:\data\%NewestFolder%\mno.xml

Regards
Alex
xxeejj
Posts: 19
Joined: Thu Dec 02, 2010 5:51 am

We have 800...

Post by xxeejj »

hi, I must define more ( and I got more info from application people):

We have software which have 800 sub folders.
sub folder names do not change.
To those subfolders software creates log file every morning.
Files come between 6-8 AM.

If we can find bad text like >RJCT< from any of these 800 sub folder file(s) , make hostmonitor alert.

We can use the %newest% , because name of text file changes, not folder like I said earlier.

Q1: several new subfolders come every week , so how to automatically generate tests ? (I can script these and load tests with hml import, but any other ideas ?)

Q2: can we add to alert line from log file, which has certain string ?

ie. log file structure is

....
<InfoId>Customer_12345</InfoId>
<Result>RJCT</Result>
...

So if this is found Result>RJCT</Result then alert with text InfoId>Customer_12345</InfoId ?

br,
esko
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Then you need to write your own script and use Shell Script test method to perform this check.
Something like this

Code: Select all

Option Explicit

const statusAlive       = "scriptRes:Host is alive:"
const statusDead        = "scriptRes:No answer:"
const statusUnknown     = "scriptRes:Unknown:"
const statusNotResolved = "scriptRes:Unknown host:"
const statusOk          = "scriptRes:Ok:"
const statusBad         = "scriptRes:Bad:"
const statusBadContents = "scriptRes:Bad contents:"

dim objFSO, objShell, objTextFile, FileName, cnt, strtext, strpos, objArgs, fo, x, BadText, fline, nline, flist, ff

Set objArgs = WScript.Arguments

if objArgs.count <> 2 then
WScript.StdOut.Write statusUnknown & "expected params: <Path to Folder> <Search Text>"
WScript.Quit
end if

Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set objShell = Wscript.CreateObject("Wscript.Shell")

BadText = ""
cnt = 0

Set fo = objFSO.GetFolder(objArgs(0))
For Each x In fo.SubFolders

  Set flist = objFSO.GetFolder(objArgs(0) & x.Name & "\")

  For Each ff In flist.files

FileName = objArgs(0) & x.Name & "\" & ff.Name

if objFSO.FileExists(FileName) then

Set objTextFile = objFSO.OpenTextFile(FileName, 1)
strpos = -1
fline = ""
nline = ""

Do While (objTextFile.AtEndOfStream <> True) AND (strpos<1)
    strtext = objTextFile.ReadLine
    strpos = InStr(1, strtext, objArgs(1),0)

    fline = nline
    nline = strtext
Loop

if strpos>0 then
  if BadText <> "" then 
    BadText = BadText & " | "
  end if

BadText=BadText & fline
cnt = cnt + 1
End If

Set objTextFile = Nothing

end if
Next
Next 

if cnt > 0 then
WScript.StdOut.Write statusBad & BadText
else
WScript.StdOut.Write statusOk & BadText
End if
Script requires 2 parameters: <Path to Folder> <Text to search>
Script returns Ok status if none of the files contains specified text. Otherwise it returns Bad status and text (1 line above specified string) from each file that contains the string.

If you need to check new files only and you need to keep old files as well, then you may add some code to check file age...

Regards
Alex
xxeejj
Posts: 19
Joined: Thu Dec 02, 2010 5:51 am

Thanks, we test this

Post by xxeejj »

hi,
I knew You have something ready to use.
We test this during coming weeks and let You know how this goes.
br,
esko
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

I knew You have something ready to use.
We did not. We created script for you :)

Regards
Alex
Post Reply