How to Manage SMS Status Filter Rules

Published : April 11, 2005

Managing status filter rules requires manipulation of arrays that are embedded in an array of objects that is itself a property of an object.

This script creates a status filter rule that causes all other status filter rules to not be evaluated if status message 4711 is received. Status message 4711 indicates that the SMS Site System Status Summarizer has detected that a storage object has less free storage space than the critical free space threshold. As a result, the created rule ensures that the remaining space is not consumed with status messages. Nothing is done with message 4711 itself.

For additional information about configuring and managing status filter rules, see the following topics in the Systems Management Server 2003 Operations Guide:

On This Page

Example
Compiling the Code
See Also

Example

On Error Resume Next
Dim objSWbemLocator
Dim ProviderLoc
Dim Location
Dim objSWbemServices
Dim objSWbemContext
Dim objSobjSWbemInst
Dim myFilterRuleName
Dim myFilterRuleArray
Dim myObjPath
Dim PropLists
Dim Rc
Dim i
Dim j
Dim intPointer1
Dim embprops
Dim tmpArray
Dim ObjEmb
Dim ObjEmbInst
 
Const strSiteCode = "YOURSITECODE"    ' SMS Sitecode.
Const strServer = "YOURSERVERNAME"    ' SMS Site Server computer name.
 
Set ProviderLoc = GetObject("winmgmts:{impersonationLevel=impersonate}!root/sms:SMS_ProviderLocation")
 
If err.number<>0 Then
    wscript.echo "Couldn't get SMS Provider"
    wscript.quit
End If
 
For Each Location In ProviderLoc.Instances_
    If Location.ProviderForLocalSite = True Then
         Set objSWbemServices = GetObject("winmgmts:" & Location.NamespacePath)
    Exit For
   End If
Next
 
Set objSWbemContext=CreateObject("WbemScripting.SWbemNamedValueSet")
objSWbemContext.Add "SessionHandle", objSWbemServices.ExecMethod ("SMS_SiteControlFile", "GetSessionHandle").SessionHandle
objSWbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & strSitecode & """", "Refresh", , , objSWbemContext
myObjPath ="SMS_SCI_Component.FileType=1,Itemtype=""Component"",Sitecode=""" & strSiteCode & """,ItemName=""SMS_STATUS_MANAGER|" & ucase(strServer) & """"
Set objSobjSWbemInst = objSWbemServices.Get(myObjPath, , objSWbemContext)
PropLists = objSobjSWbemInst.PropLists
 
'The rule details.
myFilterRuleName = "My new filter rule"
myFilterRuleArray = array( "Actions=0", "Actions Mask=16", "Stop Evaluating=1", "Code=4711" )
'Check whether the rule is already present.
Rc = 0
For i = 0 to ubound(PropLists)
    If PropLists(i).PropertyListName = "Status Filter: SMS_STATUS_MANAGER" Then
        intPointer1 = i    ' Store the index, we need it later
        Rc = 1    ' Set Rc to indicate that the object was found
        For j = 0 to ubound(PropLists(i).Values)     ' Search for the filter rule
            If PropLists(i).Values(j) = myFilterRuleName Then
                Rc = 2    ' Set Rc to indicate that the status filter rule was found
            End If
        Next
    End If
Next
If Not (Rc = 1) Then
    WScript.Echo "Rule has been added already or we could not find ""Status Filter: SMS_STATUS_MANAGER"""
                WScript.Quit
End If
 
Set embprops = objSobjSWbemInst.Properties_("PropLists")
 
'Add the name of the new rule to 
'the "Status Filter: SMS_STATUS_MANAGER" object.
tmparray = embprops.Value(intPointer1).Values    'copy the array (all filter rules)
redim preserve tmparray( ubound(tmparray) + 1 )    'extend array by 1 element
tmparray( ubound(tmparray) ) = myFilterRuleName    'add the new element
embprops.Value(intPointer1).Values =  tmparray    'overwrite the array (all filter rules)
 
'Build an embedded property.
Set ObjEmb = objSWbemServices.Get("SMS_EmbeddedPropertyList")
Set objEmbInst = ObjEmb.SpawnInstance_()
objEmbInst.PropertyListName = "Status Filter Rule: " & myFilterRuleName
objEmbInst.Values = myFilterRuleArray
 
'Add the rule itself (the embedded property) to the list of rules.
embprops.Value(Ubound(embprops.value) + 1) = objEmbInst
objSobjSWbemInst.Put_ , objSWbemContext
 
'Run SMS_SiteControlFile::Commit to update the site control file.
objSWbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & strSitecode & """", "Commit", , , objSWbemContext
objSWbemServices.Get("SMS_SiteControlFile").ReleaseSessionHandle objSWbemContext.Item("SessionHandle").Value
objSWbemContext.Remove "SessionHandle"

Compiling the Code

  • Requires Windows 2000 Server SP2 or later.

  • Requires an SMS 2003 Site Server.

See Also

Tasks

How to Read SMS Objects

How to Use the Site Control File