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.

Visual Basic  Copy Code
' <summary> 
' Displays information about the contents of the
' Microsoft.SystemCenter.NTService.Library Management Pack.
' </summary>
Imports System
Imports System.Collections.Generic
Imports System.Collections.ObjectModel
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Administration
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Common
Imports Microsoft.EnterpriseManagement.Monitoring


Namespace SDKSamples
	Class Program
		Public Overloads Shared Function Main(ByVal args() As String) As Integer

			Dim mg As ManagementGroup = New ManagementGroup("localhost")

			Console.WriteLine("Displaying Management Pack contents...")

			' Get the Management Pack.
			Dim query As String = "Name = 'Microsoft.SystemCenter.NTService.Library'"
			Dim mpCriteria As ManagementPackCriteria = New ManagementPackCriteria(query)
			Dim managementPacks As ReadOnlyCollection(Of ManagementPack) = _
				mg.GetManagementPacks(mpCriteria)
			If (managementPacks.Count <> 1) Then
				Throw New InvalidOperationException("Expected one Management Pack with " & query)
			End If

			' 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)
		End Function

		' <summary>
		' Displays identification information for the Management Pack.
		' </summary>
		' <param name="mp">The ManagementPack object to inspect.</param>
		Public Shared Sub DisplayMPInfo(ByVal mp As ManagementPack)

			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())
		End Sub

		' <summary>
		' Displays information about the rules in the Management Pack.
		' </summary>
		' <param name="mp">The ManagementPack object containing the rules.</param>
		Public Shared Sub DisplayRules(ByVal mp As ManagementPack)

			Dim rules As ManagementPackElementCollection(Of ManagementPackRule) = mp.GetRules()

			If (rules.Count > 0) Then

				For Each rule As ManagementPackRule In rules

					Console.WriteLine("	Rule: " & rule.Name & " (" & rule.Description & ")")
				Next
			Else

				Console.WriteLine("	(The Management Pack does not contain any rules)")
			End If
		End Sub

		' <summary>
		' Displays information about the tasks in the Management Pack.
		' </summary>
		' <param name="mp">The ManagementPack object containing the tasks.</param>
		Public Shared Sub DisplayTasks(ByVal mp As ManagementPack)

			Dim tasks As ManagementPackElementCollection(Of ManagementPackTask) = mp.GetTasks()

			If (tasks.Count > 0) Then

				For Each task As ManagementPackTask In tasks

					Console.WriteLine("	Task: " & task.Name & " (" & task.DisplayName & ")")
				Next
			Else

				Console.WriteLine("	(The Management Pack does not contain any tasks)")
			End If
		End Sub

		' <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 Shared Sub DisplayViewTypes(ByVal mp As ManagementPack)

			Dim viewTypes As ManagementPackElementCollection(Of ManagementPackViewType) = _
				mp.GetViewTypes()

			If (viewTypes.Count > 0) Then

				For Each viewType As ManagementPackViewType In viewTypes

					Console.WriteLine("	View Type: " & viewType.Name + " (" & viewType.DisplayName & ")")
				Next

			Else

				Console.WriteLine("	(The Management Pack does not contain any view types)")
			End If
		End Sub

		' <summary>
		' Displays information about the views in the Management Pack.
		' </summary>
		' <param name="mp">The ManagementPack object containing the 
		' views.</param>
		Public Shared Sub DisplayViews(ByVal mp As ManagementPack)

			Dim views As ManagementPackElementCollection(Of ManagementPackView) = mp.GetViews()

			If (views.Count > 0) Then

				For Each view As ManagementPackView In views

					Console.WriteLine("	View: " & view.Name & " (" & view.DisplayName & ")")
				Next

			Else

				Console.WriteLine("	(The Management Pack does not contain any views)")
			End If
		End Sub

		' <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 Shared Sub DisplayMonitoringClasses(ByVal mp As ManagementPack)

			Dim mpClasses As ManagementPackElementCollection(Of ManagementPackClass) = _
				mp.GetClasses()

			If (mpClasses.Count > 0) Then

				For Each mpClass As ManagementPackClass In mpClasses

					Console.WriteLine("	Management Pack class: " & mpClass.Name & " (" & mpClass.DisplayName & ")")
				Next

			Else

				Console.WriteLine("	(The Management Pack does not contain any classes)")
			End If
		End Sub

		' <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 Shared Sub DisplayDependentMPs(ByVal mp As ManagementPack, ByVal mg As ManagementGroup)

			Dim dependentMPs As ReadOnlyCollection(Of ManagementPack) = _
				mg.GetDependentManagementPacks(mp)

			If (dependentMPs.Count > 0) Then

				For Each dependentMP As ManagementPack In dependentMPs

					Console.WriteLine("	Dependent Management Pack: " & _
					 dependentMP.Name & " (" & dependentMP.DisplayName & ")")
				Next

			Else

				Console.WriteLine("	(The Management Pack does not have any dependent Management Packs)")
			End If
		End Sub
	End Class
End Namespace
C#  Copy Code
/// <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);
			ReadOnlyCollection<ManagementPack> managementPacks = mg.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)
		{
			ReadOnlyCollection<ManagementPack> dependentMPs = mg.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)");
		}
	}
}
}

See Also


Send comments about this topic to Microsoft.