How to Create a Management Pack
Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007
You can use the Operations Manager class libraries to create a Management Pack and add it to a Management Group.
The following code example demonstrates how to create a Management Pack. This example creates a Management Pack for a router and the ports that the router uses. A ManagementPackClass object is created for the router and the ports, and the ManagementPackRelationship class is used to set up a relationship that shows that the router hosts the ports. The Management Pack that is created references types in the following set of Management Packs, so these Management Packs must be installed for the example code to run correctly:
C:\Program Files\System Center Operations Manager 2007\System.Library.mp
C:\Program Files\System Center Operations Manager 2007\Microsoft.SystemCenter.Library.mp
C:\Program Files\System Center Operations Manager 2007\System.Health.Library.mp
The Management Pack is saved to an XML file after it is created.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Configuration.IO;
namespace MPCreation
{
class Program
{
static void Main(string[] args)
{
MPCreator mpCreator = new MPCreator();
mpCreator.AddReferences();
mpCreator.AddClasses();
mpCreator.AddRelationships();
mpCreator.AddViews();
mpCreator.AddTasks();
mpCreator.AddRules();
mpCreator.AddMonitorType();
mpCreator.SaveMPToDisk(@"C:\");
}
}
class MPCreator
{
ManagementPack m_mp;
ManagementPack m_libraryMp;
ManagementPack m_windowsLibraryMp;
ManagementPack m_healthLibraryMp;
ManagementPackFileStore m_mpStore;
ManagementPackClass m_routerClass;
ManagementPackClass m_portClass;
ManagementPackUnitMonitorType m_unitMonitorType;
//---------------------------------------------------------------------
public MPCreator()
{
m_mpStore = new ManagementPackFileStore();
m_mpStore.AddDirectory(@"C:\Program Files\System Center Operations Manager 2007");
m_mp = new ManagementPack("SampleMP", "Sample Management Pack", new Version(1, 0), m_mpStore);
m_libraryMp = new ManagementPack(@"C:\Program Files\System Center Operations Manager 2007\System.Library.mp", m_mpStore);
m_windowsLibraryMp = new ManagementPack(@"C:\Program Files\System Center Operations Manager 2007\Microsoft.SystemCenter.Library.mp", m_mpStore);
m_healthLibraryMp = new ManagementPack(@"C:\Program Files\System Center Operations Manager 2007\System.Health.Library.mp", m_mpStore);
m_mp.Description = "Sample Description";
m_mp.DisplayName = "Sample Management Pack";
m_mp.DefaultLanguageCode = "ENU";
}
//---------------------------------------------------------------------
public void AddClasses()
{
m_routerClass = new ManagementPackClass(m_mp,
"SampleMP.Router",
ManagementPackAccessibility.Public);
m_portClass = new ManagementPackClass(m_mp,
"SampleMP.Port",
ManagementPackAccessibility.Public);
m_routerClass.Abstract = false;
m_routerClass.Base = m_libraryMp.GetClass("System.NetworkDevice");
m_portClass.Abstract = false;
m_portClass.Hosted = true;
m_portClass.Base = m_libraryMp.GetClass("System.LogicalEntity");
AddRouterClassProperties();
AddPortClassProperties();
}
//---------------------------------------------------------------------
public void AddRelationships()
{
ManagementPackRelationship routerHostsPort;
routerHostsPort = new ManagementPackRelationship(m_mp,
"SampleMP.RouterHostsPort",
ManagementPackAccessibility.Public);
routerHostsPort.Abstract = false;
routerHostsPort.Base = m_libraryMp.GetRelationship("System.Hosting");
routerHostsPort.Description = "Defines the hosting relationship between a router and its ports";
routerHostsPort.DisplayName = "Router Hosts Port";
routerHostsPort.Source = m_routerClass;
routerHostsPort.Target = m_portClass;
routerHostsPort.Status = ManagementPackElementStatus.PendingAdd;
}
//---------------------------------------------------------------------
public void AddReferences()
{
m_mp.References.Add("SCLibrary", new ManagementPackReference(m_libraryMp));
m_mp.References.Add("SCWinLibrary", new ManagementPackReference(m_windowsLibraryMp));
m_mp.References.Add("SCHealth", new ManagementPackReference(m_healthLibraryMp));
}
//---------------------------------------------------------------------
public void AddViews()
{
ManagementPackFolderItem routerStateFolderItem;
ManagementPackFolder viewFolder;
ManagementPackView routerStateView;
routerStateView = new ManagementPackView(m_mp,"SampleMP.RouterStateView",ManagementPackAccessibility.Public);
viewFolder = new ManagementPackFolder(m_mp, "SampleMP.ViewFolder", ManagementPackAccessibility.Public);
viewFolder.Description = "Sample MP View Folder";
viewFolder.DisplayName = "Sample MP";
viewFolder.Status = ManagementPackElementStatus.PendingAdd;
viewFolder.ParentFolder = m_windowsLibraryMp.GetFolder("Microsoft.SystemCenter.Monitoring.ViewFolder.Root");
routerStateView.Target = m_routerClass;
routerStateView.TypeID = m_windowsLibraryMp.GetViewType("Microsoft.SystemCenter.StateViewType");
routerStateView.Description = "Router State View";
routerStateView.DisplayName = "Router State View";
routerStateView.Category = "Operations";
routerStateView.Configuration = @"<Criteria><InMaintenanceMode>false</InMaintenanceMode></Criteria>";
routerStateFolderItem = new ManagementPackFolderItem(routerStateView, viewFolder);
routerStateFolderItem.Status = ManagementPackElementStatus.PendingAdd;
routerStateView.Status = ManagementPackElementStatus.PendingAdd;
}
//---------------------------------------------------------------------
public void AddTasks()
{
ManagementPackTask task;
ManagementPackProbeActionModule probeAction;
task = new ManagementPackTask(m_mp, "ResetRouter", ManagementPackAccessibility.Public);
probeAction = new ManagementPackProbeActionModule(task, "ResetRouterProbe");
task.Description = "Resets a router";
task.DisplayName = "Reset Router";
task.Target = m_routerClass;
task.Status = ManagementPackElementStatus.PendingAdd;
task.ProbeAction = probeAction;
probeAction.TypeID = (ManagementPackProbeActionModuleType)m_libraryMp.GetModuleType("System.CommandExecuterProbe");
probeAction.Configuration = @"<ApplicationName>%WINDIR%\System32\NET.EXE</ApplicationName><WorkingDirectory/><CommandLine>USER</CommandLine><TimeoutSeconds>30</TimeoutSeconds><RequireOutput>true</RequireOutput><Files/>";
}
public void AddRules()
{
ManagementPackDataSourceModule sdkEventDS;
ManagementPackWriteActionModule writeEventToDBMWA;
ManagementPackConditionDetectionModule conditionDetection;
ManagementPackRule rule;
rule = new ManagementPackRule(m_mp, "CollectEventsRule");
writeEventToDBMWA = new ManagementPackWriteActionModule(rule, "WriteToDB");
writeEventToDBMWA.TypeID = (ManagementPackWriteActionModuleType)m_windowsLibraryMp.GetModuleType("Microsoft.SystemCenter.CollectEvent");
writeEventToDBMWA.Description = "Write Event to DB";
writeEventToDBMWA.DisplayName = "Write Event to DB";
sdkEventDS = new ManagementPackDataSourceModule(rule, "CollectSDKEvent");
sdkEventDS.TypeID = (ManagementPackDataSourceModuleType)m_windowsLibraryMp.GetModuleType("Microsoft.SystemCenter.SdkEventProvider");
sdkEventDS.DisplayName = "Collect SDK Event";
sdkEventDS.Description = "Collect SDK Event";
conditionDetection = new ManagementPackConditionDetectionModule(rule, "EventConditionDetection");
conditionDetection.TypeID = (ManagementPackConditionDetectionModuleType)m_libraryMp.GetModuleType("System.ExpressionFilter");
conditionDetection.Configuration = @"<Expression><SimpleExpression><ValueExpression><XPathQuery>EventNumber</XPathQuery></ValueExpression><Operator>Equal</Operator><ValueExpression><Value>1</Value></ValueExpression></SimpleExpression></Expression>";
rule.ConfirmDelivery = true;
rule.Description = "Collect Events Rule";
rule.DisplayName = "Collect Router Events";
rule.Priority = ManagementPackWorkflowPriority.Normal;
rule.Target = m_routerClass;
rule.DataSourceCollection.Add(sdkEventDS);
rule.WriteActionCollection.Add(writeEventToDBMWA);
rule.ConditionDetection = conditionDetection;
rule.Status = ManagementPackElementStatus.PendingAdd;
}
//---------------------------------------------------------------------
private void AddRouterClassProperties()
{
AddPropertyToClass("Id",
"Id",
"Contains the Id of the router",
true,
false,
1,
ManagementPackEntityPropertyTypes.@string,
m_routerClass);
AddPropertyToClass("Name",
"Name",
"Contains the name of the router",
false,
false,
1,
ManagementPackEntityPropertyTypes.@string,
m_routerClass);
AddPropertyToClass("ModelNumber",
"Model Number",
"Contains the model number of the router",
false,
false,
1,
ManagementPackEntityPropertyTypes.@string,
m_routerClass);
m_routerClass.Status = ManagementPackElementStatus.PendingAdd;
}
//---------------------------------------------------------------------
private void AddPortClassProperties()
{
AddPropertyToClass("Id",
"Id",
"Contains the Id of the port",
true,
false,
1,
ManagementPackEntityPropertyTypes.@string,
m_portClass);
AddPropertyToClass("PortType",
"Port Type",
"Contains the type of the port",
false,
false,
1,
ManagementPackEntityPropertyTypes.@string,
m_portClass);
AddPropertyToClass("PortStatus",
"Port Status",
"Determines whether the port is on or off",
false,
false,
1,
ManagementPackEntityPropertyTypes.@string,
m_portClass);
m_portClass.Status = ManagementPackElementStatus.PendingAdd;
}
//---------------------------------------------------------------------
internal void SaveMPToDisk(string directoryName)
{
ManagementPackXmlWriter mpXmlWriter = new ManagementPackXmlWriter(directoryName);
m_mp.AcceptChanges();
mpXmlWriter.WriteManagementPack(m_mp);
Console.WriteLine("Management pack created in the " + directoryName + m_mp.Name + ".xml file.");
}
//---------------------------------------------------------------------
private void AddPropertyToClass(
string name,
string displayName,
string description,
bool isKey,
bool isCaseSensitive,
int minLength,
ManagementPackEntityPropertyTypes type,
ManagementPackClass mpClass
)
{
ManagementPackClassProperty property = new ManagementPackClassProperty(mpClass, name);
property.CaseSensitive = isCaseSensitive;
property.Description = description;
property.Type = type;
property.MinLength = minLength;
property.Key = isKey;
property.DisplayName = displayName;
mpClass.PropertyCollection.Add(property);
}
internal void AddMonitorType()
{
ManagementPackConfigurationSchemaType monitorSchemaType = new ManagementPackConfigurationSchemaType();
ManagementPackModuleTypeReference dsRef;
ManagementPackModuleTypeReference conditionDetectionUnderThresholdRef;
ManagementPackModuleTypeReference conditionDetectionOverThresholdRef;
ManagementPackMonitorTypeState underThresholdState;
ManagementPackMonitorTypeState overThresholdState;
ManagementPackMonitorTypeDetection underThresholdDetection;
ManagementPackMonitorTypeDetection overThresholdDetection;
ManagementPackModuleCompositionNodeType dataSourceNodeType;
m_unitMonitorType = new ManagementPackUnitMonitorType(m_mp, "SdkPerfDataUnitMonitor", ManagementPackAccessibility.Public);
monitorSchemaType.Schema = @"<xsd:element name=""CounterName"" type=""xsd:string"" /><xsd:element name=""ObjectName"" type=""xsd:string"" /><xsd:element name=""Threshold"" type=""xsd:string""/><xsd:element name=""InstanceName"" type=""xsd:string"" minOccurs=""0"" maxOccurs=""1"" />";
m_unitMonitorType.Configuration = monitorSchemaType;
dsRef = new ManagementPackModuleTypeReference(m_unitMonitorType, "Datasource");
dsRef.TypeID = m_windowsLibraryMp.GetModuleType("Microsoft.SystemCenter.SdkPerformanceDataProvider");
conditionDetectionUnderThresholdRef = new ManagementPackModuleTypeReference(m_unitMonitorType, "UnderThresholdFilter");
conditionDetectionUnderThresholdRef.TypeID = m_libraryMp.GetModuleType("System.ExpressionFilter");
conditionDetectionUnderThresholdRef.Configuration = @"<Expression><SimpleExpression><ValueExpression><XPathQuery Type=""Double"">Value</XPathQuery></ValueExpression><Operator>LessEqual</Operator><ValueExpression><Value Type=""Double"">$Config/Threshold$</Value></ValueExpression></SimpleExpression></Expression>";
conditionDetectionOverThresholdRef = new ManagementPackModuleTypeReference(m_unitMonitorType, "OverThresholdFilter");
conditionDetectionOverThresholdRef.TypeID = m_libraryMp.GetModuleType("System.ExpressionFilter");
conditionDetectionOverThresholdRef.Configuration = @"<Expression><SimpleExpression><ValueExpression><XPathQuery Type=""Double"">Value</XPathQuery></ValueExpression><Operator>Greater</Operator><ValueExpression><Value Type=""Double"">$Config/Threshold$</Value></ValueExpression></SimpleExpression></Expression>";
m_unitMonitorType.DataSourceCollection.Add(dsRef);
m_unitMonitorType.ConditionDetectionCollection.Add(conditionDetectionUnderThresholdRef);
m_unitMonitorType.ConditionDetectionCollection.Add(conditionDetectionOverThresholdRef);
underThresholdState = new ManagementPackMonitorTypeState(m_unitMonitorType, "UnderThreshold");
overThresholdState = new ManagementPackMonitorTypeState(m_unitMonitorType, "OverThreshold");
m_unitMonitorType.MonitorTypeStateCollection.Add(underThresholdState);
m_unitMonitorType.MonitorTypeStateCollection.Add(overThresholdState);
underThresholdDetection = new ManagementPackMonitorTypeDetection();
overThresholdDetection = new ManagementPackMonitorTypeDetection();
underThresholdDetection.MonitorTypeStateID = "UnderThreshold";
overThresholdDetection.MonitorTypeStateID = "OverThreshold";
dataSourceNodeType = new ManagementPackModuleCompositionNodeType();
dataSourceNodeType.ID = "Datasource";
underThresholdDetection.Node.ID = "UnderThresholdFilter";
underThresholdDetection.Node.NodeCollection.Add(dataSourceNodeType);
overThresholdDetection.Node.ID = "OverThresholdFilter";
overThresholdDetection.Node.NodeCollection.Add(dataSourceNodeType);
m_unitMonitorType.RegularDetectionCollection.Add(underThresholdDetection);
m_unitMonitorType.RegularDetectionCollection.Add(overThresholdDetection);
m_unitMonitorType.Status = ManagementPackElementStatus.PendingAdd;
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Configuration.IO
Namespace MPCreation
Class Program
Public Overloads Shared Function Main(ByVal args() As String) As Integer
Dim mpCreator As New MPCreator()
mpCreator.AddReferences()
mpCreator.AddClasses()
mpCreator.AddRelationships()
mpCreator.AddViews()
mpCreator.AddTasks()
mpCreator.AddRules()
mpCreator.AddMonitorType()
mpCreator.SaveMPToDisk("C:\")
End Function 'Main
End Class 'Program
Class MPCreator
Private m_mp As ManagementPack
Private m_libraryMp As ManagementPack
Private m_windowsLibraryMp As ManagementPack
Private m_healthLibraryMp As ManagementPack
Private m_mpStore As ManagementPackFileStore
Private m_routerClass As ManagementPackClass
Private m_portClass As ManagementPackClass
Private m_unitMonitorType As ManagementPackUnitMonitorType
'---------------------------------------------------------------------
Public Sub New()
m_mpStore = New ManagementPackFileStore()
m_mpStore.AddDirectory("C:\Program Files\System Center Operations Manager 2007")
m_mp = New ManagementPack("SampleMP", "Sample Management Pack", New Version(1, 0), m_mpStore)
m_libraryMp = New ManagementPack("C:\Program Files\System Center Operations Manager 2007\System.Library.mp", m_mpStore)
m_windowsLibraryMp = New ManagementPack("C:\Program Files\System Center Operations Manager 2007\Microsoft.SystemCenter.Library.mp", m_mpStore)
m_healthLibraryMp = New ManagementPack("C:\Program Files\System Center Operations Manager 2007\System.Health.Library.mp", m_mpStore)
m_mp.Description = "Sample Description"
m_mp.DisplayName = "Sample Management Pack"
m_mp.DefaultLanguageCode = "ENU"
End Sub 'New
'---------------------------------------------------------------------
Public Sub AddClasses()
m_routerClass = New ManagementPackClass(m_mp, "SampleMP.Router", ManagementPackAccessibility.Public)
m_portClass = New ManagementPackClass(m_mp, "SampleMP.Port", ManagementPackAccessibility.Public)
m_routerClass.Abstract = False
m_routerClass.Base = m_libraryMp.GetClass("System.NetworkDevice")
m_portClass.Abstract = False
m_portClass.Hosted = True
m_portClass.Base = m_libraryMp.GetClass("System.LogicalEntity")
AddRouterClassProperties()
AddPortClassProperties()
End Sub 'AddClasses
'---------------------------------------------------------------------
Public Sub AddRelationships()
Dim routerHostsPort As ManagementPackRelationship
routerHostsPort = New ManagementPackRelationship(m_mp, _
"SampleMP.RouterHostsPort", ManagementPackAccessibility.Public)
routerHostsPort.Abstract = False
routerHostsPort.Base = m_libraryMp.GetRelationship("System.Hosting")
routerHostsPort.Description = "Defines the hosting relationship between a router and its ports"
routerHostsPort.DisplayName = "Router Hosts Port"
routerHostsPort.Source = m_routerClass
routerHostsPort.Target = m_portClass
routerHostsPort.Status = ManagementPackElementStatus.PendingAdd
End Sub 'AddRelationships
'---------------------------------------------------------------------
Public Sub AddReferences()
m_mp.References.Add("SCLibrary", New ManagementPackReference(m_libraryMp))
m_mp.References.Add("SCWinLibrary", New ManagementPackReference(m_windowsLibraryMp))
m_mp.References.Add("SCHealth", New ManagementPackReference(m_healthLibraryMp))
End Sub 'AddReferences
'---------------------------------------------------------------------
Public Sub AddViews()
Dim routerStateFolderItem As ManagementPackFolderItem
Dim viewFolder As ManagementPackFolder
Dim routerStateView As ManagementPackView
routerStateView = New ManagementPackView(m_mp, "SampleMP.RouterStateView", ManagementPackAccessibility.Public)
viewFolder = New ManagementPackFolder(m_mp, "SampleMP.ViewFolder", ManagementPackAccessibility.Public)
viewFolder.Description = "Sample MP View Folder"
viewFolder.DisplayName = "Sample MP"
viewFolder.Status = ManagementPackElementStatus.PendingAdd
viewFolder.ParentFolder = m_windowsLibraryMp.GetFolder("Microsoft.SystemCenter.Monitoring.ViewFolder.Root")
routerStateView.Target = m_routerClass
routerStateView.TypeID = m_windowsLibraryMp.GetViewType("Microsoft.SystemCenter.StateViewType")
routerStateView.Description = "Router State View"
routerStateView.DisplayName = "Router State View"
routerStateView.Category = "Operations"
routerStateView.Configuration = "<Criteria><InMaintenanceMode>false</InMaintenanceMode></Criteria>"
routerStateFolderItem = New ManagementPackFolderItem(routerStateView, viewFolder)
routerStateFolderItem.Status = ManagementPackElementStatus.PendingAdd
routerStateView.Status = ManagementPackElementStatus.PendingAdd
End Sub 'AddViews
'---------------------------------------------------------------------
Public Sub AddTasks()
Dim task As ManagementPackTask
Dim probeAction As ManagementPackProbeActionModule
task = New ManagementPackTask(m_mp, "ResetRouter", ManagementPackAccessibility.Public)
probeAction = New ManagementPackProbeActionModule(task, "ResetRouterProbe")
task.Description = "Resets a router"
task.DisplayName = "Reset Router"
task.Target = m_routerClass
task.Status = ManagementPackElementStatus.PendingAdd
task.ProbeAction = probeAction
probeAction.TypeID = CType(m_libraryMp.GetModuleType("System.CommandExecuterProbe"), ManagementPackProbeActionModuleType)
probeAction.Configuration = "<ApplicationName>%WINDIR%\System32\NET.EXE</ApplicationName><WorkingDirectory/><CommandLine>USER</CommandLine><TimeoutSeconds>30</TimeoutSeconds><RequireOutput>true</RequireOutput><Files/>"
End Sub 'AddTasks
Public Sub AddRules()
Dim sdkEventDS As ManagementPackDataSourceModule
Dim writeEventToDBMWA As ManagementPackWriteActionModule
Dim conditionDetection As ManagementPackConditionDetectionModule
Dim rule As ManagementPackRule
rule = New ManagementPackRule(m_mp, "CollectEventsRule")
writeEventToDBMWA = New ManagementPackWriteActionModule(rule, "WriteToDB")
writeEventToDBMWA.TypeID = CType(m_windowsLibraryMp.GetModuleType("Microsoft.SystemCenter.CollectEvent"), _
ManagementPackWriteActionModuleType)
writeEventToDBMWA.Description = "Write Event to DB"
writeEventToDBMWA.DisplayName = "Write Event to DB"
sdkEventDS = New ManagementPackDataSourceModule(rule, "CollectSDKEvent")
sdkEventDS.TypeID = CType(m_windowsLibraryMp.GetModuleType("Microsoft.SystemCenter.SdkEventProvider"), _
ManagementPackDataSourceModuleType)
sdkEventDS.DisplayName = "Collect SDK Event"
sdkEventDS.Description = "Collect SDK Event"
conditionDetection = New ManagementPackConditionDetectionModule(rule, "EventConditionDetection")
conditionDetection.TypeID = CType(m_libraryMp.GetModuleType("System.ExpressionFilter"), ManagementPackConditionDetectionModuleType)
conditionDetection.Configuration = "<Expression><SimpleExpression><ValueExpression><XPathQuery>EventNumber</XPathQuery></ValueExpression><Operator>Equal</Operator><ValueExpression><Value>1</Value></ValueExpression></SimpleExpression></Expression>"
rule.ConfirmDelivery = True
rule.Description = "Collect Events Rule"
rule.DisplayName = "Collect Router Events"
rule.Priority = ManagementPackWorkflowPriority.Normal
rule.Target = m_routerClass
rule.DataSourceCollection.Add(sdkEventDS)
rule.WriteActionCollection.Add(writeEventToDBMWA)
rule.ConditionDetection = conditionDetection
rule.Status = ManagementPackElementStatus.PendingAdd
End Sub 'AddRules
'---------------------------------------------------------------------
Private Sub AddRouterClassProperties()
AddPropertyToClass("Id", "Id", "Contains the Id of the router", _
True, False, 1, ManagementPackEntityPropertyTypes.string, m_routerClass)
AddPropertyToClass("Name", "Name", "Contains the name of the router", _
False, False, 1, ManagementPackEntityPropertyTypes.string, m_routerClass)
AddPropertyToClass("ModelNumber", "Model Number", "Contains the model number of the router", _
False, False, 1, ManagementPackEntityPropertyTypes.string, m_routerClass)
m_routerClass.Status = ManagementPackElementStatus.PendingAdd
End Sub 'AddRouterClassProperties
'---------------------------------------------------------------------
Private Sub AddPortClassProperties()
AddPropertyToClass("Id", "Id", "Contains the Id of the port", _
True, False, 1, ManagementPackEntityPropertyTypes.string, m_portClass)
AddPropertyToClass("PortType", "Port Type", "Contains the type of the port", _
False, False, 1, ManagementPackEntityPropertyTypes.string, m_portClass)
AddPropertyToClass("PortStatus", "Port Status", "Determines whether the port is on or off", _
False, False, 1, ManagementPackEntityPropertyTypes.string, m_portClass)
m_portClass.Status = ManagementPackElementStatus.PendingAdd
End Sub 'AddPortClassProperties
'---------------------------------------------------------------------
Friend Sub SaveMPToDisk(ByVal directoryName As String)
Dim mpXmlWriter As New ManagementPackXmlWriter(directoryName)
m_mp.AcceptChanges()
mpXmlWriter.WriteManagementPack(m_mp)
Console.WriteLine(("Management pack created in the " + directoryName + m_mp.Name + ".xml file."))
End Sub 'SaveMPToDisk
'---------------------------------------------------------------------
Private Sub AddPropertyToClass(ByVal name As String, ByVal displayName As String, _
ByVal description As String, ByVal isKey As Boolean, ByVal isCaseSensitive As Boolean, _
ByVal minLength As Integer, ByVal type As ManagementPackEntityPropertyTypes, _
ByVal mpClass As ManagementPackClass)
Dim [property] As New ManagementPackClassProperty(mpClass, name)
[property].CaseSensitive = isCaseSensitive
[property].Description = description
[property].Type = type
[property].MinLength = minLength
[property].Key = isKey
[property].DisplayName = displayName
mpClass.PropertyCollection.Add([property])
End Sub 'AddPropertyToClass
Friend Sub AddMonitorType()
Dim monitorSchemaType As New ManagementPackConfigurationSchemaType()
Dim dsRef As ManagementPackModuleTypeReference
Dim conditionDetectionUnderThresholdRef As ManagementPackModuleTypeReference
Dim conditionDetectionOverThresholdRef As ManagementPackModuleTypeReference
Dim underThresholdState As ManagementPackMonitorTypeState
Dim overThresholdState As ManagementPackMonitorTypeState
Dim underThresholdDetection As ManagementPackMonitorTypeDetection
Dim overThresholdDetection As ManagementPackMonitorTypeDetection
Dim dataSourceNodeType As ManagementPackModuleCompositionNodeType
m_unitMonitorType = New ManagementPackUnitMonitorType(m_mp, "SdkPerfDataUnitMonitor", ManagementPackAccessibility.Public)
monitorSchemaType.Schema = "<xsd:element name=""CounterName"" type=""xsd:string"" /><xsd:element name=""ObjectName"" type=""xsd:string"" /><xsd:element name=""Threshold"" type=""xsd:string""/><xsd:element name=""InstanceName"" type=""xsd:string"" minOccurs=""0"" maxOccurs=""1"" />"
m_unitMonitorType.Configuration = monitorSchemaType
dsRef = New ManagementPackModuleTypeReference(m_unitMonitorType, "Datasource")
dsRef.TypeID = m_windowsLibraryMp.GetModuleType("Microsoft.SystemCenter.SdkPerformanceDataProvider")
conditionDetectionUnderThresholdRef = New ManagementPackModuleTypeReference(m_unitMonitorType, "UnderThresholdFilter")
conditionDetectionUnderThresholdRef.TypeID = m_libraryMp.GetModuleType("System.ExpressionFilter")
conditionDetectionUnderThresholdRef.Configuration = "<Expression><SimpleExpression><ValueExpression><XPathQuery Type=""Double"">Value</XPathQuery></ValueExpression><Operator>LessEqual</Operator><ValueExpression><Value Type=""Double"">$Config/Threshold$</Value></ValueExpression></SimpleExpression></Expression>"
conditionDetectionOverThresholdRef = New ManagementPackModuleTypeReference(m_unitMonitorType, "OverThresholdFilter")
conditionDetectionOverThresholdRef.TypeID = m_libraryMp.GetModuleType("System.ExpressionFilter")
conditionDetectionOverThresholdRef.Configuration = "<Expression><SimpleExpression><ValueExpression><XPathQuery Type=""Double"">Value</XPathQuery></ValueExpression><Operator>Greater</Operator><ValueExpression><Value Type=""Double"">$Config/Threshold$</Value></ValueExpression></SimpleExpression></Expression>"
m_unitMonitorType.DataSourceCollection.Add(dsRef)
m_unitMonitorType.ConditionDetectionCollection.Add(conditionDetectionUnderThresholdRef)
m_unitMonitorType.ConditionDetectionCollection.Add(conditionDetectionOverThresholdRef)
underThresholdState = New ManagementPackMonitorTypeState(m_unitMonitorType, "UnderThreshold")
overThresholdState = New ManagementPackMonitorTypeState(m_unitMonitorType, "OverThreshold")
m_unitMonitorType.MonitorTypeStateCollection.Add(underThresholdState)
m_unitMonitorType.MonitorTypeStateCollection.Add(overThresholdState)
underThresholdDetection = New ManagementPackMonitorTypeDetection()
overThresholdDetection = New ManagementPackMonitorTypeDetection()
underThresholdDetection.MonitorTypeStateID = "UnderThreshold"
overThresholdDetection.MonitorTypeStateID = "OverThreshold"
dataSourceNodeType = New ManagementPackModuleCompositionNodeType()
dataSourceNodeType.ID = "Datasource"
underThresholdDetection.Node.ID = "UnderThresholdFilter"
underThresholdDetection.Node.NodeCollection.Add(dataSourceNodeType)
overThresholdDetection.Node.ID = "OverThresholdFilter"
overThresholdDetection.Node.NodeCollection.Add(dataSourceNodeType)
m_unitMonitorType.RegularDetectionCollection.Add(underThresholdDetection)
m_unitMonitorType.RegularDetectionCollection.Add(overThresholdDetection)
m_unitMonitorType.Status = ManagementPackElementStatus.PendingAdd
End Sub 'AddMonitorType
End Class 'MPCreator
End Namespace 'MPCreation