Text log test

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).
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Text log test

Post by raphaelb »

Hello,

I use text log test to look for a particular error message in log files created by another application. Please find below an extract of the log file I am monitoring:

08:00:10> ric $ The port 2 is on error , closing in progress

08:42:56> ric Port 2 , login in progress

The test needs to be in bad status when “The port 2 is on error , closing in progress” appears in the log files. It should remain in bad status until “Port 2 , login in progress” appears in the log file. When “Port 2 , login in progress” appears in the log file, the test status should change to “OK”.

Is there a way to achieve it with one test?
Currently, the test comes back to “OK” status after the next probe (the error message is not repeated).

Thank you for your help.
Raphael
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Sorry, this cannot be configured as single test unless you will use some external script

Regards
Alex
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Post by raphaelb »

Alex,

Thank you for your reply.
Would you have any suggestion for doing it without using external script?

Regards,
Raphael
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

raphaelb wrote:Would you have any suggestion for doing it without using external script?
You may use the following script:

Code: Select all

@echo off
rem %1 - Filename full path
rem %2 - Bad pattern string
rem %3 - Good pattern string

set last_pattern_status=Ok
set last_pattern_line=

rem Step 1: Retrieving line
for /f "eol=; tokens=*" %%i in (%1) do (
   echo %%i | find "%~2" > NUL
   IF NOT ERRORLEVEL 1 (
      set last_pattern_status=Bad
      set last_pattern_line=%%i
   )
   echo %%i | find "%~3" > NUL
   IF NOT ERRORLEVEL 1 (
      set last_pattern_status=Ok
      set last_pattern_line=%%i
   )

)

echo ScriptRes:%last_pattern_status%:%last_pattern_line%
Script requires three parameters: log filename, "Bad" pattern (e.g. "closing in progress") and "Good" pattern (e.g. "login in progress" ).
If neither "bad" nor "good" pattern is not found in the log file, the status becomes "Ok".

Foregoing script is designed for "Shell Script" test method: http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell

Also you may copy it into some .bat file (e.g. check_log.bat) and test it using command like, for instance:

Code: Select all

check_log.bat C:\Temp\log.txt  "closing in progress" "login in progress"
Please note: script may not work with the files and folders, that contain space in their name.

Regards,
Max
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Post by raphaelb »

Hello Max,

Thank you very much for the script.
I set up a test looking for the “bad” pattern “FAILURE” and a good pattern “SUCCESS”. I manage to retrieve last_pattern_status and last_pattern_line.
However the test stays in unknown status and the reply is: “Error: Invalid result (Scriptres:Ok :SUCCESS) “
Do you see any reason why?

Thanks and Regards,
Raphael
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

raphaelb wrote:However the test stays in unknown status and the reply is: “Error: Invalid result (Scriptres:Ok :SUCCESS) “
Do you see any reason why?
I suppose, you should remove the space between "Ok" and ":". There must not be a space. Your script should return "Scriptres:Ok:SUCCESS" or "Scriptres:Bad:FAILURE".

Regards,
Max
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Post by raphaelb »

:D you're right - it works perfectly now.
Many thanks.

Regards,
Raphael
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

raphaelb wrote::D you're right - it works perfectly now.
Many thanks.
You are welcome. :-)

Regards,
Max
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Post by raphaelb »

Hello Max,

I would like to use the script to monitor “server is starting” in the following log file:


08 07:15:00> main --------------------------------------------------------------------------------------------
08 07:15:00> main Start/stop automatically (start asked / current state is stopped)
E0 07:15:00> main The server is starting - 06 Jun 07 07:15:00
E0 07:15:00> main Server Configuration:


Unfortunately, the reply remains empty – i.e. ScriptRes:Ok:
The problem seems to come from “>” character located after the time for every line in my log file. When removing this character, the script works fine. Is there a workaround for this problem?

Thanks and Regards,
Raphael
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

raphaelb wrote:The problem seems to come from “>” character located after the time for every line in my log file. When removing this character, the script works fine. Is there a workaround for this problem?
You are right. ">" sign was the cause. Please, try the following updated script:

Code: Select all

@echo off 
rem %1 - Filename full path 
rem %2 - Bad pattern string 
rem %3 - Good pattern string 

set last_pattern_status=Ok 
set last_pattern_line= 

rem Step 1: Retrieving line 
for /f "eol=; tokens=*" %%i in (%1) do ( 
   echo "%%i" | find "%~2" > NUL 
   IF NOT ERRORLEVEL 1 ( 
      set last_pattern_status=Bad
      set last_pattern_line=FAILURE 
   ) 
   echo "%%i" | find "%~3" > NUL
   IF NOT ERRORLEVEL 1 ( 
      set last_pattern_status=Ok
      set last_pattern_line=SUCCESS 
   ) 

) 

echo ScriptRes:%last_pattern_status%:%last_pattern_line%	
Regards,
Max
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Post by raphaelb »

Hello Max,

I have implemented the script to monitor several log files.
For some of them, a new file is created when the size reaches 5Mb (and a new file is generated every 2 minutes). When the script is triggered to “audit” such file, it takes more than 600 seconds to complete (i.e. more than the maximum number of seconds). Then Hostmonitor sets “unknown” status for the script.
- Does the script check the whole file or start from the last checked record at each refresh?
- Would you have a solution to avoid the test going to an “unknown” status when applied to large file?

Thanks and Regards,
Raphael
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Such script works slowly because it starts external command in the loop.
If your free-updates/support term has not expired yet, we may develop special utility for you. Could you please provide your registration name and/or order number to support@ks-soft.net?

Regards
Alex
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Post by raphaelb »

Alex,

All details have been sent to support@ks-soft.net as requested.

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

Post by KS-Soft »

Utility available at http://www.ks-soft.net/download/utils/t ... scheck.exe
It requires 3 parameters: <filename> <bad string pattern> <good string pattern>
E.g. texteventscheck.exe c:\app\log1.txt "service stopped" "service started"

Regards
Alex
raphaelb
Posts: 18
Joined: Thu May 31, 2007 4:21 am

Post by raphaelb »

Hello Alex,

Many thanks for the utility. I have implemented an external test with the following parameters:
O:\Hostmonitor\external_program\texteventscheck.exe \\mymachine\c$\Log\test2.log "service stopped" "service started"

However, it always replies ‘0’ even when “service stopped” message is in the log file. Could you please let me know what I am doing wrong?

Thanks and Regards,
Post Reply