本文件已封存並已停止維護。

How to create a monitor based on a script

更新日期: 2010年4月

適用於: System Center Operations Manager 2007

The following procedure shows how to create a monitor based on a monitoring script in the Operations Manager 2007 Authoring console. Before you perform this procedure, you must first complete the prerequisite procedure How to Create a Class in which you create the target class.

The monitor created in this procedure has the following characteristics:

  • Runs on any computer with an instance of MyComputerRole1.

  • Sets the monitor to a critical state when the script returns a status message of Bad.

  • Sets the monitor to a healthy state when the script returns a status message of Good.

  • 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.

To create a script monitor

  1. In the Authoring Console, select Health Model, and then select Monitors.

  2. In the Monitors pane, expand Computer Role 1 and then System.Health.EntityState.

  3. Right click System.Health.AvailabilityState, select New, select Scripting and then select Two State.

  4. On the General page, do the following:

    1. In the ElementID box, type MyMP.Monitor.MyApplicationScriptMonitor.

    2. In the Display Name box, type My Application Script Monitor.

    3. In the Target box, select MyMP.MyComputerRole1.

    4. In the Parent Monitor box, select System.Health.AvailabilityState.

    5. In the Category box, select AvailabilityHealth. Click Next.

  5. On the Schedule page, in the Run every box, type 15 minutes. Click Next.

  6. On the Script page, do the following:

    1. For the File Name value, type MyScript.vbs

    2. For the Timeout value, type 1 minutes

    3. In the Script box, paste the complete contents of the following script.

      
      sComputerName = WScript.Arguments(0)
      bTestSuccessful = True
      
      Set oAPI = CreateObject("MOM.ScriptAPI")
      oAPI.LogScriptEvent "MyScript.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)
      
      
    4. Click the Parameters button.

    5. Select Target, then select (Host=Windows Computer), then select Principal Name (Windows Computer).

    6. Click OK.

    7. Click Next.

  7. On the Unhealthy Expression page, do the following:

    1. Click Insert.

    2. In the Parameter Name box type Property[@Name='Result'].

    3. In the Operator box select Equals.

    4. In the Value box type Bad.

    5. Click Next.

  8. On the Healthy Expression page, do the following:

    1. Click Insert.

    2. In the Parameter Name box type Property[@Name='Result'].

    3. In the Operator box select Equals.

    4. In the Value box type Good.

    5. Click Finish.

  9. Expand System.Health.AvailabilityState.

  10. Right click MyMP.Monitor.MyApplicationScriptMonitor and select Properties.

  11. On the Health tab, for Error, change the Health State to Critical.

  12. On the Alerting page, do the following:

    1. Check Generate alerts for this monitor

    2. In the Alert description box, type Result: $Data/Context/Property[@Name='Result']$

    3. Click OK.

另請參閱

顯示: