If you build a monitor to monitor a logfile, Operations Manager will remember which line it was reading last. Operations Manager will only look for new keyword below that line, it will not read the whole file again. I did a lot of tests with logfile monitoring, read more about them here. If you need to get Operations Manager to read the whole logfile each time, you can use a scrip like this:
Const ForReading = 1
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oBag = oAPI.CreatePropertyBag()Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile _
(“c:\temp\file.txt”, ForReading)Do Until objTextFile.AtEndOfStream
strText = objTextFile.ReadLinevarWarPos = Instr(strText, “Warning”)
If varWarPos > 0 Then
varStatus = “Warning”
varLine = strText
End IfvarCriPos = Instr(strText, “Critical”)
If varCriPos > 0 Then
Call oBag.AddValue(“Line”, strText)
Call oBag.AddValue(“Status”,”critical”)
Call oAPI.Return(oBag)
Wscript.Quit(0)
End IfLoop
objTextFile.CloseIf varStatus = “Warning” Then
Call oBag.AddValue(“Line”, varLine)
Call oBag.AddValue(“Status”,”warning”)
Call oAPI.Return(oBag)
Wscript.Quit(0)
Else
Call oBag.AddValue(“Status”,”ok”)
Call oAPI.Return(oBag)
End If
This script will read the file (c:\temp\file.txt) line by line. The script is looking for two keywords in the logfile, “Warning” and “Critical”. If there is a “Critical” in a line the script will send back a bag with status=Critical and the script will stop. If there is a “Warning” in the line the script will continue, as there might be a “critical” somewhere too. If there was only “Warning” the script will send back status=Warning. If there was no “Warning” or “Critical” the script will send back status=ok.
If there is a “Warning” or “Critical” the script will also put that line into a bag, and send it back to Operations Manager. You will see this line in the alert description. To use this script, you can configure a monitor like this:
- Create a new monitor of type Scripting/Generic/Timed Script Three State Monitor. Input a suitable name and target. More about targeting here.
- Schedule
- Configure your script to run every X minute. The script will rad the whole logfile each time
- Script
- Filename and Timeout, for example CheckFile.vbs and 2 minutes
- Paste the script in the script field
- Unhealthy expression
- Property[@Name='Status']
- Equals
- Warning
- Degraded expression
- Property[@Name=’Status’]
- Equals
- Critical
- Healthy expression
- Property[@Name=’Status’]
- Equals
- ok
- Alerting
- Check Generate alerts for this monitor
- Generate an alert when: The monitor is in a critical or warning health state
- Check Automatically resolve the alert when the monitor returns to a healthy state
- Alert name: Input an alert name
- Alert Description
- State $Data/Context/Property[@Name=’Status’]$
- Line $Data/Context/Property[@Name=’Line’]$
Summary: This monitor, including the script, will read a logfile and generate alerts based on keywords. In will read the whole logfile each time and look for two different keywords.

I think that the same script for two state will look like :
Const ForReading = 1
Set oAPI = CreateObject(“MOM.ScriptAPI”)
Set oBag = oAPI.CreatePropertyBag()
Set objFSO = CreateObject(“Scripting.FileSystemObject”)
Set objTextFile = objFSO.OpenTextFile _
(“c:\temp\file.txt”, ForReading)
Do Until objTextFile.AtEndOfStream
strText = objTextFile.ReadLine
varCriPos = Instr(strText, “Critical”)
If varCriPos > 0 Then
Call oBag.AddValue(“Line”, strText)
Call oBag.AddValue(“Status”,”critical”)
Call oAPI.Return(oBag)
Wscript.Quit(0)
End If
Loop
objTextFile.Close
Call oBag.AddValue(“Status”,”ok”)
Call oAPI.Return(oBag)
End If
Anders,
I am trying to accomplish the same script as a two state monitor. Critical and Ok but I am unable to have any success when I modify the script. By chance do you have an example two state script.
Cheers,
Phil