Share via


How to Retrieve Information from a Management Pack

Applies To: System Center 2012 - Operations Manager

[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]

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 (ManagementPackProperty 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);
            }
        }
    }
}

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");
            IList<ManagementPack> managementPacks = mg.ManagementPacks.GetManagementPacks();

            foreach (ManagementPack mp in managementPacks)
            {
                Console.WriteLine("{0} - {1}", mp.DisplayName,mp.Version.ToString());
            }
        }
    }
}

See Also

Tasks

How to Display Management Pack Contents

Other Resources

Automating Management Pack Development