Management Pack Health Model Exercise #13 - Creating a Script Based Event Collection Rule
This document is part of the Operations Manager Management Pack Authoring Guide .
Overview
The following procedure shows how to create an event collection rule by using a monitoring script in 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 rule.
- Creating a Delimited Text Log Alerting Rule - Create the rule template group (VSAE only)
- Creating a WMI Performance Collection Rule - Add the reference for the Data Warehouse Library (VSAE only)
Revisions
The Microsoft System Center team has validated this procedure as of the original revision. 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 rule created in this procedure has the following characteristics:
- Runs on any computer that has an instance of MyComputerRole1.
- The script accepts two parameters, one for computer name and another for the version of the application that is stored as a property on the target class.
- The script itself is only for testing and performs no real function. It simulates a script running a synthetic transaction and returning a property bag with static values.
Authoring Console Procedure
- In the Authoring Console, select Health Model, and then select Rules.
- Right-click in the Rules pane, select New, select Collection, select Performance Based, and then select Script Based Event Collection.
- On the General page, do the following:
- In the ElementID box, type MyMP.Rule.CollectScriptEvent.
- In the Display Name box, type My Application Collect Script Event.
- In the Target box, select MyMP.MyComputerRole1.
- In the Category box, select EventCollection. Click Next.
- On the Schedule page, in the Run every box, type 15 minutes.
- On the Script page, do the following:
For the File Name value, type MyEventCollectionScript.vbs.
For the Timeout value, type 1 minutes.
In the Script box, paste the complete contents of the following script.
sComputerName = WScript.Arguments(0) sVersion = WScript.Arguments(1) Set oAPI = CreateObject("MOM.ScriptAPI") Set oBag = oAPI.CreatePropertyBag() Call oBag.AddValue("ComputerName",sComputerName) Call oBag.AddValue("EventID",100) Call oBag.AddValue("ParamValue","Param1") oAPI. Return (oBag)
Click the Parameters button.
Select Target, select (Host=Windows Computer), and then select Principal Name (Windows Computer).
Type a SPACE.
Select Target and then Version (My Computer Role Base).
Click OK.
Click Next.
- On the Event Mapper page, do the following:
- In the Computer box type $Data/Property[@Name='ComputerName']$.
- In the Event Source box, type MyApp.
- In the Event Log box, type CustomScript.
- In the Event ID box type $Data/Property[@Name='EventID']$.
- In the Category box type 0.
- In the Level box select Information.
- Click the Parameters button.
- Type $Data/Property[@Name='ParamValue']$.
- Click OK.
- Click Finish.
Visual Studio Authoring Extensions Procedure
- Create the script:
In Solution Explorer, right click Right click the name of the solution, select Add and then select New Item..
Select VBScript File.
Change the name of the script to MyEventCollectionScript.vbs and click Add.
Right-click MyEventCollectionScript.vbs and select Open.
Copy the following code into the script window:
sComputerName = WScript.Arguments(0) sVersion = WScript.Arguments(1) Set oAPI = CreateObject("MOM.ScriptAPI") Set oBag = oAPI.CreatePropertyBag() Call oBag.AddValue("ComputerName",sComputerName) Call oBag.AddValue("EventID",100) Call oBag.AddValue("ParamValue","Param1") oAPI.Return(oBag)
Select File, and then click Save MyEventCollectionScript.vbs.
- Create the Rule:
- In Solution Explorer, right click Rules.mptg and then select Open.
- Right click in the template window and select Add Template.
- Select Rule (Event Collection).
- Configure the Rule Properties:
- Right click the entry for NewEventCollectionRule and select Properties Window.
- Change the ID to Rule.CollectScriptEvent.
- Change the Display Name to My Application Collect Script Event.
- Select the Rule Target:
- Select Target and click the ellipse (...) button on the right of the field.
- Select MyMP.MyComputerRole1 and click OK.
- Select the Rule modules:
Select Data Sources and click the ellipse (...) button on the right of the field.
Click Add.
Select Data Source Type ID and click the ellipse (...) button on the right of the field.
Select Microsoft.Windows.TimedScript.EventProvider and click OK.
Select Data Source 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.
< IntervalSeconds >900</ IntervalSeconds > < SyncTime /> < ScriptName >MyEventCollectionScript.vbs</ ScriptName > < Arguments >$Target/Host/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$ $Target/Property[Type="MyMP.MyComputerRoleBase"]/Version$</ Arguments > < ScriptBody >$IncludeFileContent/MyEventCollectionScript.vbs$</ ScriptBody > < TimeoutSeconds >60</ TimeoutSeconds > < EventOriginId >$MPElement$</ EventOriginId > < PublisherId >$MPElement$</ PublisherId > < PublisherName >MyApp</ PublisherName > < Channel >CustomScript</ Channel > < LoggingComputer >$Data/Property[@Name='ComputerName']$</ LoggingComputer > < EventNumber >$Data/Property[@Name='EventID']$</ EventNumber > < EventCategory /> < EventLevel >4</ EventLevel > < UserName /> < Params > < Param >$Data/Property[@Name='ParamValue']$</ Param > </ Params >
Click OK.
- Save and Compile the Project:
- Select File, and then click Save Rules.mptg.
- Select Build and then Build Solution.
- Ensure that you don't receive any errors.