It came to my attention that CreateTypedPropertyBag method of MOMScriptAPI is not documented in MSDN (or at least not published at the time I’m writing this post). I will try to offer a bit of insight for this API as well as provide a sample for its usage.

This method creates a new property bag object, which is used to “temporarily” store operations data (such as discovery, event, performance data, or any other data) as a collection of name-value pairs. This property bag data then may serve as input to subsequent mapping module which is converting property bag into “more” specific operations data type. Such converted data type is likely to be used within a workflow later (to collect in operational DB etc).

MOMScriptAPI.CreateTypedPropertyBag(type)

Parameters

Parameter

Type

Description

type

Long

The type of allowed conversion/mapping.

 

Return Value

Type

Description

Object

A new instance of the MOMPropertyBag object.

 

Remarks

A script uses a property bag to store output data that will be used by subsequent modules. When CreatePropertyBag API is used, output data can be handled by any subsequent module that allows property bag as its input. With discussed API, only possible uses of property bags are:

·         Map data to an alert and store in the database.

·         Map data to an event and store in the database.

·         Map data to a performance point and store in the database.

·         Use data to evaluate state as part of a monitor.

 

It is also imperative that with this API, there is just one conversion use at one time only. Use is specifically driven by API input argument - type. This is ultimately what community already tried to resolve on its own (rather successfully I must say). So to summarize in this post as well, possible conversions based on type used are:

·         oBag = CreateTypedPropertyBag(0)
property bag can be converted only to alert, it is not convert-able to anything else and would be ultimately dropped with such conversion request

·         oBag = CreateTypedPropertyBag(1)
property bag can be converted only to event, it is not convert-able to anything else and would be ultimately dropped with such conversion request

·         oBag = CreateTypedPropertyBag(2)
property bag can be converted only to perf data, it is not convert-able to anything else and would be ultimately dropped with such conversion request

·         oBag = CreateTypedPropertyBag(3)
property bag can be converted only to state data, it is not convert-able to anything else and would be ultimately dropped with such conversion request

With current release of OpsMgr2007, only mapping modules performing conversion to event and perf data make use of this conversion type check (there is not really a mapping module to alert and state data type implemented and/or needed yet), but in the future I would expect all mapping modules expecting property bag as its input and producing particular operations data to follow this paradigm.

 

Perf conversion example

 

This example shows possible creation of a property bag typed for performance data conversion and adds a name-value pair for performance counter name, performance counter instance name and performance counter value. Those pairs of such property bag then need to be properly “mapped” in configuration of module creating performance data type to allow for correct conversion.

NOTE: This example also uses API functions that I may post later (AddItem, ReturnItems)

Dim oAPI

Set oAPI = CreateObject("MOM.ScriptAPI")

...

Set objAD = CreateObject("McActiveDir.ActiveDirectory")

objAD.Server = strComputer

 

If objAD.GetDatabaseInfo(strPathDB, lSizeDB, lFreeSpaceDB) Then

strPathDB = LCase(strPathDB)

 

Set oBag = oAPI.CreateTypedPropertyBag(PerformanceDataType)

oBag.AddValue "StatusCounter" , "Database Drive Free Space"

oBag.AddValue "StatusInstance" , strPathDB

oBag.AddValue "StatusValue", "" & lFreeSpaceDB

oAPI.AddItem oBag

 

Set oBag = oAPI.CreateTypedPropertyBag(PerformanceDataType)

oBag.AddValue "StatusCounter" , "Database Size"

oBag.AddValue "StatusInstance" , strPathDB

oBag.AddValue "StatusValue", "" & lSizeDB

oAPI.AddItem oBag

 

End If

...

Call oAPI.ReturnItems 

<ConditionDetection ID="PerfMapper" TypeID="SystemPerf!System.Performance.DataGenericMapper">

<ObjectName>AD Storage</ObjectName>

<CounterName>$Data/Property[@Name='StatusCounter']$</CounterName>

<InstanceName>$Data/Property[@Name='StatusInstance']$</InstanceName>

<Value>$Data/Property[@Name='StatusValue']$</Value>

</ConditionDetection>