How to Retrieve Information from 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 gather information about an existing Management Pack. For a list of Management Pack properties, see ManagementPack and ManagementPackClass.
Example
Description
The following example demonstrates how to retrieve information from two different Management Packs. The example displays information about the classes, relationships, monitors, rules, and tasks in the Management Packs.
Code
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Configuration.IO;
namespace SDKSamples
{
class Program
{
static void Main(string[] args)
{
ManagementPack libraryMp;
ManagementPack sqlMp;
ManagementPackElementCollection<ManagementPackClass> classes;
ManagementPackElementCollection<ManagementPackRelationship> relationships;
ManagementPackElementCollection<ManagementPackTask> tasks;
ManagementPackElementCollection<ManagementPackMonitor> monitors;
ManagementPackElementCollection<ManagementPackRule> rules;
libraryMp = new ManagementPack(@"c:\ManagementPacks\System.Library.xml");
sqlMp = new ManagementPack(@"c:\ManagementPacks\Microsoft.SQLServer.2005.Monitoring.xml");
classes = libraryMp.GetClasses();
relationships = libraryMp.GetRelationships();
monitors = sqlMp.GetMonitors();
rules = sqlMp.GetRules();
tasks = sqlMp.GetTasks();
Console.WriteLine("Classes");
foreach (ManagementPackClass mpClass in classes)
{
Console.WriteLine("\n\tName: {0}", mpClass.DisplayName);
Console.WriteLine("\tProperties");
foreach (ManagementPackClassProperty property in mpClass.PropertyCollection)
{
Console.WriteLine("\t\tName: {0}", property.Name);
}
}
Console.WriteLine("\nRelationships");
foreach (ManagementPackRelationship relationship in relationships)
{
Console.WriteLine("\tName: {0}", relationship.DisplayName);
Console.WriteLine("\t\tSource: {0}", relationship.Source.Name);
Console.WriteLine("\t\tTarget: {0}", relationship.Target.Name);
}
Console.WriteLine("\nMonitors");
foreach (ManagementPackMonitor monitor in monitors)
{
Console.WriteLine("\n\tName: {0}", monitor.DisplayName);
Console.WriteLine("\tTarget: {0}", monitor.Target.Name);
Console.WriteLine("\tEnabled: {0}",monitor.Enabled);
}
Console.WriteLine("\nRules");
foreach (ManagementPackRule rule in rules)
{
Console.WriteLine("\n\tName: {0}", rule.DisplayName);
Console.WriteLine("\tTarget: {0}", rule.Target.Name);
Console.WriteLine("\tEnabled: {0}", rule.Enabled);
}
Console.WriteLine("\nTasks");
foreach (ManagementPackTask task in tasks)
{
Console.WriteLine("\n\tName: {0}", task.DisplayName);
Console.WriteLine("\tTarget: {0}", task.Target.Name);
Console.WriteLine("\tEnabled: {0}", task.Enabled);
}
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.VisualBasic
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Configuration.IO
Namespace SDKSamples
Class Program
Public Overloads Shared Function Main(ByVal args() As String) As Integer
Dim libraryMp As ManagementPack
Dim sqlMp As ManagementPack
Dim classes As ManagementPackElementCollection(Of ManagementPackClass)
Dim relationships As ManagementPackElementCollection(Of ManagementPackRelationship)
Dim tasks As ManagementPackElementCollection(Of ManagementPackTask)
Dim monitors As ManagementPackElementCollection(Of ManagementPackMonitor)
Dim rules As ManagementPackElementCollection(Of ManagementPackRule)
libraryMp = New ManagementPack("c:\ManagementPacks\System.Library.xml")
sqlMp = New ManagementPack("c:\ManagementPacks\Microsoft.SQLServer.2005.Monitoring.xml")
classes = libraryMp.GetClasses()
relationships = libraryMp.GetRelationships()
monitors = sqlMp.GetMonitors()
rules = sqlMp.GetRules()
tasks = sqlMp.GetTasks()
Console.WriteLine("Classes")
For Each mpClass As ManagementPackClass In classes
Console.WriteLine(ControlChars.Lf + ControlChars.Tab + _
"Name: {0}", mpClass.DisplayName)
Console.WriteLine(ControlChars.Tab + "Properties")
For Each prop As ManagementPackClassProperty In mpClass.PropertyCollection
Console.WriteLine(ControlChars.Tab + ControlChars.Tab + "Name: {0}", prop.Name)
Next
Next
Console.WriteLine(ControlChars.Lf + "Relationships")
For Each relationship As ManagementPackRelationship In relationships
Console.WriteLine(ControlChars.Tab + "Name: {0}", relationship.DisplayName)
Console.WriteLine(ControlChars.Tab + ControlChars.Tab + "Source: {0}", relationship.Source.Name)
Console.WriteLine(ControlChars.Tab + ControlChars.Tab + "Target: {0}", relationship.Target.Name)
Next
Console.WriteLine(ControlChars.Lf + "Monitors")
For Each monitor As ManagementPackMonitor In monitors
Console.WriteLine(ControlChars.Lf + ControlChars.Tab + _
"Name: {0}", monitor.DisplayName)
Console.WriteLine(ControlChars.Tab + "Target: {0}", monitor.Target.Name)
Console.WriteLine(ControlChars.Tab + "Enabled: {0}", monitor.Enabled)
Next
Console.WriteLine(ControlChars.Lf + "Rules")
For Each rule As ManagementPackRule In rules
Console.WriteLine(ControlChars.Lf + ControlChars.Tab + _
"Name: {0}", rule.DisplayName)
Console.WriteLine(ControlChars.Tab + "Target: {0}", rule.Target.Name)
Console.WriteLine(ControlChars.Tab + "Enabled: {0}", rule.Enabled)
Next
Console.WriteLine(ControlChars.Lf + "Tasks")
For Each task As ManagementPackTask In tasks
Console.WriteLine(ControlChars.Lf + ControlChars.Tab + _
"Name: {0}", task.DisplayName)
Console.WriteLine(ControlChars.Tab + "Target: {0}", task.Target.Name)
Console.WriteLine(ControlChars.Tab + "Enabled: {0}", task.Enabled)
Next
End Function
End Class
End Namespace
Example
Description
The following example demonstrates how to retrieve the display name and version for all the Management Packs in a Management Group.
Code
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Text;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.Configuration;
using Microsoft.EnterpriseManagement.Configuration.IO;
namespace SDKSamples
{
class Program
{
static void Main(string[] args)
{
ManagementGroup mg = new ManagementGroup("localhost");
ReadOnlyCollection<ManagementPack> managementPacks;
managementPacks = mg.GetManagementPacks();
foreach (ManagementPack mp in managementPacks)
{
Console.WriteLine("{0} - {1}", mp.DisplayName,mp.Version.ToString());
}
}
}
}
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports System.Text
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Configuration.IO
Namespace SDKSamples
Class Program
Public Overloads Shared Function Main(ByVal args() As String) As Integer
Dim mg As ManagementGroup = New ManagementGroup("localhost")
Dim managementPacks As ReadOnlyCollection(Of ManagementPack)
managementPacks = mg.GetManagementPacks()
For Each mp As ManagementPack In managementPacks
Console.WriteLine("{0} - {1}", mp.DisplayName, mp.Version.ToString())
Next
End Function
End Class
End Namespace
See Also
Tasks
How to Display Management Pack Contents