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


Table of Contents




Overview

The following procedure shows how to create a monitor based on a monitoring script using  the Operations Manager 2007 Authoring console and Visual Studio Authoring Extensions.

Product Versions

This exercise applies to the following products:

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

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 event monitor created in this procedure has the following characteristics:


Authoring Console Procedure

  1. In the Authoring Console, select Health Model, and then select Monitors.
  2. In the Monitors pane, expand My Application Component, and then expand 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, do the following:
    1. In the Run every box, type 15 minutes.
    2. 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 T>bTestSuccessful =
         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 Value box type Bad.
    4. 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 Value box type Good.
    4. 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']$ 
  13. Click OK.

Visual Studio Authoring Extensions Procedure

  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 MyScript.vbs and click Add.
    4. Right-click MyScript.vbsand select Open.
    5. Copy the following code into the script window:

      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)

    6. Select File, and then click Save MyScript.vbs.
  2. Create the Monitor:
    1. In Solution Explorer, right click Monitors.mptg and then select Open.
    2. Right click in the  template window and select Add Template.
    3. Change the name of the template to Monitors.mptg and click Add.
    4. Select Monitor (Unit) and click OK.
  3. Configure the Monitor Properties:
    1. Right click the entry for NewUnitMonitor and select Properties Window.
    2. Change the ID to Monitor.MyApplicationScriptMonitor.
    3. Change the Display Name to My Application Script Monitor.
  4. Select the Monitor Target:
    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyComputerRole1and click OK.
  5. Select the Monitor Type:
    1. Select Monitor Type ID and click the ellipse (...) button on the right of the field. 
    2. Select Microsoft.Windows.TimedScript.TwoStateMonitorType 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.
  6. 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.

      <IntervalSeconds>900</IntervalSeconds>
      <SyncTime />
      <ScriptName>MyScript.vbs</ScriptName>
      <Arguments>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
      <ScriptBody>$IncludeFileContent/MyScript.vbs$</ScriptBody>
      <SecureInput />
      <TimeoutSeconds>60</TimeoutSeconds>
      <ErrorExpression>
        <SimpleExpression>
      &s>$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Arguments>
      <ValueExpression>
            <XPathQuery Type="String">Property[@Name='Result']</XPathQuery>
          </ValueExpression>
          <Operator>Equal</Operator>
          <ValueExpression>
            <Value Type="String">Bad</Value>
          </ValueExpression>
        </SimpleExpression>
      </ErrorExpression>
      <SuccessExpression>
        <SimpleExpression>
          <ValueExpression>
            <XPathQuery Type="String">Property[@Name='Result']</XPathQuery>
          </ValueExpression>
          <Operator>Equal</Operator>
          <ValueExpression>
            <Value Type="String">Good</Value>
          </ValueExpression>
        </SimpleExpression>
      </SuccessExpression>


    3. Select Monitor Operational States and click the ellipse (...) button on the right of the field.
    4. Next to Error, select Critical.
    5. Next to Success, select Healthy.
    6. Click OK,
  7. Save and Compile the Project:
    1. Select File, and then click Save Monitors.mptg.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

See Also