Management Pack Health Model Exercise #13 - Creating a Script Based Event Collection Rule

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:

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

  1. In the Authoring Console, select Health Model, and then select Rules.
  2. Right-click in the Rules pane, select New, select Collection, select Performance Based, and then select Script Based Event Collection.
  3. On the General page, do the following:
    1. In the ElementID box, type MyMP.Rule.CollectScriptEvent.
    2. In the Display Name box, type My Application Collect Script Event.
    3. In the Target box, select MyMP.MyComputerRole1.
    4. In the Category box, select EventCollection. Click Next.
  4. On the Schedule page, in the Run every box, type 15 minutes.
  5. On the Script page, do the following:
    1. For the File Name value, type MyEventCollectionScript.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)
      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)
       

    4. Click the Parameters button.
    5. Select Target, select (Host=Windows Computer), and then select Principal Name (Windows Computer).
    6. Type a SPACE.
    7. Select Target and then Version (My Computer Role Base).
    8. Click OK.
    9. Click Next.
  6. On the Event Mapper page, do the following:
    1. In the Computer box type $Data/Property[@Name='ComputerName']$.
    2. In the Event Source box, type MyApp.
    3. In the Event Log box, type CustomScript.
    4.  In the Event ID box type $Data/Property[@Name='EventID']$.
    5. In the Category box type 0.
    6. In the Level box select Information.
    7. Click the Parameters button.
    8. Type $Data/Property[@Name='ParamValue']$.
    9. Click OK.
    10. Click Finish.

 


Visual Studio Authoring Extensions Procedure 

  1. Create the script:
    1. In Solution Explorer, right click 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 MyEventCollectionScript.vbs and click Add.
    4. Right-click MyEventCollectionScript.vbs and select Open.
    5. 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)

       
    6. Select File, and then click Save MyEventCollectionScript.vbs.
  2. Create the Rule:
    1. In Solution Explorer, right click Rules.mptg and then select Open.
    2. Right click in the  template window and select Add Template
    3. Select Rule (Event Collection).  
  3. Configure the Rule Properties:
    1. Right click the entry for NewEventCollectionRule and select Properties Window.
    2. Change the ID to Rule.CollectScriptEvent.
    3. Change the Display Name to My Application Collect Script Event.
  4. Select the Rule Target:
    1. Select Target and click the ellipse (...) button on the right of the field. 
    2. Select MyMP.MyComputerRole1 and click OK.
  5. Select the Rule modules:
    1. Select Data Sources and click the ellipse (...) button on the right of the field.
    2. Click Add
    3. Select Data Source Type ID and click the ellipse (...) button on the right of the field.
    4. Select Microsoft.Windows.TimedScript.EventProvider and click OK.
    5. Select Data Source Configuration and click the ellipse (...) button on the right of the field.
    6. 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>


    7. Click OK.
  6. Save and Compile the Project:
    1. Select File, and then click Save Rules.mptg.
    2. Select Build and then Build Solution.
    3. Ensure that you don't receive any errors.

See Also

Leave a Comment
  • Please add 5 and 6 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
Page 1 of 1 (1 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
Page 1 of 1 (1 items)