This document is part of the Operations Manager Management Pack Authoring Guide





Overview

The following procedure shows how to create a monitor based on a custom data source module running a script in the Operations Manager 2007 Authoring console and Visual Studio Authoring Extensions. 

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 #6.  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

Sample Code

A sample of the completed code for each exercise is available in the TechNet Gallery.  There is a separate sample for each exercise that includes the management pack completed at the end of that exercise and each preceding exercise.  This strategy allows you to work through each exercise in order and then compare your results.  For VSAE, this also includes the Visual Studio solution. 

Details

The monitor created in this procedure has the following characteristics:

  • Targeted at a class with only a single instance on an agent. Because there is a single instance, there is no requirement to support cookdown.
  • Sets its state based on the comparison of the script value to specified threshold values.
  • The monitor supports On Demand Discovery. This requires a probe action module to run the script.
  • The script accepts only a single argument for the computer name of the target object’s agent.
  • The script itself is only for testing and performs no real function. It simulates a script running a synthetic transaction and returning a status message of success or failure.

 


Authoring Console Procedure

Create Probe Action Module to Run a Script

  1. In the Authoring Console, select Type Library and then Probe Actions.
  2. Right-click in the Probe Actions pane and select New and then Composite Probe Action.
  3. In the Choose a unique identifier box, type MyMP.ProbeActionModule.MyTransactionScript. Click OK
  4. On the General tab, do the following:
    1. In the Name box, type Transaction Script Probe Action.
  5. On the Member Modules tab, do the following:
    1. Click Add to add a module.
    2. In the Choose Module Type box, select Microsoft.Windows.ScriptPropertyBagProbe.
    3. In the Module ID box, type Script. Click OK.
    4. In the ScriptName box, type MyTransactionScript.vbs.
    5. In the Arguments box, type $Config/ComputerName$.
    6. In the TimeoutSeconds box, type 300.
    7. Click the Edit… button. This starts the custom editor.
    8. Paste the complete contents of the following script between the ScriptBody tags in the XML. Replace any text that might already exist:

      <![CDATA[
      sComputerName = WScript.Arguments(0)
      bTestSuccessful = True
       
      Set oAPI = CreateObject("MOM.ScriptAPI")
      oAPI.LogScriptEvent "MyTransactionScript.vbs",10,4, "Running script on " & sComputerName
      Set oBag = oAPI.CreatePropertyBag()
      Call oBag.AddValue("ComputerName",sComputerName)
      If bTestSuccessful = True Then
         Call oBag.AddValue("Result","Good")
      Else
         Call oBag.AddValue("Result","Bad")
      End If
      oAPI.Return(oBag)
      ]]>
       

    9. Close the editor to save the script back to the module.
    10. Click OK to save the module configuration.
    11. In the NextModule column for the Script module, select Module Output
  6. On the Configuration Schema tab, do the following:
    1. In the Simple Configuration Schema section, click Add to add a parameter.
    2. In the Please enter the requested value box, type ComputerName. Click OK.
  7.   On the Data Types tab, do the following:
    1. In the Input Data section, select This module required input data.
    2. In the Output Data section, in the Data Type: box select System.PropertyBagData.
  8. Click OK to save the module.
  9. Select File, and then click Save.

 

Create Data Source Module to Run Probe Action on Schedule

  1. Select Type Library and then Data Sources.
  2. Right-click the Data Sources pane, select New, and then Composite Data Source.
  3. In the Choose a unique identifier box, type MyMP.DataSourceModule.MyTransactionScriptTimed. Click OK
  4. On the General tab, do the following:
    1. In the Name box, type Timed Transaction Script Data Source.
  5. On the Member Modules tab, do the following:
    1. Click Add to add a module.
    2. In the Choose Module Type box, select System.SimpleScheduler.
    3. In the Module ID box, type Schedule. Click OK.
    4. Click the button to the right side of the IntervalSeconds box and select Promote. This enters the text $Config/IntervalSeconds$.
    5. Click the button to the right side of the SyncTime box and select Promote. This enters the text $Config/SyncTime$.
    6. Click OK to save the module configuration.
    7. Click Add to add a new module.
    8. In the Choose Module Type box, select MyMP.ProbeActionModule.MyTransactionScript.
    9. In the Module ID box, type Probe. Click OK.
    10. Select the button to the right side of the ComputerName box and select Promote. This enters the text $Config/ComputerName$.
    11. Click OK to save the module configuration.
    12. In the NextModule column for the Schedule module, select Probe.
    13. In the NextModule column for the Probe module, select Module Output
  6. On the Configuration Schema tab, do the following:
    1. Change the Type for the IntervalSeconds parameter to Integer.
    2. Clear the Required box next to the SyncTime parameter. The SyncTime parameter is optional for this module.
  7. On the Overrideable Parameters tab, do the following:
    1. Click Add and then IntervalSeconds.
    2. In the Choose a unique identifier box, type IntervalSeconds. Click OK.
    3. Change Configuration Element to Integer.
    4. Click Add and then SyncTime.
    5. In the Choose a unique identifier box, type SyncTime. Click OK.
  8. On the Data Types tab, do the following:
    1. Ensure the value in the Data Types box is System.PropertyBagData. 
  9. Click OK to save the module.
  10. Select File, and then click Save.

