Share via


Management Pack Health Model Exercise #5 - Creating a WMI Event Monitor

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



Overview

The following procedure shows how to create a WMI event 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:

  • 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 #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:

  • Runs on any computer that has an instance of MyComputerRole1.
  • Sets the monitor to a critical state when Notepad is started on the agent computer.
  • Sets the monitor to a healthy state when Notepad is ended on the agent computer.

Authoring Console Procedure

  1. In the Authoring Console, select Health Model, and then select Monitors.
  2. In the Monitors pane, expand Computer Role 1 and then expand System.Health.EntityState.
  3. Right-click System.Health.AvailabilityState, select New, select WMI Events, select Simple, and then select Event Reset.
  4. On the General page, do the following:
    1. In the ElementID box**,** type MyMP.Monitor.MyApplicationWMIEventError.
    2. In the Display Name box, type MyApplication WMI Event Error.
    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 First WMI Event Provider page, do the following:
    1. In the WMI Namespace box, type root\cimv2.

    2. In the Query box, paste the following WMI query:

      Select * From __InstanceCreationEvent WITHIN 60 Where TargetInstance ISA 'Win32_Process' and TargetInstance.Name = 'notepad.exe'
      
      
    3. In the Poll Interval box, type 60.

    4. Click Next.

  6. On the First Expression page, do the following:
    1. Click Insert.
    2. In the Parameter Name box type Dummy.
    3. In the Operator box select Equals.
    4. In the Value box type Dummy.
    5. Click Next.
  7. On the Second WMI Event Provider page, do the following:
    1. In the WMI Namespace box, type root\cimv2

    2. In the Query box, paste the following WMI query:

      Select * From __InstanceDeletionEvent WITHIN 60 Where TargetInstance ISA 'Win32_Process' and TargetInstance.Name = 'notepad.exe'
      
      
    3. In the Poll Interval box, type 60.

    4. Click Next.

  8. On the Second Expression page, do the following:
    1. Click Insert.
    2. In the Parameter Name box type Dummy.
    3. In the Operator box select Equals.
    4. In the Value box type Dummy.
    5. Click Finish.
  9. Expand System.Health.AvailabilityState.
  10. Right-click MyMP.Monitor.MyApplicationWMIEventError and select Properties.
  11. On the Configuration tab, do the following:
    1. Click Configure.
    2. Select the First Expression tab.
    3. Click Delete.
    4. Select the Second Expression tab.
    5. Click Delete.
    6. Click OK.
  12. On the Health tab, for FirstEventRaised, change the Health State to Critical.
  13. On the Alerting page, do the following:
    1. Check Generate alerts for this monitor.
    2. In the Alert description box, type Stopped process: $Data/Context/Collection['TargetInstance']/Property[@Name='Caption']$ 
  14. Click OK.

Visual Studio Authoring Extensions Procedure

  1. 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.
  2. Configure the Monitor Properties:
    1. Right click the entry for NewUnitMonitor and select Properties Window.
    2. Change the ID to Monitor.MyApplicationWMIEventError.
    3. Change the Display Name to My Application WMI Event Monitor.
  3. Select the Monitor Target:
    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select ****MyMP.MyComputerRole1and 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 Microsoft.Windows.WmiEventProvider.2SingleEvent2StateMonitorType 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.

      
      
            <    FirstNameSpace    >root\cimv2</    FirstNameSpace    >  
            <    FirstQuery    >Select * From __InstanceCreationEvent WITHIN 60 Where TargetInstance ISA 'Win32_Process' and TargetInstance.Name = 'notepad.exe'</    FirstQuery    >  
            <    FirstPollInterval    >60</    FirstPollInterval    >  
            <    FirstExpression />
            <    SecondNameSpace    >root\cimv2</    SecondNameSpace    >  
            <    SecondQuery    >Select * From __InstanceDeletionEvent WITHIN 60 Where TargetInstance ISA 'Win32_Process' and TargetInstance.Name = 'notepad.exe'</    SecondQuery    >  
            <    SecondPollInterval    >60</    SecondPollInterval    >  
            <    SecondExpression />
      

             

    3. Select Monitor Operational States and click the ellipse (...) button on the right of the field.

    4. Next to FirstEventRaised, select Critical.

    5. Next to SecondEventRaised, select Healthy.

    6. Click OK,

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