Export (0) Print
Expand All

How to Seal a Management Pack in Operations Manager

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 seal a Management Pack. A sealed Management Pack is a binary file that cannot be edited. An unsealed Management Pack is an XML file that can be edited. Sealed Management Packs should have an .mp extension, and unsealed Management Packs should have an .xml extension.

Example

This example demonstrates how to seal a Management Pack that has been imported in a Management Group. For information about importing Management Packs, see How to Import a New Management Pack.

/// <summary> 
/// Demonstrates how to seal a 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.Configuration.IO;
using Microsoft.EnterpriseManagement.Monitoring;
using System.Text;

namespace SDKSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementGroup mg = new ManagementGroup("localhost");

            Console.WriteLine("Sealing a Management Pack...");
            try
            {
                // Get the Management Pack you want to seal.
                // You can use the ID of the Management Pack,
                // or you can use a ManagementPackCriteria object to define
                // the management pack you want to sign (shown below).
                string mpName = "SampleMP";
                string query = ("Name = '" + mpName + "'");
                ManagementPackCriteria mpCriteria = new ManagementPackCriteria(query);

                ReadOnlyCollection<ManagementPack> mPacks =
                    mg.GetManagementPacks(mpCriteria);
                if (mPacks.Count != 1)
                {
                    Console.WriteLine(
                        "Error! Expected one Management Pack with: " + query);
                    return;
                }
                string companyName = "Microsoft Corp.";
                string outputDir = @"C:\Program Files\System Center Management Packs\";

                // This key file is generated by using the sn.exe tool.
                // You can use the sn.exe -k C:\temp\keyPair.snk command to generate the file.
                string keyFileName = @"c:\temp\keyPair.snk";

                ManagementPackAssemblyWriterSettings mpWriterSettings =
                    new ManagementPackAssemblyWriterSettings(companyName, keyFileName, false);
                mpWriterSettings.OutputDirectory = outputDir;
                ManagementPackAssemblyWriter mpWriter = new ManagementPackAssemblyWriter(mpWriterSettings);
                string result = mpWriter.WriteManagementPack(mPacks[0]);

                Console.WriteLine("The " + mpName + " Management Pack is now sealed.");

            }
            catch (MonitoringException e)
            {
                Console.WriteLine("Sealing a Management Pack failed: " + e.Message);
            }
        }
    }
}

Show:
© 2014 Microsoft