How to Retrieve Information from a Management Pack

System Center

Updated: May 22, 2009

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

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

See Also

Show: