none
First time creating script monitor - Expressions & Syntax

    Question

  • Hi,

    I'm trying to create a two-state script monitor with the following script:

    "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("n",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)"

    all objAPI.Return(oBag)
    WScript.Quit"

    Two questions: The parameters value should they be just like the commanlind would be, like this: "c:\temp 1". c:\temp is Targetfolder = objParameters(0) and 1 is ThresholdAge = int(objParameters(1)) ?

    And to the expressions, how  will they look with script above: Call oBag.AddValue("State","BAD") AND all oBag.AddValue("State","GOOD"). I'm thinking of the syntax for the parameter

    Was unable to find sufficent guidance elsewhere, thanks on beforehand!!


    Thanks in advance, Best Regards

    Tuesday, May 29, 2012 12:45 PM

Answers

All replies

  • The syntax for your two-state monitor would have an expression similar to - Property[@Name='State'] EQUALS BAD for the unhealthy expression.  The healthy expression would be EQUALS GOOD (in your example). 

    Check out this example in the MP Authoring Guide for more details on how to create a monitor based off of a script - http://technet.microsoft.com/en-us/library/ff629453.aspx.  You would be passing two parameters for the script arguments as Argument1 Argument2 (space inbetween).  Here is a real-world example - http://blogs.technet.com/b/jimmyharper/archive/2008/08/10/monitoring-a-service-for-state-and-startmode.aspx

    Hope that helps.

    Tuesday, May 29, 2012 6:14 PM
  • In your case, better if you will be return not state, but strDiff and fullpath of files to Property Bag. After it you just can compare strDiff with value in monitor. I wrote about it in russian forum, but you can translate via translate.google.com or etc.

    http://social.technet.microsoft.com/Forums/ru-RU/momru/thread/2821c5b3-fe3a-4380-b73d-67d41e6b036d

    Wednesday, May 30, 2012 9:40 AM
  • Thanks,

    I'm no script expert so I need help on two more things:

    - Now I only get an alert on one of the files in the target folder even tough there are several files there who's age pass the threshold. I'd like an alert for each file.

    - how do I access UNC paths with RunAS ? I can't seem to get this working properly. 

    On beforehand, Thanx


    Thanks in advance, Best Regards

    Wednesday, May 30, 2012 12:03 PM
  • - Now I only get an alert on one of the files in the target folder even tough there are several files there who's age pass the threshold. I'd like an alert for each file.

    You need to write discovery rule.

    - how do I access UNC paths with RunAS ? I can't seem to get this working properly.

    You can use RunAs Profile and associate it with RunAs Account. In your monitor just select your RunAs Profile.
    Wednesday, May 30, 2012 12:27 PM
  • Can't find how to select RunAS Profile within the monitor. How to target this correctly?

    Thanks in advance, Best Regards

    Monday, June 04, 2012 11:33 AM
  • Monday, June 04, 2012 1:24 PM
  • Thanks for your answer, but I'm on SCOM 2012 and I can't see completely how it relates.

    Thanks in advance, Best Regards

    Monday, June 04, 2012 1:27 PM
  • Thanks for your answer, but I'm on SCOM 2012 and I can't see completely how it relates.

    Thanks in advance, Best Regards


    For this task you need Authoring Console, this option is not available in Operations Console. You can download it here - http://www.microsoft.com/en-us/download/details.aspx?id=18222. Management Packs for SCOM 2007 R2 is backward compatible with SCOM 2012, so you can create management packs in OM 2007 R2 Authoring Console.
    Tuesday, June 05, 2012 5:11 AM