Share via


Management Pack Service Model Exercise #6 - Creating a Script Discovery (VBScript)


Overview

The following procedures show how to create a VBScript script discovery using  the Operations Manager 2007 Authoring console and Visual Studio Authoring Extensions.  This exercise is part of the System Center Operations Manager Management Pack Authoring Center.

Product Versions

This exercise applies to the following products:

  • System Center Operations Manager 2007 R2
  • System Center 2012 Operations Manager
  • System Center 2012 Operations Manager SP1

Prerequisites

Before you perform this procedure, you must first complete the following prerequisite procedures:

Revisions

The Microsoft System Center team has validated this procedure as of revision #1.  We will continue to review any changes and periodically provide validations on later revisions as they are made.  Please feel free to make any corrections or additions to this procedure that you think would assist other users

Details

The discovery created in this procedure has the following characteristics:

  • Searches for class on any agent with an instance of MyComputerRole1.
  • Discovers three instances of a class named My Application Component. The class has a single key property called ComponentName and a non-key property named Version.
  • The discovered class is hosted by a class named MyComputerRole1 which is hosted by the Windows Computer class. This hosting class has no key property.

Authoring Console Procedure

  1. Select Health Model, and then select Discoveries.
  2. Right-click in the Discoveries pane, select New, and then select Script.
  3. On the General page, do the following:
    1. In the ElementID box, type MyMP.Discovery.MyApplicationComponent.VBScript.
    2. In the Display Name box, type Discover MyApplicationComponent (VBScript).
    3. In the Target box, select MyMP.MyComputerRole1.
    4. In the Category box, select Discovery, and then click Next.
  4. On the Schedule page, in the Run every: box, type 4 hours. Click Next.
  5. On the Script page, do the following:
    1. In the File Name box, type DiscoverApplicationComponents.vbs.

    2. In the Timeout box, type 5 minutes.

    3. Copy the complete following script, and paste it into the Script box.

      SourceId = WScript.Arguments(0) 
      ManagedEntityId = WScript.Arguments(1)
      sComputerName = WScript.Arguments(2)
       
      Set oAPI = CreateObject("MOM.ScriptAPI")
      Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
       
      For i = 1 to 3
         Set oInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='MyMP.MyApplicationComponent']$")
         oInstance.AddProperty "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sComputerName
         oInstance.AddProperty "$MPElement[Name='MyMP.MyApplicationComponent']/ComponentName$", "Component" & i
         oDiscoveryData.AddInstance(oInstance)
      Next
      oAPI.Return(oDiscoveryData)
      
    4. Click Parameters.

    5. In the Parameters box, type $MPElement$, followed by a space.

    6. Click Target, and select Id.

    7. Type a space after $Target/Id$.

    8. Click Target, select (Host=Windows Computer), and then select Principal Name (Windows Computer). Make sure that there is a space between the three variables in the Parameters box.

    9. Click OK and then click Finish.

  6. Select File, and then click Save.

Visual Studio Authoring Extensions Procedure

  1. Create the script:

    1. In Solution Explorer, right click the name of the solution and select Add and then New Item

    2. Select VBScript File.

    3. In the Name box, type DiscoverApplicationComponents.vbs and click Add

    4. Copy the following code into the script:

      SourceId = WScript.Arguments(0)
      ManagedEntityId = WScript.Arguments(1)
      sComputerName = WScript.Arguments(2)
        
      Set oAPI = CreateObject("MOM.ScriptAPI")
      Set oDiscoveryData = oAPI.CreateDiscoveryData(0, SourceId, ManagedEntityId)
        
      For i = 1 to 3
         Set oInstance = oDiscoveryData.CreateClassInstance("$MPElement[Name='MyMP.MyApplicationComponent']$")
         oInstance.AddProperty "$MPElement[Name='Windows!Microsoft.Windows.Computer']/PrincipalName$", sComputerName
         oInstance.AddProperty "$MPElement[Name='MyMP.MyApplicationComponent']/ComponentName$", "Component" & i
         oDiscoveryData.AddInstance(oInstance)
      Next
      oAPI.Return(oDiscoveryData)
      
    5. Select File, and then click DiscoverApplicationComponents.vbs.

  2. Create the Discovery:

    1. In Solution Explorer, right click Right click Discoveries.mptg and click Open.
    2. Right click in the  template window and select Add Template.
    3. Select Discovery (Custom) and click OK.
  3. Configure the Discovery Properties:

    1. Right click the entry for NewDiscovery and select Properties Window.
    2. Change the ID to Discovery.MyApplicationComponent.VBScript.
    3. Change the Display Name to Discover MyApplicationComponent (VBScript).
  4. Select the Discovery Target:

    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyComputerRole1 and click OK.
  5. Select and Configure the Discovery Data Source"

    1. Select Data Source Type ID and click the ellipse (...) button on the right of the field. 

    2. Select Microsoft.Windows.TimedScript.DiscoveryProvider and click OK.

    3. Select Data Source Configuration and click the ellipse (...) button on the right of the field.

    4. Copy the following XML into the configuration window between the <Configuration> tags.  Note that you can use Intellisense to manually type in each entry.  Type the < character to be prompted with valid tags.

      <!-- IntervalSeconds specifies how often we will run the discovery. -->
      <IntervalSeconds>14400</IntervalSeconds>
      
      
      <!-- SyncTime specifies the minutes after the hour to synchronize execution of the discovery. -->
      <SyncTime />
      
      
      <!-- ScriptName specifies the name of the script. -->
      <ScriptName>DiscoverApplicationComponents.vbs</ScriptName>
      
      
      <!-- Arguments specifies the arguments to pass into the script. -->
      <!-- A discovery script will always include $MPElement and $Target/ID$ in addition to any other values and variables the script requires. -->
      <Arguments>$MPElement$ $Target/Id$ $Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
      
      
      <!-- ScriptBody is the text of the script. In this case, a variable is used to specify the script file in the VSAE project -->
      <ScriptBody>$IncludeFileContent/DiscoverApplicationComponents.vbs$</ScriptBody>
      
      
      <!-- TimeoutSeconds is the seconds that the script must be running before it is automatically ended. -->
      <TimeoutSeconds>300</TimeoutSeconds>
      
  6. Save and Compile the Project:

    1. Select File, and then click Save Discoveries.mptg.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

See Also