Search String test query

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
KerryPatrick
Posts: 11
Joined: Wed Jan 26, 2011 6:21 am
Location: Jersey, Channel Islands

Search String test query

Post by KerryPatrick »

Can you please let me know if it is possible for a log file test (compare files) to alert after a string has appeared say 5 times, rather than just the first time?
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

If these strings appears within specific period of time, you may use options offered by action properties, start action after 5th consecutive bad result.
Please check the manual or visit our web site for more information http://www.ks-soft.net/hostmon.eng/mfra ... properties

Regards
Alex
KerryPatrick
Posts: 11
Joined: Wed Jan 26, 2011 6:21 am
Location: Jersey, Channel Islands

Post by KerryPatrick »

Hi Alex

All our tests are set to notify only after 2 bad results, however there doesn't seem to be a way to make this work within a log file. As soon as a string appears once, the email alert goes out so it is hard to tell without logging onto the server whether this is one error string or 100.

Thanks
KerryPatrick
Posts: 11
Joined: Wed Jan 26, 2011 6:21 am
Location: Jersey, Channel Islands

Post by KerryPatrick »

Just to clarify, the actual setting is to notify after 2 bad results. Obviously once the file is checked again, the string is still in the log file as our files are only archived overnight so the same string is picked up, and the result remains bad until it is archived. I guess what I really want to know is if there is a way to set it to find 2 bad strings in the one log file rather than 2 bad results, as this is only duplicating the first bad result.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

You may use ShellScript test method (http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell) and custom made script like this:
'====================================================
'start cmd: cmd /c cscript.exe /B /E:VBScript %Script% %Params%
'Script requires 2 parameters: <Path to File> <Search Text>
'Script return count of <Search Text> strings in file <Path to File>
'====================================================
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

Set objArgs = WScript.Arguments

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

Set objFSO = Wscript.CreateObject("Scripting.FileSystemObject")
Set objShell = Wscript.CreateObject("Wscript.Shell")
FileName = objArgs(0)
Set objTextFile = objFSO.OpenTextFile(FileName, 1)
cnt = 0

Do While objTextFile.AtEndOfStream <> True
strtext = objTextFile.ReadLine
strpos = -1
Do While (strpos > 0) OR (strpos=-1)
if strpos=-1 then strpos=1
strpos = InStr(strpos, strtext, objArgs(1),0)
If strpos > 0 Then
cnt=cnt+1
strpos=strpos+1
End If
Loop

Loop
objTextFile.Close
If cnt>5 then
WScript.StdOut.Write statusOk & cnt
else
WScript.StdOut.Write statusBad & cnt
end if
'====================================================
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Just to clarify, the actual setting is to notify after 2 bad results. Obviously once the file is checked again, the string is still in the log file as our files are only archived overnight so the same string is picked up, and the result remains bad until it is archived. I guess what I really want to know is if there is a way to set it to find 2 bad strings in the one log file rather than 2 bad results, as this is only duplicating the first bad result.
Compare Files test method is not designed to check log files (check for new records in the file). You should use Text Log test method for this purpose.
http://www.ks-soft.net/hostmon.eng/mfra ... tm#textlog

If you don't care about new bad events that may be recorded in the file and you just need to know how many "bad" records in the file at the moment, use script listed above

Regards
Alex
Post Reply