Create Custom Monitor Type Using Custom Data Source

  1. Select Type Library and then Monitor Types.
  2. Right-click in the Monitor Types pane and select New and then Composite Monitor Type.
  3. In the Choose a unique identifier box, type MyMP.MyTransactionMonitorType. Click OK
  4. On the General tab, do the following:
    1. In the Name box, type My Transaction Script Monitor Type.
  5. On the States tab, do the following:
    1. Select 2 State Monitor Type.
    2. In the ID of state 1 box type Success.
    3. In the ID of state 2 box, type Failure.  
  6. On the Member Modules tab, do the following:
    1. Click Add to add a module.
    2. In the Choose Module Type box, select System.PassThroughProbe.
    3. In the Module ID box, type PassThru. Click OK.
    4. Click OK to save the module configuration.
    5.  Click Add to add a module.
    6. In the Choose Module Type box, select MyMP.ProbeActionModule.MyTransactionScript.
    7. In the Module ID box, type Probe. Click OK.
    8. Click the button to the right of the ComputerName box and select Promote. This will enter the text $Config/ComputerName$.
    9. Click OK to save the module configuration.
    10. Click Add to add a new module.
    11. In the Choose Module Type box, select MyMP.DataSourceModule.MyTransactionScriptTimed.
    12. In the Module ID box, type DataSource. Click OK.
    13. Click the button to the right side of the IntervalSeconds box and select Promote . This enters the text $Config/IntervalSeconds$.
    14. Click the button to the right side of the ComputerName box and select Promote. This enters the text $Config/ComputerName$.
    15. Click Edit. This starts the custom editor.
    16. After the line:

      <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>

      add the following line:

      <SyncTime>$Config/SyncTime$</SyncTime>
    17.  Close the editor to add the XML back the Authoring console.  If you receive an error saying that the IntervalSeconds parameter is invalid according to its data type, click Ignore. This error message occurs because the IntervalSeconds parameter is configured as an integer, and the Authoring Console is reading $Config/IntervalSeconds$ as a string. This variable will be replaced with an integer value when the workflow is run so the error can be ignored.
    18. Click OK to save the module configuration.
    19. Click Add to add a new module.
    20. In the Choose Module Type box, select System.ExpressionFilter.
    21. In the Module ID box, type FilterSuccess. Click OK.
    22. Clear the Required box next to the SyncTime parameter. The SyncTime parameter is optional for this module.
    23. Click Configure to open the Expression dialog box.
    24. Click Insert.
    25. In the Parameter Name box type Property[@Name='Result'].
    26. In the Operator box select Equals.
    27. In the Value box type Good.
    28. Click OK to save the expression.
    29. Click OK to save the module configuration.
    30. Click Add to add a new module.
    31. In the Choose Module Type box, select System.ExpressionFilter.
    32. In the Module ID box, type FilterFailure. Click OK.
    33. Click Configure to open the Expression dialog box.
    34. Click Insert.
    35. In the Parameter Name box type Property[@Name='Result'].
    36. In the Operator box select Equals.
    37. In the Value box type Bad.
    38. Click OK to save the expression.
    39. Click OK to save the module configuration.
  7. On the Regular tab, do the following:
    1. Select Success.
    2. Check the Include box next to DataSource.
    3. Check the Include box next to FilterSuccess.
    4. In the Next Module box next to DataSource select FilterSuccess.
    5. In the Next Module box next to FilterSuccess select Monitor State Output.
    6. Select Failure.
    7. Check the Include box next to DataSource.
    8. Check the Include box next to FilterFailure.
    9. In the Next Module box next to DataSource select FilterFailure.
    10. In the Next Module box next to FilterFailure select Monitor State Output.
  8. On the On Demand tab, do the following:
    1. Check the box next to Use On Demand Detection.
    2. Select Success.
    3. Check the Include box next to PassThru.
    4. Check the Include box next to Probe.
    5. Check the Include box next to FilterSuccess.
    6. In the Next Module box next to PassThru select Probe.
    7. In the Next Module box next to Probe select FilterSuccess.
    8. In the Next Module box next to FilterSuccess select Monitor State Output.
    9. Select Failure.
    10. Check the Include box next to PassThru.
    11. Check the Include box next to Probe.
    12. Check the Include box next to FilterFailure.
    13. In the Next Module box next to PassThru select Probe.
    14. In the Next Module box next to Probe select FilterFailure.
    15. In the Next Module box next to FilterFailure select Monitor State Output.
  9. On the Configuration Schema tab, do the following:
    1. In the Type box next to IntervalSeconds select Integer.
    2. Click Add to add a parameter.
    3. In the Please enter the requested value box type SyncTime. Click OK.
    4. Clear the Required box next to SyncTime.
  10. On the Overrideable Parameters tab, do the following:
    1. Click Add, then IntervalSeconds.
    2. In the Choose a unique identifier box type IntervalSeconds. Click OK.
    3. In the Configuration Element box for IntervalSeconds, select Integer.
    4. Click Add, then SyncTime.
    5. In the Choose a unique identifier box, type SyncTime. Click OK.
  11. Click OK to save the module type.
  12. Select File, and then click Save.  

