Monitor help
Hi All,
I am looking to do something I think is fairly straight forward, I hope. I want to implement a SCOM 2 state monitor to tell me if files in a set directory are over a certain age. I have a handy guide that shows me how to create a 2 state monitor and I
am good with that process.
I hope to use the script below (thanks to the author) as it looks exactly like what I wish to do:
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 2009
'
' NAME: Monitor Age of Multiple Files (for two-state monitor)
'
' AUTHOR: Olof Helge
' DATE : 2/27/2010
'
' COMMENT: Script to monitor age of files in a directory, and raise alert if
' any are older than threshold.
'==========================================================================
'Declare variables
DIM objFSO,objParameters,Targetfolder,ThresholdAge,objAPI,oBag
'Create objects
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objParameters = WScript.Arguments
Set objAPI = CreateObject("MOM.ScriptAPI")
Set oBag = objAPI.CreateTypedPropertyBag(StateDataType)
'Set Parameters
Targetfolder = objParameters(0)
ThresholdAge = int(objParameters(1))
'***********************************************************************************
Set colFiles = objFSO.GetFolder(Targetfolder).Files
For Each objFile In colFiles
dtmStartTime = objFile.DateLastModified
strDiff = (DateDiff("h",dtmStartTime,Now()))
'***********************************************************************************
If strDiff > int(ThresholdAge) Then
'WScript.Echo objFile.Name & " is " & strDiff & " hours old."
Call oBag.AddValue("State","BAD")
Call objAPI.Return(oBag)
WScript.Quit
Else
End If
'***********************************************************************************
Next
'Wscript.echo "No file is older then " & ThresholdAge & " hour(s)"
Call oBag.AddValue("State","GOOD")
Call objAPI.Return(oBag)
WScript.Quit
So I start my 2 state monitor build and then get confused as I am a disaster area when it comes to scripting:
How do I set the directory and file age I need to monitor, I see the reference to the
parameters I just don't see how I customise them to my needs.
I guess click the Parameters button and then enter what is needed? Can someone help with exactly what they would enter lets say to check a file in:
C:\ExampleDir
that is over lets say 2 hours old
Would very much appreciate guidance on this as I have zero .vbs knowledge and really need to paint by numbers to some extent!
Thanks in advance
May 26th, 2012 12:32pm
Hi
For the parameters you can enter them with a space between them:
"C:\Example Dir" 2
Once you get this working, you might want to look to try to do the same thing with the Authoring Console so that you expose the parameters as overrides so that administrators can make changes via the overrides tab (rather than having to make changes
to the parameters in the parameters box). This would also then allow you to seal the management pack that the monitor is part of to stop anyone accidently messing about with the script.
Cheers
GrahamRegards Graham New System Center 2012 Blog! -
http://www.systemcentersolutions.co.uk
View OpsMgr tips and tricks at
http://systemcentersolutions.wordpress.com/
Free Windows Admin Tool Kit Click here and download it now
May 27th, 2012 2:34am
Hi Graham,
Well that looks pretty straight forward!
Many thanks for the beginners help and for the additional tips.
May 27th, 2012 4:28am


