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.
Text log value
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
Re: Text log value
I think, you may use "Shell script" test method with the following script: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
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
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#scriptdgilbert 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
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.dgilbert wrote:This is easily accomplished externally, but I'm dearly hoping it can be accomplished in a manner native to HM.

Actually, "Shell Script" and "Active Script" test methods are "native" to HM as well.

Regards,
Max