Share via


How to Create Monitoring Data by Using a Script

Applies To: System Center 2012 - Operations Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

You can develop a custom runtime script to create monitoring data for use in a management pack. To create monitoring data, a script creates a MOMPropertyBag object, which stores a set of name-value pairs. After adding as many name-value pairs to the object as are needed, a script submits the data to a management server for processing.

To develop a monitoring script

  1. Create a new script in any script authoring environment. For more information about creating scripts, see Getting Started Developing Runtime Scripts.

  2. Create an instance of the Operations Manager scripting object (MOMScriptAPI).

  3. Create a new property bag instance by calling the scripting object's MOMScriptAPI.CreatePropertyBag method.

  4. Add any number of name-value pairs to the property bag by calling the MOMPropertyBag.AddValue method for each name-value pair.

  5. Submit the property bag to Operations Manager for processing by calling the scripting object's MOMScriptAPI.Return method.

  6. Add the script to a management pack. The management pack defines the script, configures the script's arguments, and defines how frequently the script runs. For more information, see How to Use Monitoring Data in a Management Pack.

Example

This section provides a simple example script that is written in VBScript. The example script reads the size of all files in a specified directory and creates a name-value pair for each file. The pair consists of the file's name and size (expressed in kilobytes (KB)). The script then submits the monitoring data to a management server for processing.

The script requires the following argument:

  • sPath—The directory containing the files whose size should be monitored.

The argument's value is passed to the script by the monitor, rule, or task that runs the script.

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

See Also

Concepts

Runtime Scripts Overview

Other Resources

Using Operations Manager Runtime Scripts
How to Use Runtime Scripts for Monitoring