WMI Events in MOM
Total Page:16
File Type:pdf, Size:1020Kb
Brian Wren Systems Management UNLOCKING THE MYSTERY OF WMI EVENTS IN MOM Microsoft Operations Manager (MOM) is a great tool for keeping an eye on your environment, but it can sometimes be tricky to monitor a particular activity. If the activity can be watched through the Windows event log or a counter in Performance Monitor, then it is relatively easy to create a corresponding To monitor WMI events in MOM, a WMI rule in MOM. If the activity cannot be monitored through one of these means, however, event provider is created to collect the ap- then a custom script is often needed. Such a script will typically be written to sample a propriate events generated on the monitored particular resource on a predefined schedule and generate an alert upon detecting that computer. An event processing rule uses this the defined activity occurred. provider to generate a MOM alert. For example, an application may rely on a Windows process that is not a Windows ser- vice. If this process ends unexpectedly, there likely wouldn’t be an event written to the Understanding WMI Windows event log or any other applica- In order to monitor WMI events in • Understanding the workings of WMI tion log. The only way to determine if this MOM, a basic understanding of WMI is re- • MOM classes for event notification process is still running is to execute a script quired. WMI is the Microsoft implementa- • Writing scripts to manipulate on a periodic basis to ensure that it is still tion of Web-Based Enterprise Management WMI objects healthy. Rather than writing a custom script (WBEM) as defined by the Distributed • Sample event queries to sample a resource periodically, you can Management Task Force (DMTF). It is take advantage of Windows Management the primary management technology for Brian Wren is a Principal Consultant with Microsoft Consulting AT A GLANCEAT Services in Southern California. In addition to architecting and de- Instrumentation (WMI) events. Virtually Windows operating systems, permitting ploying a variety of solutions for customers, he writes and speaks every interesting activity in Windows gen- management of a variety of computing regularly on management technologies. He can be reached at erates a WMI event, and MOM includes a resources using a common language and [email protected]. provider for monitoring all of them. common interfaces. You can write scripts 42 To get your FREE copy of TechNet Magazine subscribe at: www.microsoft.com/uk/technetmagazine with the WMI Scripting Library in order to inspect and modify computer resources Figure 1 Sample WMI Classes represented by WMI classes. Before you do, Class Description however, there are a number of WMI con- cepts that you should know. Win32_Process Processes running on a Windows computer Common Information Model (CIM) Win32_ComputerSystem A computer running a Windows operating system Repository The CIM repository is the WMI CIM_DataFile A file stored on a disk schema that stores the class definitions that MSFT_Alert An alert in MOM model WMI-managed resources. The re- pository holds the information required to Instance An instance is a unique occurrence __InstanceDelectionEvent, and __Instance- work with live resources in the computing of a particular class. For example, each service ModificationEvent. (Notice the double un- environment. It does not contain actual installed on a computer running Windows derscore characters at the beginning of each data about these resources since this data is is an instance of the Win32_Service class. name.) Extrinsic events are used to moni- dynamically retrieved as required. It is this The C: drive is an instance of the Win32_ tor resources that are not represented by schema that allows the wide variety of dif- LogicalDrive class. Figure 3 shows sample a WMI class. There is no common set of ferent resources to be uniformly managed. properties of one instance of the Win32_ extrinsic events, and individual ones must Namespaces CIM classes are organised service class. be implemented for a particular resource into namespaces. Each namespace in the WMI Events Just as each resource is identi- using them. CIM repository contains a logical group of fied by a WMI class, each type of WMI event The most common extrinsic events that related classes representing a specific tech- is represented by a class. When an event oc- would be used in MOM are for monitoring nology or area of management. Any time a curs, an instance of the corresponding WMI the registry. The registry must use extrin- connection is made to WMI, a namespace event class is created. The two types of WMI sic events since there is no WMI class for must be specified. Only the classes contained event classes that are used by MOM are in- individual registry settings (the intrinsic within this namespace may be accessed by trinsic and extrinsic. (Note that there is also events associated with the Win32_registry the connection. an event class type of Timer that is rarely class represent the registry as a whole). The The most important namespace for used. This type is not relevant to MOM so registry-related extrinsic events are Registry- Windows management is root\cimv2. It I won’t discuss it here.) KeyChangeEvent, RegistryTreeChangeEvent, contains the classes with the Win32_ pre- Intrinsic events are used to monitor re- and RegistryValueChangeEvent, and are lo- fix representing various components of the sources that have a WMI class. Each time an cated in the root\default namespace. Windows operating system and hosting instance of any such class is created, modi- Other applications may implement ex- computer. Examples include Win32_Process fied or deleted, an intrinsic event is gen- trinsic events that may be monitored. It is (running processes in Windows), Win32_ erated within the class’s namespace. The their responsibility to provide the names LogicalDisk (Windows logical disk drives), most common intrinsic event classes used and other information for these events. The and Win32_ComputerSystem (the computer in MOM are __InstanceCreationEvent, Application Center 2000 Management Pack, hosting Windows). This namespace also in- cludes the CIM_DataFile class which can be used to monitor files and folders. Two oth- Figure 2 Sample Properties of Win32_Service Class er important namespaces are root\default, Property Description which contains registry events, and root\ Name Unique name of the service MOM, which contains classes for accessing DisplayName Displayed name of the service MOM from external processes. PathName The command-line path that was executed to start the service Class Every resource that can be managed StartMode Startup type of the service (Auto, Manual, or Disabled) by WMI is defined by a class. A class is a template for each type of resource and de- State Current state of the service (Running, Stopping or Stopped) fines the properties that will be collected for that resource. Examples of common WMI Figure 3 Sample Properties of a Win32_Service Instance classes are shown in Figure 1. Property A property is a unique piece of in- Property Description formation about an instance. All instances Name Winmgmt of a class will have the same set of proper- DisplayName Windows Management Instrumentation ties although the values of each instance’s PathName C:\WINDOWS\system32\svchost.exe -k netsvcs properties may differ. Some Properties StartMode Auto of the Win32_Service class are shown in State Running Figure 2. TechNet Magazine October 2006 43 Systems Management namespace you will be using anyway. The namespace can be changed later by typing a new one into the textbox in the top left- hand corner of the UI. By default, you will be connecting to the local machine, but you may specify another computer by clicking on the computer button. Fortunately, WMI lets you connect to a remote repository as easily as to a local one. CIM Studio looks daunting when first started, and it does pro- vide a complete set of services for working with WMI, but for the purposes of this ar- ticle you won’t have to worry about most of that complexity. The simplest method of locating a class Figure 4 Class Search in CIM Studio is to search the repository. This is done by clicking on the binoculars button next to for example, has a number of WMI Event While all of these tools are useful, all the the namespace textbox (the result is shown Providers using these events. required functionality for the purposes of in Figure 4). This example returns a set of this article can be achieved with CIM Studio, classes that include the word “process” in WMI Tools which is designed to work with classes de- their name, including the class I’m inter- Tools for working with WMI include CIM fined in the CIM Repository. The first step ested in: Win32_Process. Selecting this Studio and Object Browser, which may be in using WMI events in MOM is determin- class will cause it to be displayed in the tree used to inspect the WMI repository and ing the class corresponding to the resource in the left pane. The details of the class will determine the appropriate class and related of interest, and CIM Studio may be used appear in the right pane (see Figure 5). The properties to monitor. The toolset, found for this purpose. most important information is the list of at go.microsoft.com/fwlink/?LinkId=70207 also in- When CIM Studio is started, you are re- properties. The property names may be cludes the WMI Event Viewer and WMI quired to connect to a namespace. This will used for specifying criteria in WMI notifi- Event Registration Editor. default to root\cimv2, which is typically the cation queries. In addition to the structure of the class, CIM Studio can display the instances of the class with their values for each proper- ty.