How to create a recovery based on the output of a diagnostic

Applies To: System Center Operations Manager 2007

Note

This exercise has been updated to include a procedure for Visual Studio Authoring Extensions in the latest version of the Management Pack Authoring Guide on the TechNet Wiki.

The following procedure shows how to create a recovery in the Operations Manager 2007 Authoring console that runs after a diagnostic. The recovery only runs if the output from the diagnostic meets certain criteria. Before you perform these procedures, you must complete the following prerequisite procedures.

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.

To create 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, 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, make sure that MyMP.MyComputerRole1 is selected.

  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.

To create 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, make sure that MyMP.MyComputerRole1 is selected.

  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. Click Configure.

    6. Click Insert.

    7. In the Parameter column, type Diagnostic/DataItem/Property[@Name='Result'].

    8. In the Operator column, select Equals.

    9. In the Parameter column, type Positive.

    10. Click OK.

    11. Click OK.

    12. Under Actions, click Create.

    13. In the Choose Module Type box, select Microsoft.Windows.ScriptWriteAction.

    14. In the Module ID box, type Script, and then click OK.

    15. Click Edit.

    16. Click Configure.

    17. In the File Name box, type MyRecoveryScript.vbs.

    18. Paste the contents of the following script in 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
      
    19. Click Parameters.

    20. In the Parameters box, type $Data/Diagnostic/DataItem/Property[@Name='Result']$.

    21. Click OK.

    22. Click OK.

    23. Click OK.

    24. Click OK.

    25. Click OK.

See Also

Concepts

Diagnostics and Recoveries