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





Overview

The following procedure shows how to create  a recovery that runs after a diagnostic using the Operations Manager 2007 Authoring console and Visual Studio Authoring Extensions.  The recovery only runs if the output from the diagnostic meets certain criteria.

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 the original revision.  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 diagnostic created in this procedure has the following characteristics:

  • Automatically runs when the MyMP.Monitor.MyApplicationEventError monitor goes to a critical state.
  • Runs a script that returns a single value in a property bag.
  • The script itself is only for testing and performs no real function. This script only simulates a script that gathers diagnostic data and returns that data in a property bag.

The recovery created in this procedure has the following characteristics:

  • Runs only when the value of the Result property in the property bag from the diagnostic is Positive.
  • Runs a script that writes an event to the OperationsManager event log on the agent and returns a message to the Operations console.
  • The value of the Result property in the property bag from the diagnostic is sent into the recovery script through an argument. This value is used in the event and the message created by the script.
  • The script itself is only for testing and performs no real function. This script only simulates a script that performs a recovery action and returns the results that are shown in an event and to the Operations console.

 


Authoring Console Procedure

Creating a diagnostic that runs a script

  1. In the Authoring Console, select Health Model, and then select Monitors.
  2. In the Monitors pane, expand MyMP.MyComputerRole1, and then expand System.Health.EntityState, and then expand System.Health.AvailabilityState.
  3. Right-click MyMP.Monitor.MyApplicationEventError and select Properties.
  4. Select the Diagnostic and Recovery tab.
  5. Under Configure diagnostic tasks, click Add and then Diagnostic for a critical health state.
  6. In the Choose a unique identifier box, type MyMP.MyApplicationEventError.ScriptDiagnostic and then click OK.
  7. On the General tab, do the following:
    1. In the Name box, type Run Diagnostic Script.
    2. In the Target box, select MyMP.MyComputerRole1.
  8. On the Configuration tab, do the following:
    1. In the Execute on monitor box, make sure that MyMP.Monitor.MyApplicationEventError is selected.
    2. In the Execute when monitor’s health is box, make sure that Error is selected.
  9. On the Modules tab, do the following:
    1. Under Actions, click Create.
    2. In the Choose Module Type box, select Microsoft.Windows.ScriptPropertyBagProbe.
    3. In the Module ID box, type Script. Click OK.
    4. Under Actions, click Edit.
    5. In the ScriptName box, type MyDiagnosticScript.vbs.
    6. In the Arguments box, clear the existing text.
    7. In the TimeoutSeconds box, type 300.
    8. Click Edit. This starts the external editor.
    9. Paste the contents of the following script between the ScriptBody tags in the XML. Replace any text that might already exist.

      bTestSuccessful = True
       
      Set oAPI = CreateObject("MOM.ScriptAPI")
      Set oBag = oAPI.CreatePropertyBag()
      If bTestSuccessful = True Then
         Call oBag.AddValue("Result","Positive")
      Else
         Call oBag.AddValue("Result","Negative")
      End If
      oAPI.Return(oBag)

    10. Close the external editor to save the script back to the module.
    11. Click OK.
    12. Click OK

 

Creating a recovery based on the output of a diagnostic

  1. Under Configure recovery tasks, click Add and then Recovery for a critical health state.
  2. In the Choose a unique identifier box, type MyMP.MyApplicationEventError.ScriptRecovery and then click OK.
  3. On the General tab, do the following:
    1. In the Name box, type Run Recovery Script.
    2. In the Target box, select MyMP.MyComputerRole1.
  4. On the Configuration tab, do the following:
    1. In the Execute on monitor box, make sure that MyMP.Monitor.MyApplicationEventError is selected.
    2. Select Execute after diagnostic
    3. Select MyMP.MyApplicationEventError.ScriptDiagnostic.
  5. On the Modules tab, do the following:
    1. Under Condition Detection, click Create.
    2. In the Choose Module Type box, select System.ExpressionFilter.
    3. In the Module ID box, type FilterDiagnostic. Click OK.
    4. Under Condition Detection, click Edit.
    5. In the Operator column, select Equals.
    6. In the Parameter column, type Positive.
    7. Click OK.
    8. Click OK.
    9. Under Actions, click Create.
    10. In the Choose Module Type box, select Microsoft.Windows.ScriptWriteAction.
    11. In the Module ID box, type Script, and then click OK.
    12. Click Edit.
    13. Click Configure.
    14. In the File Name box, type MyRecoveryScript.vbs.
    15. Paste the contents of the following script into the Script box:

      sDiagnosticOutput = WScript.Arguments(0)
       
      sMessage = "Recovery ran after diagnostic result of " & sDiagnosticOutput & "."
      Set oAPI = CreateObject("MOM.ScriptAPI")
      oAPI.LogScriptEvent "MyRecoveryScript.vbs",100,4,sMessage

    16. Click Parameters.
    17. In the Parameters box, type $Data/Diagnostic/DataItem/Property[@Name='Result']$.
    18. Click OK.
    19. Click OK.
    20. Click OK.
    21. Click OK.
    22. Click OK.

 