Create Monitor Based on Custom Monitor Type

  1. Select Health Model, then Monitors.
  2. In the Monitors pane, expand MyMP.MyComputerRole1 and System.Health.EntityState.
  3. Right-click System.Health.AvailabilityState, select New, and then Custom Unit Monitor
  4. In the Choose a unique identifier box, type MyMP.Monitor.MyTransactionMonitor. Click OK
  5. On the General tab, do the following:
    1. In the Name box, type My Transaction Monitor.
  6. On the Configuration tab, do the following:
    1. Click Browse for a type.
    2. In the Choose unit monitor type box, select MyMP.MyTransactionMonitorType. Click OK.
    3. In the IntervalSeconds box type 900.
    4. Clear the text in the ComputerName box. Click the button to the right side of the box, select (Host=Windows Computer), and then Principal Name (Windows Computer).
  7. On the Health tab, do the following:
    1. In the Health State box for Success select Healthy.
    2. In the Health State box for Failure select Critical.
  8. On the Alerting tab, do the following:
    1. Check the box next to Generate alerts for this monitor.
    2.  In the Generate an alert when, select The monitor is in a critical health state.
    3. In the Alert name: box, type Test transaction failed.
  9. Click OK to save the monitor.
  10. Select File, then click Save.

 


Visual Studio Authoring Extensions Procedure 

Create Probe Action Module to Run a Script

The Probe Action module contains the script itself and can be called from tasks and other modules. In the monitor, it is used for On Demand Detection which runs when the user selects Recalculate Health.

  1. Create the script:
    1. In Solution Explorer, right click the name of the solution, select Add and then select New Item.
    2. Select VBScript File.
    3. Change the name of the script to MyTransactionScript.vbs and click Add.
    4. Right-click MyTransactionScript.vbs and select Open.
    5. Copy the following code into the script window:

      sComputerName = WScript.Arguments(0)
      bTestSuccessful = True
        
      Set oAPI = CreateObject("MOM.ScriptAPI")
      oAPI.LogScriptEvent "MyTransactionScript.vbs",10,4, "Running script on " & sComputerName
      Set oBag = oAPI.CreatePropertyBag()
      Call oBag.AddValue("ComputerName",sComputerName)
      If bTestSuccessful = True Then
         Call oBag.AddValue("Result","Good")
      Else
         Call oBag.AddValue("Result","Bad")
      End If
      oAPI.Return(oBag)

       
    6. Select File, and then click Save MyEventCollectionScript.vbs.
  2. Create the Probe Action module. 
    1. In Solution Explorer, right click the Composition folder and then select New Item.
    2. Select Empty Management Pack Fragment.
    3. Change the name of the fragment to MyTransactionModules.mpx and click Add.
    4. Right-click MyTransactionModeules.mpx and select Open.  
    5. Copy the following XML into the configuration window between the <ManagementPackFragment> tags.  Note that you can use Intellisense to manually type in each entry.

      <TypeDefinitions>
        <ModuleTypes>
           
          <ProbeActionModuleType
            ID="MyMP.ProbeActionModule.MyTransactionScript"
            Accessibility="Internal"
            Batching="false"
            PassThrough="false">
            <Configuration>
              <xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
            </Configuration>
            <ModuleImplementation Isolation="Any">
              <Composite>
                <MemberModules>
                  <ProbeAction
                    ID="Script"
                    TypeID="Windows!Microsoft.Windows.ScriptProbeAction">
                    <ScriptName>MyTransactionScript.vbs</ScriptName>
                    <Arguments>$Config/ComputerName$</Arguments>
                    <ScriptBody>$IncludeFileContent/Composition/MyTransactionScript.vbs$</ScriptBody>
                    <TimeoutSeconds>300</TimeoutSeconds>
                  </ProbeAction>
                </MemberModules>
                <Composition>
                  <Node ID="Script" />
                </Composition>
              </Composite>
            </ModuleImplementation>
            <OutputType>System!System.PropertyBagData</OutputType>
            <InputType>System!System.BaseData</InputType>
          </ProbeActionModuleType>
           
        </ModuleTypes>
      </TypeDefinitions>

