次の方法で共有


Parameter replacements (part 2)

As started in Parameter replacements (part1), context parameters can be used in any part of a text and replaced by the runtime with the actual parameter value before the module is instantiated.

Management Pack Element Context Parameters

Some monitoring objects may require having a GUID reference to some MP elements such as the rule id where the module is defined, or reference id of managed entity types etc. MP author passes these references using MPElement context parameters.

Syntax

$MPElement$

Where Used:

1. To retrieve the id of the rule, monitor or task. This context parameter is often used with script base discovery (discovery data are requested to provide the creator when calling CreateDiscoveryData). Sample snapshot below:

<Discovery ID="Sample" Target="Windows!Microsoft.Windows.Computer">

        <Category>Discovery</Category>

        <DiscoveryTypes />

        <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScript.DiscoveryProvider">

          <IntervalSeconds>900</IntervalSeconds>

          <SyncTime />

          <ScriptName>sampleDiscovery.vbs</ScriptName>

          <Arguments> $MPElement$ $Target/Id$</Arguments>

          <ScriptBody><![CDATA[

Option Explicit

Dim oArgs

Set oArgs = WScript.Arguments

Dim SourceId, ManagedEntityId

SourceId = oArgs(0)

ManagedEntityId = oArgs(1)

Dim oApi

Set oApi = CreateObject("MOM.ScriptAPI")

Dim oData

Set oData = oApi.CreateDiscoveryData ( _

            0, _

            SourceId, _

            ManagedEntityId _

) …

Syntax

$MPElement[Name=”<MPAlias>!<Relname>”]$

$MPElement[Name=”<Relname>”]$

$MPElement[Name=”<MPAlias>!<Relname>”]/<SubObjectName$

$MPElement[Name=”<Relname>”]/<SubObjectName$

Where Used:

1. To retrieve the id (GUID) of any MP object such as task id, rule id, type id where MPAlias needs to be specified if the element referred is in another MP.

2. To retrieve the id of a sub-object of an MP element such as the property of a Managed Entity Type, the write action id of a rule etc. Again, MPAlias needs to be specified if the element referred is in another MP defined as publicly accessible.

<Discovery ID="Sample.DiscoverComputerRole" Target="Windows!Microsoft.Windows.Computer">

  <Category>Discovery</Category>

  <DiscoveryTypes>

    <DiscoveryClass TypeID="Sample.ComputerRole" />

  </DiscoveryTypes>

  <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.WmiProviderWithClassSnapshotDataMapper">

    <NameSpace>root\cimv2</NameSpace>

    <Query>select * from Win32_ComputerSystem</Query>

    <Frequency>900</Frequency>

    <ClassId> $MPElement[Name="Sample.ComputerRole"]$ </ClassId>

    <InstanceSettings>

      <Settings>

        <Setting>

          <Name> $MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$ </Name>

          <Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>

      </Setting>

        <Setting>

          <Name> $MPElement[Name="System!System.Entity"]/DisplayName$ </Name>

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

        </Setting>

      </Settings>

    </InstanceSettings>

  </DataSource>

</Discovery>

Note:

In general, MPElement replacement, although used is not something that MP authoring developer needs to face directly too frequently. Some cases where this context parameter may be required might be hidden by the use of our authoring tools as well. Other cases are documented within MSDN (OpsMgr scripting, Using Context Parameters in script, …). I would encourage seeking advice thru newsgroup aliases and other community resources for issue related to the use of MPElement, if any help is indeed needed in this area.

Also, please check back again, I will continue describing other context parameters as well ($Target,$Data …)

Comments

  • Anonymous
    November 17, 2007
    Parameter replacements series