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:
- Creating a New Management Pack - Create the management pack.
- Creating a Class - Create the class that is the target for the monitor.
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
- In the Authoring Console, select Health Model, and then select Monitors.
- In the Monitors pane, expand Computer Role 1 and then expand System.Health.EntityState.
- Right-click System.Health.AvailabilityState, select New, select WMI Events, select Simple, and then select Event Reset.
- On the General page, do the following:
- In the ElementID box**,** type MyMP.Monitor.MyApplicationWMIEventError.
- In the Display Name box, type MyApplication WMI Event Error.
- In the Target box, select MyMP.MyComputerRole1.
- In the Parent Monitor box, select System.Health.AvailabilityState.
- In the Category box, select AvailabilityHealth. Click Next.
- On the First WMI Event Provider page, do the following:
In the WMI Namespace box, type root\cimv2.
In the Query box, paste the following WMI query:
Select * From __InstanceCreationEvent WITHIN 60 Where TargetInstance ISA 'Win32_Process' and TargetInstance.Name = 'notepad.exe'
In the Poll Interval box, type 60.
Click Next.
- On the First Expression page, do the following:
- Click Insert.
- In the Parameter Name box type Dummy.
- In the Operator box select Equals.
- In the Value box type Dummy.
- Click Next.
- On the Second WMI Event Provider page, do the following:
In the WMI Namespace box, type root\cimv2.
In the Query box, paste the following WMI query:
Select * From __InstanceDeletionEvent WITHIN 60 Where TargetInstance ISA 'Win32_Process' and TargetInstance.Name = 'notepad.exe'
In the Poll Interval box, type 60.
Click Next.
- On the Second Expression page, do the following:
- Click Insert.
- In the Parameter Name box type Dummy.
- In the Operator box select Equals.
- In the Value box type Dummy.
- Click Finish.
- Expand System.Health.AvailabilityState.
- Right-click MyMP.Monitor.MyApplicationWMIEventError and select Properties.
- On the Configuration tab, do the following:
- Click Configure.
- Select the First Expression tab.
- Click Delete.
- Select the Second Expression tab.
- Click Delete.
- Click OK.
- On the Health tab, for FirstEventRaised, change the Health State to Critical.
- On the Alerting page, do the following:
- Check Generate alerts for this monitor.
- In the Alert description box, type Stopped process: $Data/Context/Collection['TargetInstance']/Property[@Name='Caption']$
- Click OK.
Visual Studio Authoring Extensions Procedure
- Create the Monitor:
- In Solution Explorer, right click Monitors.mptg and then select Open.
- Right click in the template window and select Add Template.
- Change the name of the template to Monitors.mptg and click Add.
- Select Monitor (Unit) and click OK.
- Configure the Monitor Properties:
- Right click the entry for NewUnitMonitor and select Properties Window.
- Change the ID to Monitor.MyApplicationWMIEventError.
- Change the Display Name to My Application WMI Event Monitor.
- Select the Monitor Target:
- Select Target and click the ellipse (...) button on the right of the field.
- Select ****MyMP.MyComputerRole1and click OK.
- Select the Monitor Type:
- Select Monitor Type ID and click the ellipse (...) button on the right of the field.
- Select Microsoft.Windows.WmiEventProvider.2SingleEvent2StateMonitorType and click OK.
- Select Parent Monitor ID and click the ellipse (...) button on the right of the field.
- Select System.Health.AvailabilityState and click OK.
- Configure the Monitor:
Select Monitor Configuration and click the ellipse (...) button on the right of the field.
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 />
Select Monitor Operational States and click the ellipse (...) button on the right of the field.
Next to FirstEventRaised, select Critical.
Next to SecondEventRaised, select Healthy.
Click OK,
- Save and Compile the Project:
- Select File, and then click Save Monitors.mptg.
- Select Build and then Build Solution.
- Ensure that you don't receive any errors.