There have been a few requests recently for more granular notification subscriptions. While this is fully supported, our UI is limited in what it exposes for users to tweak. Here is a look at the SDK and how to use it to create a subscription (and related objects).
First of all, to use subscriptions, you need to setup some auxiliary objects. In my example below, the first thing I create is an endpoint. We support Sip, Sms and Smtp. The endpoint is stored as a ModuleType in the database, although this is abstracted away by the API. The fact that it's a module type, however, means that the name has to follow the naming restrictions for management pack elements. After the endpoint, I create an action (also a ModuleType). The action combines an endpoint with configuration that allows the format of the endpoint to be specified. In the Smtp case, this allows you to specify email properties. Finally, I create a recipient that the subscription will be targeted to.
The actual subscription involves combining all the aforementioned components and specifying the criteria by which to filter notifications. In SCOM 2007, notifications are based on alerts. You configure which alerts you want to trigger notifications by using the AlertNotChangedSubscriptionConfiguration and the AlertChangedSubscriptionConfiguration classes. These are also used for connector framework subscriptions to mark alerts for forwarding. These two classes represent criteria by which to match alerts. The first matches alert that have not changed that match the criteria while the latter matches alerts that have changed that match the criteria. Both work off a polling interval. If you look at the classes in the SDK, you will notice that you can specify groups and classes to filter by, but what I really wanted to outline here was the criteria property as this is what is really not exposed fully by the UI. The criteria has to match the schema as defined in the Microsoft.SystemCenter.Library called AlertCriteriaType. Note, you don't need the Expression tag, that is filled in for you. In terms of which columns you can query for in the criteria, it is anything that is defined on the Alert table in the db.
EDIT: Stefan Koell has put together a great powershell example to accomplish the same task.
Here's the code:
(Note - If the criteria is not all on one line, it doesn't work correctly, that's why the formatting is a bit weird below. If you select the code, the full criteria should select)
partial class Program
static void InsertSubscription()
// Connect to the sdk service on the local machine
ManagementGroup localManagementGroup = new ManagementGroup("localhost);
// Setup an Smtp Endpoint
SmtpServer smtpServer = new SmtpServer("localhost");
smtpServer.PortNumber = 42;
// The guid is here for a unique name so this can be rerun
SmtpNotificationEndpoint smtpEndpoint =
"SmtpEndpoint_" + Guid.NewGuid().ToString().Replace('-', '_'),
smtpEndpoint.DisplayName = "My Smtp Endpoint";
smtpEndpoint.Description = "This is my Smtp Endpoint";
smtpEndpoint.MaxPrimaryRecipientsPerMail = 10;
smtpEndpoint.PrimaryServerSwitchBackIntervalSeconds = 15;
// This commits the endpoint into the system
// Setup the Smtp Action (this includes email format)
SmtpNotificationAction smtpNotificationAction =
"SmtpAction" + Guid.NewGuid().ToString().Replace('-', '_'));
smtpNotificationAction.Body = "Body";
smtpNotificationAction.Description = "Description";
smtpNotificationAction.DisplayName = "DisplayName";
smtpNotificationAction.Endpoint = smtpEndpoint;
smtpNotificationAction.From = "Test@Test.com";
new SmtpNotificationActionHeader("Name", "Value"));
smtpNotificationAction.IsBodyHtml = false;
smtpNotificationAction.ReplyTo = "firstname.lastname@example.org";
smtpNotificationAction.Subject = "my subject";
// This commits the action into the system
// Setup a recipient
NotificationRecipientScheduleEntry scheduleEntry =
new NotificationRecipientScheduleEntryTime(8, 0);
new NotificationRecipientScheduleEntryTime(17, 0);
NotificationRecipientDevice recipientDevice =
new NotificationRecipientDevice("smtp", "email@example.com");
recipientDevice.Name = "TestDevice";
NotificationRecipient recipient =
new NotificationRecipient("RecipientName" + DateTime.Now.ToString());
// Commits the recipient
// Alert configuration
AlertNotChangedSubscriptionConfiguration config =
config.Criteria = "<SimpleExpression><ValueExpression><Property>ResolutionState</Property></ValueExpression><Operator>Equal</Operator><ValueExpression><Value>255</Value></ValueExpression></SimpleExpression>";
config.ExpirationStartTime = DateTime.Now;
config.PollingIntervalMinutes = 1;
AlertNotificationSubscription alertChangeSubscription =
"MyNewAlertChangeSubscription" + Guid.NewGuid().ToString().Replace('-', '_'),
alertChangeSubscription.DisplayName = "My Subscription";
alertChangeSubscription.Description = "My Subscription Description";
// Commits the subscription
How I can use this C+ code?
I must make an exe file?
This is C# and yes, you would need to make an exe.
Oh, I see.
Will it create new Subscription, new Recipient and new Notification Channel?
Shall I have opportunity to see it in UI?
Shall I have opportunity to change it through UI?
To answer your questions in order:
Yes (depending on the complexity of the criteria, however, some things are not supported in the UI)
Thanks a Lot!
I try to run this code, but get a error:
"The type or namespace name 'EnterpriseManagement' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)"
I could create a new Subscription!!!
The first results
(It is my first operational experience with C# and VS)
First of all I can’t see new Notification channel.
How to remove already created channels (by this code)?
I want to add new subscription to the concrete monitor (alerts from only one monitor) and I don’t see how I can do this by this code.
Where I can get all parameters, if I must use “Criteria” property of AlertChangedSubscriptionConfiguration Class for this? And I do not know where I can get Monitor ID.
1. To find the notification channel, go to the Administration pane -> Settings -> Notification.
2. You can delete from there, or programatically using the ManagementGroup.DeleteNotificationAction()/DeleteNotificationEndpoint() methods.
3/4. You need to use criteria for this. Essentially, you can use any property that is defined on the MonitoringAlert object. For a monitor it is ProblemId.
1. I can find there only channels which have been created through UI, and not one channel through this code.
2. Thanks for advice
3. I'll try.
Thanks a lot!
1. Looks like the UI uses specific names for the channels it shows:
SmtpEndpoint and DefaultSmtpAction
ImEndpoint and DefaultImAction
SmsEndpoint and DefaultSmsAction
I have tested your sample code to create a subscription for our customer's requirement for a while. However I could not find the code to control "Alert Aging" option in your sample code and SDK. Could you tell me how to control alert aging option under subscription? Thank you for your help.
Are you looking for alerts that haven't changed in some time? For that, you should use AlertNotChangedSubscriptionConfiguration and the IdleMinutes property.
Thanks Jakub. That is what I need. Now I can understand the sdk descirption of IdleMinutes "Gets or sets the interval of time, in minutes, that alerts do not change.".
I also find out you have sample code which used this property in another post.
BTW, will MS plan to release a enhanced SCOM console that support creating complex subscription? I got exception window each time when I double-click subscription created by coding. It's a little hard to maintain.
Unfortunately, there is no current plan to expand the UI support for creating subscriptions.