Udostępnij za pośrednictwem


How to Seal a Management Pack in Operations Manager

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);
            }
        }
    }
}
' Demonstrates how to seal a Management Pack.
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.Administration
imports Microsoft.EnterpriseManagement.Configuration
imports Microsoft.EnterpriseManagement.Configuration.IO
Imports Microsoft.EnterpriseManagement.ConnectorFramework
Imports Microsoft.EnterpriseManagement.Common
Imports Microsoft.EnterpriseManagement.Monitoring
Imports System.Collections.ObjectModel

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

            Dim mg As ManagementGroup = 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).
                Dim mpName As String = "SampleMP"
                Dim query As String = ("Name = '" & mpName & "'")
                Dim mpCriteria As ManagementPackCriteria = New ManagementPackCriteria(query)

                Dim mPacks As ReadOnlyCollection(Of ManagementPack) = _
                    mg.GetManagementPacks(mpCriteria)
                If (mPacks.Count <> 1) Then

                    Console.WriteLine( _
                        "Error! Expected one Management Pack with: " & query)
                    Return 1
                End If

                Dim companyName As String = "Microsoft Corp."
                Dim outputDir As String = "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.
                Dim keyFileName As String = "c:\temp\keyPair.snk"

                Dim mpWriterSettings As ManagementPackAssemblyWriterSettings = _
                    New ManagementPackAssemblyWriterSettings(companyName, keyFileName, False)
                mpWriterSettings.OutputDirectory = outputDir
                Dim mpWriter As ManagementPackAssemblyWriter = _
                    New ManagementPackAssemblyWriter(mpWriterSettings)
                Dim result As String = mpWriter.WriteManagementPack(mPacks(0))

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

            Catch e As MonitoringException

                Console.WriteLine("Sealing a Management Pack failed: " & e.Message)
            End Try
        End Function
    End Class
End Namespace