Post · 3 min read· pp. 201–202

Monitor file age with Operations Manager 2007 (vbscript monitor)

In this post, I will explain one of the techniques to monitor the age of a given file, using vbscript and Operations Manager 2007

This is what the script looks like :

Option Explicit ' ' Script that returns the difference in number of days between now() and ' the last modified timestamp of a file ' feed the full path to the file as the first parameter ' Written by Peter Van Eeckhoutte ' Feb 2008 ' Dim oArgs Set oArgs = Wscript.Arguments Dim oAPI Set oAPI = CreateObject("MOM.ScriptAPI") if oArgs.Count < 1 Then     ' If the script is called without the required argument,     ' create an information event and then quit.     Call oAPI.LogScriptEvent(WScript.ScriptName,101,0,WScript.ScriptName+" script was called without any arguments and was not executed. ")     Wscript.Quit -1 End If Dim objFile Dim ValueToReturn Dim oFso Dim oFile Dim oBag Dim filename Set oFso = CreateObject("Scripting.FileSystemObject") 'replace single slashes with double slashes filename = Replace(oArgs(0),"",\) 'see if file exists if (oFso.FileExists(filename)) Then      set objFile = oFso.GetFile(filename)      ValueToReturn=DateDiff("d",objFile.DateLastModified,Now) Else      ValueToReturn=9999 End If Set oBag = oAPI.CreatePropertyBag() Call oBag.AddValue("DaysAgo",ValueToReturn) Call oAPI.LogScriptEvent(WScript.ScriptName,101,0,ValueToReturn) Call oAPI.Return(oBag)

This is how it works

Open the authoring pane in OpsMgr and go to monitors

Find the Windows Computers (or any other scope that contains computer objects). Create a new unit monitor (Script based, two state monitor) and save the monitor in your custom management pack. Specify a good name, make sure to leave the monitor disabled for now (uncheck the "Monitor is enabled" checkbox at the bottom). We only want to run this script on one server, so we will create an override for this server lateron.

Quick note before continuing : you'll have to create a monitor for each file that you want to watch. So you can put the name of the server and the name of the file in the monitor name field.

Configure the schedule (e.g. once per day)

Define the script filename (don't forget the .vbs extension) and set a timeout. This is a just a simple script, so 1 minute will be fine.

Click "Parameters" and enter the absolute path to the file that you want to monitor. (between double quotes)

Paste the entire script from the table above in the Script: field

Expressions : Unhealthy : Parameter Name : Property[@Name='DaysAgo'] Operator : is greater than Value :

(Note : as you can see in the script, if the file is not found, the script will return 9999… it's up to you how you want to deal with that. You can write another monitor that checks for the presence of the file and look at the 9999 value… )

Healthy : Parameter Name : Property[@Name='DaysAgo'] Operator : is less than or equal to Value :

Finish the monitor by allowing the monitor to create an alert. In the alert description field, you can specify some text :

The file is Data/Context/Property[@Name=′DaysAgo′]Data/Context/Property[@Name='DaysAgo'] days old, which is older than …. days

Save the monitor

Edit the monitor again and create an override for the server that contains the file you want to look at.

Enable the monitor for that server, and wait until it kicks it.