次の方法で共有


MOMScriptAPI.CreateDiscoveryData Method

Applies To: System Center 2012 - Operations Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

Creates a new MOMDiscoveryData object, which stores discovery data and is used to submit the collected data back to the management server.

MOMScriptAPI.CreateDiscoveryData(dwSourceType, bstrSourceId, bstrManagedEntityId)

Parameters

Parameter Type Description

dwSourceType

Long

The source type. The value 0 (Rule) should always be used for the source type.

bstrSourceId

String

The ID of the source monitoring class.

bstrManagedEntityId

String

The ID of the monitoring object.

Return Value

Type Description

Object

A new instance of the MOMDiscoveryData object.

Remarks

To create discovery data, you must first create a MOMScriptAPI object.

After a MOMScriptAPI object is created, you can create a discovery data object. The MOMScriptAPI.CreateDiscoveryData method takes three parameters—dwSourceType, bstrSourceId, and bstrManagedEntityId.

The globally unique identifier (GUID) of the discovery object that launched the script is passed into the script as $MPElement$, and the GUID of the object that the script is executing against is passed in as $Target/Id$.

After the MOMDiscoveryData object is created, you can create instances and relationships to be submitted to Operations Manager.

Requirements

Platforms: Requires Windows Server 2003, Windows Vista, or Windows Server 2008

Version: Requires Operations Manager 2007 or System Center 2012 – Operations Manager

Example

This example creates a discovery data object as identified by the input parameters, and it adds property values to any files in the identified folder on the target computer.

Option Explicit
Dim oArgs
Set oArgs = WScript.Arguments

Dim oAPI
Set oAPI = CreateObject("MOM.ScriptAPI")

Dim SourceId, ManagedEntityId, targetComputer
' SourceId is the GUID of the discovery object that runs the script.
SourceId = oArgs(0)
' ManagedEntityId is the GUID of the computer class that is targeted by the script.
ManagedEntityId = oArgs(1)
' targetComputer is the Fully Qualified Domain Name
' of the computer targeted by the script. The FQDN
' is in Arg(2) of the command prompt.
targetComputer = oArgs(2)

Dim oFSO, oDiscoveryData, oInst
Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
Set oFSO = CreateObject("Scripting.FileSystemObject")
If (oFSO.FolderExists("C:Appy")) Then
    ' Create the application instance.
    Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Demo.Scripting.Appy']$")
    ' Define the property values.
    Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
    Call oInst.AddProperty("$MPElement[Name='Microsoft.Demo.Scripting.AppY']/Version$", "2.0")
    Call oInst.AddProperty("$MPElement[Name='Microsoft.Demo.Scripting.AppY']/Path$", "C:\AppY")
    Call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", "Application Y")
    Call oDiscoveryData.AddInstance(oInst)
    ' Discover the application's components.
    Dim oFolder, ofile
    Set oFolder = oFSO.GetFolder("C:\Appy")
    ' Create a separate class instance for each file in the folder.
    For Each oFile in oFolder.Files
        Set oInst = oDiscoveryData.CreateClassInstance("$MPElement[Name='Microsoft.Demo.Scripting.AppYComponent']$")
        ' Define the property values for the class.
        ' The available properties are detemined by the
        'Management Pack that defines the class.
        Call oInst.AddProperty("$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", targetComputer)
        Call oInst.AddProperty("$MPElement[Name='Microsoft.Demo.Scripting.AppYComponent']/ID$", StripExtension(oFile.Name))
        Call oInst.AddProperty("$MPElement[Name='Microsoft.Demo.Scripting.AppYComponent']/FileName$", oFile.Name)
        Call oInst.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$",StripExtension(oFile.Name))
        Call oDiscoveryData.AddInstance(oInst)
    Next    
End If

' Submit the discovery data to the Operations Manager database.
Call oAPI.Return(oDiscoveryData)

' A helper function to remove the extension from a file name.
Function StripExtension (sFile)
    StripExtension = Left(sFile, Len(sFile) -4)
End Function

See Also

Reference

MOMDiscoveryData Object
MOMScriptAPI Object