Text log value

Need new test, action, option? Post request here.
Post Reply
dgilbert
Posts: 1
Joined: Thu Jul 05, 2007 10:02 pm

Text log value

Post by dgilbert »

I have a tilde (~) delimted text log that I need to parse and determine if the 3rd value (of three) is greater than a certain threshhold. If so, then alert as bad.

Here's a sample of the text log:
07:59:56~1128~604

Ideally, I'd report as bad any condition where the third field is a percentage of 2nd. So, in the example, if the third field were, say, >=80% of the 2nd, (e.g. >=902), condition bad would be set. I could easly hard set the threshhold but the percentage method would be far more suitable in this application where the second value changes occasionally

This is easily accomplished externally, but I'm dearly hoping it can be accomplished in a manner native to HM.

Help would be greatly appreciated.
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Re: Text log value

Post by KS-Soft Europe »

dgilbert wrote:I have a tilde (~) delimted text log that I need to parse and determine if the 3rd value (of three) is greater than a certain threshhold. If so, then alert as bad.

Here's a sample of the text log:
07:59:56~1128~604
I think, you may use "Shell script" test method with the following script:

Code: Select all

@echo off
rem %1 - log file name
rem %2 - threshold value

SET last_line=""
SET last_value=0

IF NOT EXIST %1 (
   echo ScriptRes:Unknown:File not found: %1
   goto end
)

FOR /F "tokens=* delims=" %%A IN ('type %1') DO SET last_line=%%A 

FOR /F "tokens=3* delims=~" %%A IN ('echo %last_line%') DO SET last_value=%%A

IF %last_line%=="" (
   echo ScriptRes:Unknown:Line not found
   goto end
)

IF %last_value% GTR %2 (
   echo ScriptRes:Bad:%last_value%
) ELSE (
   echo ScriptRes:Ok:%last_value%
)

:END
Script takes the last line from the log file and compare the third value with given threshold. Please read the following article concerning "Shell Script" test method: http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
dgilbert wrote:Ideally, I'd report as bad any condition where the third field is a percentage of 2nd. So, in the example, if the third field were, say, >=80% of the 2nd, (e.g. >=902), condition bad would be set. I could easly hard set the threshhold but the percentage method would be far more suitable in this application where the second value changes occasionally
Prety complicated calculation for the .bat file, isn't it? Probably, using "Active Script" test method is preferable in this case: http://www.ks-soft.net/hostmon.eng/mfra ... htm#script
dgilbert wrote:This is easily accomplished externally, but I'm dearly hoping it can be accomplished in a manner native to HM.
You know, there are a lot of different log files with different delimiters and different parsing and comparing requirements, so it is not easy to implement single "cooked" solution. :roll:
Actually, "Shell Script" and "Active Script" test methods are "native" to HM as well. ;-)

Regards,
Max
Post Reply