Simple script which checks the modified time (hours) of a log file

Recently I had to monitor a backup log file. If the modification time stamp of the log file was later than at a certain time then SCOM should fire a warning. In my case if the file was modified later than at 05:00 o’clock (24-hour time notation) an alert should occur. There was no characteristic inside the file to determine the state of the backup nor should it be to complex to fulfill this task.

My approach was to create a timed two state monitor using a vbscript.


Give this monitor an appropriate name and target. Don’t enable the monitor yet.


Run every 15 minutes or even less


Here you insert the script




Dim oArgs
Set oArgs = WScript.Arguments
Dim oAPI
Set oAPI = CreateObject(“MOM.ScriptAPI”)

Dim objFile
Dim ValueToReturn
Dim oFso
Dim oFile
Dim oBag
Dim Filename
Dim DateLastModified

Set oFso = CreateObject(“Scripting.FileSystemObject”)

‘Path to the log file

Filename = “C:\1\log.txt”

If (oFso.FileExists(Filename)) Then

Set objFile = oFso.GetFile(Filename)

DateLastModified= objFile.DateLastModified

‘Here we just pick the hours of the time stamp. Since we are having 24-hour time notation it is easy to pick the hour-part e.g. 05:00 it would pick the “5” or in 16:00 it would pick the “16”.

If DatePart(“h”,objFile.DateLastModified) < 5 Then

ValueToReturn = “OK”


ValueToReturn = “FAILED”

End If


‘Here you just could pick the return value 9999 if an error occurs e.g. for use in an three state monitor

ValueToReturn = 9999

End If

Set oBag = oAPI.CreatePropertyBag()
Call oBag.AddValue(“Status”,ValueToReturn)
Call oBag.AddValue(“Filename”,Filename)
Call oBag.AddValue(“DateLastModified”,DateLastModified)
Call oAPI.Return(oBag)


Next build the unhealthy expression


Then build the healthy expression


Configure the health status of the object


Finally configure the alert here I just put the variables inside. of course you could add some more text into the alert description 🙂


Now as a last step you just have to set an override for the server object or group


Set the status enabled to true



  1. Hi,

    Sorry to be a pain (again) but the script isn’t working as intended. It’s saying the monitor is critical when the minutes in the hour are less than 5 rather that if the file was modified less than 5 minutes ago.

    Any help would be appreciated.

  2. Hi,

    The Query is comparing the time stamp from file last modified date and today’s date, so it would always raise false alaram where file is not modified for days.

    Can you please provide the script where it stores last modified date always and compare it with current time stamp of the file, if there is any change in the time stamp of the file current time stamp with last modified stamp.It should raise alert.

    Kiran Kumar

  3. HI Stefan,

    I need to monitor an xml file to alert only if the file was not modifies in last 24 hours.

    This file gets modified a couple of times in a day, but if it not modified for more than 24 hours , i wish to get alerted for that.

    Any advice on how i can accomplish that.

  4. Hi Stefan

    I have a service that creates multiple log files in a folder. Sometimes the service crashes, but you can’t realy see if it’s working ore not. The only way is to check the logfiles.
    Is it possible to do a script, witch generates an alert, when the modified date of a folder is older than 2 hours?

    Thanks in advance

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s