How to Seal a Management Pack in Operations Manager
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 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 into 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);
IList<ManagementPack> mPacks =
mg.ManagementPacks.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 (EnterpriseManagementException e)
{
Console.WriteLine("Sealing a Management Pack failed: " + e.Message);
}
}
}
}