Create Data Source Module to Run Probe Action on Schedule

The Data Source module calls the probe action module on a schedule. This is used for Regular Detection where the monitor is constantly running on the agent.

  1. Copy the following XML into the configuration window between the <DataSourceModuleType> tag and the <ProbeActionModuleType> tag.  Note that you can use Intellisense to manually type in each entry.

    <DataSourceModuleType
      ID="MyMP.DataSourceModule.MyTransactionScriptTimed"
      Accessibility="Internal"
      Batching="false">
      <Configuration>
        <xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" />
        <xsd:element minOccurs="0" name="SyncTime" type="xsd:string" />
        <xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
      </Configuration>
      <OverrideableParameters>
        <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
        <OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
      </OverrideableParameters>
      <ModuleImplementation Isolation="Any">
        <Composite>
          <MemberModules>
            <DataSource ID="Schedule" TypeID="System!System.SimpleScheduler">
              <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
              <SyncTime>$Config/SyncTime$</SyncTime>
            </DataSource>
            <ProbeAction ID="Probe" TypeID="MyMP.ProbeActionModule.MyTransactionScript">
              <ComputerName>$Config/ComputerName$</ComputerName>
            </ProbeAction>
          </MemberModules>
          <Composition>
            <Node ID="Probe">
              <Node ID="Schedule" />
            </Node>
          </Composition>
        </Composite>
      </ModuleImplementation>
      <OutputType>System!System.PropertyBagData</OutputType>
    </DataSourceModuleType>

Create Custom Monitor Type Using Custom Data Source

