After creating a custom runtime script to collect monitoring data, you must add the script to a Management Pack. You can add a script to any of the following Management Pack elements:
- A data source module typeAdding a script to a data source
module type allows you to define configuration overrides and reuse
the script in different monitoring objects that are defined in the
Management Pack.
- A monitor (or monitor type), a rule, or a taskAdding a script
to a specific monitor, rule, or task allows you to use the script
only for that monitoring object.
A Management Pack that uses script-based monitoring data must also contain an element that maps the collected data to one of the following data types for storage in the Operations Manager database:
- Discovery
- Event
- Performance
- Alert
This data mapping can be performed by a data source module that includes a mapping component or by a specific monitoring object that uses a write action.
Example
The following examples show how to add a script to a Management Pack by editing the Management Pack's XML file. For information about how to add a script to a Management Pack by using the Operations Console, see the Operations Manager 2007 Help.
Example 1Defining a Monitor That Runs a Script
In this example, a Management Pack creates a monitor that runs a custom script at regular intervals. The script iterates through the files in a given directory and adds each file's name and size to a property bag that is stored in the Operations Manager database. The monitor indicates whether any file's size exceeds a specified threshold.
To create the monitor, the example Management Pack creates the following elements:
- A new data source module type, which contains the
script.
- A custom monitoring type, which uses a module of the new type
as its data source.
- A monitor of the custom monitoring type, which runs the script
at regular intervals.
The example Management Pack first creates the following data source module, of type Microsoft.Demo.Scripting.AppYComponent.FileSizeProvider, a custom type. For more information about the script used in this example, see How to Create Monitoring Data by Using a Script.
Copy Code | |
---|---|
<DataSourceModuleType ID="Microsoft.Demo.Scripting.AppYComponent.FileSizeProvider" Accessibility="Internal"> <Configuration> <xsd:element name="IntervalSeconds" type="xsd:integer"/> <xsd:element name="Path" type="xsd:string"/> <xsd:element name="FileName" type="xsd:string"/> </Configuration> <OverrideableParameters> <OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/> </OverrideableParameters> <ModuleImplementation> <Composite> <MemberModules> <DataSource ID="DS" TypeID="Windows!Microsoft.Windows.TimedScriptPerformanceProvider"> <IntervalSeconds>60</IntervalSeconds> <ScriptName>CollectAppYComponentFileSize.vbs</ScriptName> <Arguments>$Config/Path$</Arguments> <ScriptBody> <![CDATA[ Option Explicit Dim oAPI Set oAPI = CreateObject("MOM.ScriptAPI") ' Check for the required script arguments. Dim oArgs Set oArgs = WScript.Arguments if oArgs.Count < 1 Then ' If the script is called without the required arguments, ' create an information event, and then quit. Call oAPI.LogScriptEvent("CollectAppYComponentFileSize.vbs",101,0, _ "CollectAppYComponentFileSize script was called without any " _ & "arguments and was not executed. ") Wscript.Quit -1 End If Dim sPath sPath = oArgs(0) ' The path of the directory containing the files. Dim oFso, oFile, oFolder, oBag, oSize Set oFso = CreateObject("Scripting.FileSystemObject") if (oFso.FolderExists(sPath)) Then Set oBag = oAPI.CreatePropertyBag() Set oFolder = oFso.GetFolder(sPath) For Each oFile in oFolder.Files oSize = oFile.Size/1024 Call oBag.AddValue(oFile.Name, oSize) Next Call oAPI.Return(oBag) End If ]]> </ScriptBody> <TimeoutSeconds>20</TimeoutSeconds> ' The module uses the following elements to map ' values in the property bag to performance data ' stored in the Operations Manager database. <ObjectName>AppY</ObjectName> <CounterName>File Size</CounterName> <InstanceName>$Target/Property[Type='System!System.Entity']/DisplayName$</InstanceName> <Value>$Data/$Config/FileName$$</Value> </DataSource> </MemberModules> <Composition> <Node ID="DS"/> </Composition> </Composite> </ModuleImplementation> <OutputType>SystemPerf!System.Performance.LinkedData</OutputType> </DataSourceModuleType> |
The custom module type is based on the Microsoft.Windows.TimedScriptPerformanceProvider module type defined in the Microsoft.Windows.Library Management Pack. The TimedScriptPerformanceProvider accepts the following configuration elements that are used to run the script:
- IntervalSecondsThe length of time between each run of
the script.
- ScriptNameA user-defined script name with the required
.vbs or .js extension. To run the script, the agent creates a
temporary script file with the specified name, which is then
executed by CScript.exe (the command-line version of the Windows
Script Host).
- ArgumentsWhitespace-delimited values for any arguments
that are required by the script.
- ScriptBodyThe body of the script.
- TimeoutSecondsThe amount of time to allow the script to
run before terminating it.
The TimedScriptPerformanceProvider also includes a component that maps each name-value pair in the property bag to a performance data type that is stored in the Operations Manager database. To perform this mapping, the module's configuration accepts the following additional configuration elements:
- ObjectNameA user-defined name for the object for which
performance data is collected.
- CounterNameA user-defined name for the performance
data.
- InstanceNameA user-defined name for the entity that
generated the performance data.
- ValueThe value from the property bag data that is
converted to a performance data point.
The custom module type defines values for each of these required configuration elements. When defining the script's body, the module wraps the script in CDATA to ensure that any XML characters in the script that are not valid are not exposed in the Management Pack's XML filefor example, an ampersand or a greater than or less than symbol.
The custom module type also allows users of the Management Pack to override the value of the IntervalSeconds configuration element, which defines how frequently the monitoring script runs.
The Management Pack uses a data module of the custom type as a data source for a new monitoring type. The monitoring type defines two states for an AppYComponent file: GreaterThanThreshold or LessThanEqualThreshold. The type also defines conditions to compare the file size to the given threshold, which is specified when creating a monitor of this type.
Copy Code | |
---|---|
<MonitorTypes> <UnitMonitorType ID="Microsoft.Demo.Scripting.AppYComponent.FileSize.ThresholdMonitorType" Accessibility="Internal"> <MonitorTypeStates> <MonitorTypeState ID="GreaterThanThreshold"/> <MonitorTypeState ID="LessThanEqualThreshold"/> </MonitorTypeStates> <Configuration> <xsd:element name="IntervalSeconds" type="xsd:integer"/> <xsd:element name="Path" type="xsd:string"/> <xsd:element name="FileName" type="xsd:string"/> <xsd:element name="ThresholdKB" type="xsd:double"/> </Configuration> <OverrideableParameters> <OverrideableParameter ID="IntervalSeconds" ParameterType="int" Selector="$Config/IntervalSeconds$"/> </OverrideableParameters> <MonitorImplementation> <MemberModules> <!-- The monitor type uses the script-based module as its data source. --> <DataSource ID="DS" TypeID="Microsoft.Demo.Scripting.AppYComponent.FileSizeProvider"> <IntervalSeconds>$Config/IntervalSeconds$</IntervalSeconds> <Path>$Config/Path$</Path> <FileName>$Config/FileName$</FileName> </DataSource> <ConditionDetection ID="FilterLessThanEqual" TypeID="System!System.ExpressionFilter"> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="Double">Value</XPathQuery> </ValueExpression> <Operator>LessEqual</Operator> <ValueExpression> <Value Type="Double">$Config/ThresholdKB$</Value> </ValueExpression> </SimpleExpression> </Expression> </ConditionDetection> <ConditionDetection ID="FilterGreaterThan" TypeID="System!System.ExpressionFilter"> <Expression> <SimpleExpression> <ValueExpression> <XPathQuery Type="Double">Value</XPathQuery> </ValueExpression> <Operator>Greater</Operator> <ValueExpression> <Value Type="Double">$Config/ThresholdKB$</Value> </ValueExpression> </SimpleExpression> </Expression> </ConditionDetection> </MemberModules> <RegularDetections> <RegularDetection MonitorTypeStateID="GreaterThanThreshold"> <Node ID="FilterGreaterThan"> <Node ID="DS"/> </Node> </RegularDetection> <RegularDetection MonitorTypeStateID="LessThanEqualThreshold"> <Node ID="FilterLessThanEqual"> <Node ID="DS"/> </Node> </RegularDetection> </RegularDetections> </MonitorImplementation> </UnitMonitorType> </MonitorTypes> |
The Management Pack uses the new monitor type to define a new monitor. The monitor associates each of the monitor type's states with a corresponding health state. If the file's size is less than or equal to a given threshold, the monitor sets the file's health state to "Success." If the file's size is greater than a given threshold, the monitor sets the file's health state to "Error" and generates an alert. When defining the configuration values required by the monitor's type, the monitor sets the file's threshold to 100 KB.
Copy Code | |
---|---|
<Monitors> <UnitMonitor ID="Microsoft.Demo.Scripting.AppYComponent.FileSizeMonitor" Target="Microsoft.Demo.Scripting.AppYComponent" TypeID="Microsoft.Demo.Scripting.AppYComponent.FileSize.ThresholdMonitorType" Enabled="true" Remotable="false" ParentMonitorID="SystemHealth!System.Health.PerformanceState" Accessibility="Internal"> <Category>PerformanceHealth</Category> <AlertSettings> <AlertOnState>Error</AlertOnState> <AutoResolve>true</AutoResolve> <AlertPriority>Normal</AlertPriority> </AlertSettings> <OperationalStates> <OperationalState HealthState="Success" MonitorTypeStateID="LessThanEqualThreshold" ID="FileSizeOK"/> <OperationalState HealthState="Error" MonitorTypeStateID="GreaterThanThreshold" ID="FileSizeTooBig"/> </OperationalStates> <Configuration> <IntervalSeconds>60</IntervalSeconds> <Path>$Target/Host/Property[Type='Microsoft.Demo.Scripting.AppY']/Path$</Path> <FileName>$Target/Property[Type='Microsoft.Demo.Scripting.AppYComponent']/FileName$</FileName> <ThresholdKB>100.0</ThresholdKB> </Configuration> </UnitMonitor> </Monitors> |
Example 2Defining a Rule that Runs a Script
In this example, a Management Pack creates a rule that runs a custom script by using the same data source as defined in example 1.
Copy Code | |
---|---|
<Rule ID="Microsoft.Demo.Scripting.AppYComponent.GetFileSizeAsPerf" Target="Microsoft.Demo.Scripting.AppYComponent" Enabled="true" Remotable="false"> <Category>PerformanceHealth</Category> <DataSources> <DataSource ID="DS" TypeID="Microsoft.Demo.Scripting.AppYComponent.FileSizeProvider"> <IntervalSeconds>60</IntervalSeconds> <Path>$Target/Host/Property[Type='Microsoft.Demo.Scripting.AppY']/Path$</Path> <FileName>$Target/Property[Type='Microsoft.Demo.Scripting.AppYComponent']/FileName$</FileName> </DataSource> </DataSources> <WriteActions> <WriteAction ID="WriteToDB" TypeID="SC!Microsoft.SystemCenter.CollectPerformanceData"/> </WriteActions> </Rule> |
The rule uses a write action to map the property bag data to a performance data type that is stored in the Operations Manager database.
See Also
Send comments about this topic to Microsoft.