Text log test
Text log test
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
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
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
You may use the following script:raphaelb wrote:Would you have any suggestion for doing it without using external 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%
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"
Regards,
Max
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
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
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
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".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?
Regards,
Max
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
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
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
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
You are right. ">" sign was the cause. Please, try the following updated script: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?
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%
Max
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
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
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
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
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,
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,