The monitor type calls the data source module and defines the logic for determining different health states. 

  1. Create the Monitor Type.  This includes the health states and the configuration parameters for the monitor.  Copy the following XML into the configuration window after the ending </ModuleTypes> tag.  Note that you can use Intellisense to manually type in each entry:

     
    <UnitMonitorType ID="MyMP.MyTransactionMonitorType" Accessibility="Internal">
      <MonitorTypeStates>
        <MonitorTypeState ID="Success" NoDetection="false" />
        <MonitorTypeState ID="Failure" NoDetection="false" />
      </MonitorTypeStates>
      <Configuration>
        <xsd:element minOccurs="1" name="ComputerName" type="xsd:string" />
        <xsd:element minOccurs="1" name="IntervalSeconds" type="xsd:integer" />
        <xsd:element minOccurs="1" name="SyncTime" type="xsd:string" />
      </Configuration>
      <OverrideableParameters>
        <OverrideableParameter ID="IntervalSeconds" Selector="$Config/IntervalSeconds$" ParameterType="int" />
        <OverrideableParameter ID="SyncTime" Selector="$Config/SyncTime$" ParameterType="string" />
      </OverrideableParameters>
    </UnitMonitorType>

                 
  2. Add the Data Source Module to the Monitor Type.  The values of the configuration parameters provided by the monitor are passed to the module.  Copy the following XML into the configuration window after the ending </OverideableParameters> tag.  Note that you can use Intellisense to manually type in each entry:

     <MonitorImplementation>

      <MemberModules>
        <DataSource ID="DataSource" TypeID="MyMP.DataSourceModule.MyTransactionScriptTimed">
          <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds>
          <SyncTime>$Config/SyncTime$</SyncTime>
          <ComputerName>$Config/ComputerName$</ComputerName>
        </DataSource>
      </MemberModules>
    </MonitorImplementation>

     

  3. Add a Pass Through Probe module to the Monitor Type.  This module takes no parameters but is required for the On Demand detection since our probe action module is configured with PassThrough=False. Copy the following XML into the configuration window after the Data Source module.  Note that you can use Intellisense to manually type in each entry:

    <ProbeAction ID="PassThru" TypeID="System!System.PassThroughProbe" />

      

  4. Add the Probe module to the Monitor Type.  This is used by the On Demand Detection.  Copy the following XML into the configuration window after the PassThru module.  Note that you can use Intellisense to manually type in each entry:

     

    <ProbeAction ID="Probe" TypeID="MyMP.ProbeActionModule.MyTransactionScript">
      <ComputerName>$Config/ComputerName$</ComputerName>
    </ProbeAction>

  5. Add Condition Detection modules to the Monitor Type for each of the health states.  These include an expression that defines the criteria based on output from the script.  Copy the following XML into the configuration window after the PassThru module.  Note that you can use Intellisense to manually type in each entry:

     

    <ConditionDetection ID="FilterSuccess" TypeID="System!System.ExpressionFilter">
      <Expression>
        <SimpleExpression>
          <ValueExpression>
            <XPathQuery Type="String">Property[@Name='Result']</XPathQuery>
          </ValueExpression>
          <Operator>Equal</Operator>
          <ValueExpression>
            <Value Type="String">Good</Value>
          </ValueExpression>
        </SimpleExpression>
      </Expression>
    </ConditionDetection>
    <ConditionDetection ID="FilterFailure" TypeID="System!System.ExpressionFilter">
      <Expression>
        <SimpleExpression>
          <ValueExpression>
            <XPathQuery Type="String">Property[@Name='Result']</XPathQuery>
          </ValueExpression>
          <Operator>Equal</Operator>
          <ValueExpression>
            <Value Type="String">Bad</Value>
          </ValueExpression>
        </SimpleExpression>
      </Expression>
    </ConditionDetection>

     

  6. Add Regular Detection to the Monitor Type.  This defines the modules that are run to determine each health state.  The module in the innermost node is run first followed by the others in the detection. Copy the following XML into the configuration window after the closing </MemberModules> tag.  Note that you can use Intellisense to manually type in each entry:

    <RegularDetections>
      <RegularDetection MonitorTypeStateID="Success">
        <Node ID="FilterSuccess">
          <Node ID="DataSource" />
        </Node>
      </RegularDetection>
      <RegularDetection MonitorTypeStateID="Failure">
        <Node ID="FilterFailure">
          <Node ID="DataSource" />
        </Node>
      </RegularDetection>
    </RegularDetections>


  7. Add On Demand Detections to the Monitor Type.  This defines the modules that are run to determine each health state.  The module in the innermost node is run first followed by the others in the detection.  Copy the following XML into the configuration window after the closing </MemberModules> tag.  Note that you can use Intellisense to manually type in each entry:

    <OnDemandDetections>
      <OnDemandDetection MonitorTypeStateID="Success">
        <Node ID="FilterSuccess">
          <Node ID="Probe">
            <Node ID="PassThru" />
          </Node>
        </Node>
      </OnDemandDetection>
      <OnDemandDetection MonitorTypeStateID="Failure">
        <Node ID="FilterFailure">
          <Node ID="Probe">
            <Node ID="PassThru" />
          </Node>
        </Node>
      </OnDemandDetection>
    </OnDemandDetections>
               
               
  8. Save and Compile the Project:
    1. Select File, and then click Save MyTransactionModules.mptg.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

Create Monitor Based on Custom Monitor Type

  1. Create the Monitor:
    1. In Solution Explorer, right click the Composition folder, select Add and then select New Item.
    2. Select Monitor (Unit).
    3. Change the name of the template to Monitors.mptg and click Add.
  2. Configure the Monitor Properties:
    1. Right click the entry for NewUnitMonitor and select Properties Window.
    2. Change the ID to Monitor.MyTransactionMonitor.
    3. Change the Display Name to My Transaction Monitor.
  3. Select the Monitor Target:
    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyComputerRole1 and click OK.
  4. Select the Monitor Type:
    1. Select Monitor Type ID and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyTransactionMonitorType and click OK.
    3. Select Parent Monitor ID and click the ellipse (...) button on the right of the field.
    4. Select System.Health.AvailabilityState and click OK.
  5. Configure the Monitor:
    1. Select Monitor Configuration and click the ellipse (...) button on the right of the field.
    2. Copy the following XML into the configuration window between the <Configuration> tags.  Note that you can use Intellisense to manually type in each entry.
                     
      <ComputerName>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</ComputerName>
      <IntervalSeconds>900</IntervalSeconds>
      <SyncTime />
                     
    3. Select Monitor Operational States and click the ellipse (...) button on the right of the field.
    4. Next to Success, select Healthy.
    5. Next to Failure, select Critical.
    6. Click OK,
  6. Save and Compile the Project:
    1. Select File, and then click Save Rules.mptg.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

 

See Also