Visual Studio Authoring Extensions Procedure

Creating a diagnostic that runs a script

  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 MyDiagnosticScript.vbs and click Add.
    4. Copy the following code into the script:
      sDiagnosticOutput = WScript.Arguments(0)
       
      sMessage = "Recovery ran after diagnostic result of " & sDiagnosticOutput & "."
      Set oAPI = CreateObject("MOM.ScriptAPI")
      oAPI.LogScriptEvent "MyRecoveryScript.vbs",100,4,sMessage

  2. Create the Diagnostic:
    1. Right click Diagnostics.mpx and select Open.
    2. Add the following to the Diagnostics section of the XML:
      <Diagnostic ID="MyMP.MyApplicationEventError.ScriptDiagnostic" Accessibility="Internal" Enabled="true" Target="MyMP.MyComputerRole1" Monitor="MyMP.Monitor.MyApplicationEventError" ExecuteOnState="Error" Remotable="true" Timeout="300">
        <Category>Custom</Category>
        <ProbeAction ID="MyDiagnosticScript.vbs" TypeID="Windows!Microsoft.Windows.ScriptPropertyBagProbe">
          <ScriptName>MyDiagnosticScript.vbs</ScriptName>
          <Arguments />
          <ScriptBody>$IncludeFileContent/MyDiagnosticScript.vbs$</ScriptBody>
          <TimeoutSeconds>300</TimeoutSeconds>
        </ProbeAction>
      </Diagnostic>


    3. Add the following to the DisplayStrings section of the XML:
       

      <DisplayString ElementID="MyMP.MyApplicationEventError.ScriptDiagnostic">
        <Name>Run diagnostic script</Name>
        <Description />
      </DisplayString>


  3. Create the recovery 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 MyRecoveryScript.vbs and click Add.
    4. Copy the following code into the script:

      sDiagnosticOutput = WScript.Arguments(0)
       
      sMessage = "Recovery ran after diagnostic result of " & sDiagnosticOutput & "."
      Set oAPI = CreateObject("MOM.ScriptAPI")
      oAPI.LogScriptEvent "MyRecoveryScript.vbs",100,4,sMessage

  4. Create the Recovery:
    1. Add the following to the Monitoring section of the XML after the Diagnostics section:


      <Recoveries>
        <Recovery ID="MyMP.MyApplicationEventError.ScriptRecovery" Accessibility="Internal" Enabled="true" Target="MyMP.MyComputerRole1" Monitor="MyMP.Monitor.MyApplicationEventError" ResetMonitor="false" ExecuteOnDiagnostic="MyMP.MyApplicationEventError.ScriptDiagnostic" Remotable="true" Timeout="300">
          <Category>Custom</Category>
          <ConditionDetection ID="FilterDiagnostic" TypeID="System!System.ExpressionFilter">
            <Expression>
              <SimpleExpression>
                <ValueExpression>
                  <XPathQuery Type="String">Diagnostic/DataItem/Property[@Name='Result']</XPathQuery>
                </ValueExpression>
                <Operator>Equal</Operator>
                <ValueExpression>
                  <Value Type="String">Positive</Value>
                </ValueExpression>
              </SimpleExpression>
            </Expression>
          </ConditionDetection>
          <WriteAction ID="Script" TypeID="Windows!Microsoft.Windows.ScriptWriteAction">
            <ScriptName>MyRecoveryScript.vbs</ScriptName>
            <Arguments>$Data/Diagnostic/DataItem/Property[@Name='Result']$</Arguments>
            <ScriptBody>$IncludeFileContent/MyRecoveryScript.vbs$</ScriptBody>
            <TimeoutSeconds>300</TimeoutSeconds>
          </WriteAction>
        </Recovery>
      </Recoveries>


    2. Add the following to the DisplayStrings section of the XML:

      <DisplayString ElementID="MyMP.MyApplicationEventError.ScriptRecovery">
        <Name>Run recovery script</Name>
        <Description />
      </DisplayString>
  5. Save and Compile the Project:
    1. Select File, and then click Save Diagnostics.mpx.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

See Also