The Operations Manager class libraries expose information about installed management packs. The management pack classes can be used to view or edit the configuration of a management pack. For more information about using the Operations Manager class libraries for creating your own management pack authoring tools, see Automating Management Pack Development.
Example
The following example demonstrates how to enumerate the contents of a specific management pack that is installed in a management group.
/// <summary> /// Displays information about the contents of the /// Microsoft.SystemCenter.NTService.Library Management Pack. /// </summary> using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Microsoft.EnterpriseManagement; using Microsoft.EnterpriseManagement.Administration; using Microsoft.EnterpriseManagement.Common; using Microsoft.EnterpriseManagement.Configuration; using Microsoft.EnterpriseManagement.Monitoring; using System.Text; namespace SDKSamples { class Program { static void Main(string[] args) { ManagementGroup mg = new ManagementGroup("localhost"); Console.WriteLine("Displaying Management Pack contents..."); // Get the Management Pack. string query = "Name = 'Microsoft.SystemCenter.NTService.Library'"; ManagementPackCriteria mpCriteria = new ManagementPackCriteria(query); IList<ManagementPack> managementPacks = mg.ManagementPacks.GetManagementPacks(mpCriteria); if (managementPacks.Count != 1) throw new InvalidOperationException("Expected one Management Pack with " + query); // Display information about the Management Pack. DisplayMPInfo(managementPacks[0]); DisplayRules(managementPacks[0]); DisplayTasks(managementPacks[0]); DisplayViews(managementPacks[0]); DisplayViewTypes(managementPacks[0]); DisplayMonitoringClasses(managementPacks[0]); DisplayDependentMPs(managementPacks[0], mg); } /// <summary> /// Displays identification information for the Management Pack. /// </summary> /// <param name="mp">The ManagementPack object to inspect.</param> public static void DisplayMPInfo(ManagementPack mp) { Console.WriteLine("---------------------------------"); Console.WriteLine("Management Pack: " + mp.Name + " (" + mp.DisplayName + ")"); Console.WriteLine(" Description: " + mp.Description); Console.WriteLine(" FriendlyName: " + mp.FriendlyName); Console.WriteLine(" Version: " + mp.Version.ToString()); Console.WriteLine(" ID: " + mp.Id.ToString()); } /// <summary> /// Displays information about the rules in the Management Pack. /// </summary> /// <param name="mp">The ManagementPack object containing the rules.</param> public static void DisplayRules(ManagementPack mp) { ManagementPackElementCollection<ManagementPackRule> rules = mp.GetRules(); if (rules.Count > 0) { foreach (ManagementPackRule rule in rules) { Console.WriteLine(" Rule: " + rule.Name + " (" + rule.Description + ")"); } } else { Console.WriteLine(" (The Management Pack does not contain any rules)"); } } /// <summary> /// Displays information about the tasks in the Management Pack. /// </summary> /// <param name="mp">The ManagementPack object containing the tasks.</param> public static void DisplayTasks(ManagementPack mp) { ManagementPackElementCollection<ManagementPackTask> tasks = mp.GetTasks(); if (tasks.Count > 0) { foreach (ManagementPackTask task in tasks) { Console.WriteLine(" Task: " + task.Name + " (" + task.DisplayName + ")"); } } else { Console.WriteLine(" (The Management Pack does not contain any tasks)"); } } /// <summary> /// Displays information about the view types defined /// in the Management Pack. /// </summary> /// <param name="mp">The ManagementPack object containing /// the view types.</param> public static void DisplayViewTypes(ManagementPack mp) { ManagementPackElementCollection<ManagementPackViewType> viewTypes = mp.GetViewTypes(); if (viewTypes.Count > 0) { foreach (ManagementPackViewType viewType in viewTypes) { Console.WriteLine(" View Type: " + viewType.Name + " (" + viewType.DisplayName + ")"); } } else { Console.WriteLine(" (The Management Pack does not contain any view types)"); } } /// <summary> /// Displays information about the views in the Management Pack. /// </summary> /// <param name="mp">The ManagementPack object containing the /// views.</param> public static void DisplayViews(ManagementPack mp) { ManagementPackElementCollection<ManagementPackView> views = mp.GetViews(); if (views.Count > 0) { foreach (ManagementPackView view in views) { Console.WriteLine(" View: " + view.Name + " (" + view.DisplayName + ")"); } } else { Console.WriteLine(" (The Management Pack does not contain any views)"); } } /// <summary> /// Displays information about the monitoring classes /// defined in the Management Pack. /// </summary> /// <param name="mp">The ManagementPack object containing /// the monitoring classes.</param> public static void DisplayMonitoringClasses(ManagementPack mp) { ManagementPackElementCollection<ManagementPackClass> mpClasses = mp.GetClasses(); if (mpClasses.Count > 0) { foreach (ManagementPackClass mpClass in mpClasses) { Console.WriteLine(" Management Pack class: " + mpClass.Name + " (" + mpClass.DisplayName + ")"); } } else { Console.WriteLine(" (The Management Pack does not contain any classes)"); } } /// <summary> /// Displays information about the dependent Management Packs of /// the specified Management Pack. /// </summary> /// <param name="mp">The ManagementPack object to /// check for dependencies.</param> public static void DisplayDependentMPs(ManagementPack mp, ManagementGroup mg) { IList<ManagementPack> dependentMPs = mg.ManagementPacks.GetDependentManagementPacks(mp); if (dependentMPs.Count > 0) { foreach (ManagementPack dependentMP in dependentMPs) { Console.WriteLine(" Dependent Management Pack: " + dependentMP.Name + " (" + dependentMP.DisplayName + ")"); } } else { Console.WriteLine(" (The Management Pack does not have any dependent Management Packs)"); } } } }