Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

How to Display Management Pack Contents

System Center

Updated: May 22, 2009

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

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);
            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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.