How to Create a Subscription
Applies To: System Center Service Manager 2010
Management pack monitoring enables objects to be processed through custom logic and workflow. This provides your solution with a powerful way of creating the logic features of your management pack. The two components of the subscription system are the criteria and the action. When the subscription criteria have been matched, the action component of the subscription will execute.
To create a Windows workflow subscription
Find the RePackaging.Library management pack.
Create an instance of the subscription criteria, the InstanceTypeSubscription class, providing the management pack class identifier for the RePackaging.Request class.
Create an instance of the subscription action, the WorkflowSubscription class, providing the previously created subscription criteria.
Add parameters to the workflow subscription action.
Use the management group to insert the new subscription action, linking it to the management pack class.
Accept the changes to the management pack.
The following example uses the InstanceTypeSubscription criteria to trigger when a new RePackaging.Request object is created. The InstanceTypeSubscription class can also be used to trigger when the object was created, updated, or deleted.
string managementPackName = "RePackaging.Library";
string managementClassName = "RePackaging.Request";
ManagementPackCriteria searchCrit = new ManagementPackCriteria("$Name='" + managementPackName + "'$");
foreach (var mp in mg.ManagementPacks.GetManagementPacks(searchCrit))
{
InstanceTypeSubscription subCriteria = new InstanceTypeSubscription(OperationType.Add, mp.GetClass(managementClassName).Id, "");
subCriteria.BatchSize = 100;
subCriteria.PollingIntervalInSeconds = 60;
WorkflowSubscription subAction = new WorkflowSubscription("WF_AcceptPackageRequest", "Accepts the package request.", subCriteria);
subAction.AssemblyName = "WorkflowPackageRequest";
subAction.WorkflowTypeName = "WorkflowPackageRequest.PackageInitial";
subAction.Enabled = true;
subAction.Parameters.Add(new KeyValuePair<string, IWorkflowParameterValueBase>("InternalID", new WorkflowParameterValue(WorkflowParameterType.GuidType, "$Data/BaseManagedEntityId$")));
subAction.Parameters.Add(new KeyValuePair<string, IWorkflowParameterValueBase>("ClassGUID", new WorkflowParameterValue(WorkflowParameterType.GuidType, "$MPElement[Name='RePackaging.Request']$")));
mg.Subscription.InsertSubscription(mp.Id, subAction);
mp.AcceptChanges();
break;
}
<ManagementPack ContentReadable="true" SchemaVersion="1.1" OriginalSchemaVersion="1.1" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<Monitoring>
<Rules>
<Rule ID="WorkflowSubscription_378b1659_ad6c_405b_b301_2a929e56523b" Enabled="true" Target="SystemCenter!Microsoft.SystemCenter.SubscriptionWorkflowTarget" ConfirmDelivery="true" Remotable="true" Priority="Normal" DiscardLevel="100">
<Category>System</Category>
<DataSources>
<DataSource ID="DS" TypeID="SystemCenter1!Microsoft.SystemCenter.CmdbInstanceSubscription.DataSourceModule">
<Subscription>
<InstanceSubscription Type="$MPElement[Name='RePackaging.Request']">
<AddInstance />
</InstanceSubscription>
<PollingIntervalInSeconds>60</PollingIntervalInSeconds>
<BatchSize>100</BatchSize>
</Subscription>
</DataSource>
</DataSources>
<WriteActions>
<WriteAction ID="WA" TypeID="SystemCenter1!Microsoft.EnterpriseManagement.SystemCenter.Subscription.WindowsWorkflowTaskWriteAction">
<Subscription>
<EnableBatchProcessing>false</EnableBatchProcessing>
<WindowsWorkflowConfiguration>
<AssemblyName>AcceptPackageRequest</AssemblyName>
<WorkflowTypeName>WorkflowAuthoring.AcceptPackageRequest</WorkflowTypeName>
<WorkflowParameters>
<WorkflowParameter Name="InternalID" Type="guid">$Target/Id$</WorkflowParameter>
</WorkflowParameters>
<RetryExceptions />
<RetryDelaySeconds>60</RetryDelaySeconds>
<MaximumRunningTimeSeconds>7200</MaximumRunningTimeSeconds>
</WindowsWorkflowConfiguration>
</Subscription>
</WriteAction>
</WriteActions>
</Rule>
</Rules>
</Monitoring>
<LanguagePacks>
<LanguagePack ID="ENU" IsDefault="false">
<DisplayStrings>
<DisplayString ElementID="WorkflowSubscription_378b1659_ad6c_405b_b301_2a929e56523b">
<Name>WF_AcceptPackageRequest</Name>
<Description>Accepts the package request.</Description>
</DisplayString>
</DisplayStrings>
</LanguagePack>
</LanguagePacks>
</ManagementPack>
Namespaces
Microsoft.EnterpriseManagement
Microsoft.EnterpriseManagement.Configuration
Microsoft.EnterpriseManagement.Subscriptions
Assemblies
Microsoft.EnterpriseManagement.Core