When adding history with a response in MOM 2005 if you set up the response to run after duplicate alert suppression the update to the alert is lost. This is because the alert instance is stored to the database during duplicate alert suppression and any subsequent changes made to the instance are abandoned.
It is possible to workaround this limitation with a managed code response, by retrieving and editing the alert instance that was stored during alert suppression, here is a sample:
using System; using System.Collections.Generic; using System.Text; // Include namespaces for MOM SDK using Microsoft.EnterpriseManagement.Mom; using Microsoft.EnterpriseManagement.Mom.Runtime; // This sample shows how to use a Managed code response to add history to an alert // after duplicate suppression has taken place (the alert is committed to the database) // ==================================================================================== namespace Sample { public class SampleClass { public static void ManagedResponseEntry(Context currentContext) { // Get the alert we want to modify from the response context // ========================================================= Guid alertId = currentContext.Alert.Id; // Get the same alert via SDK // ========================== Alert alertInstance = findAlert(alertId); if (alertInstance != null) { AddToHistory(alertInstance, "The quick brown fox jumped over the lazy dog's back"); } } public static void AddToHistory(Alert alertInstance, string textToAdd) { if(!string.IsNullOrEmpty(textToAdd)) { alertInstance.AddAlertHistoryComment(textToAdd); alertInstance.Update(); } } public static Alert findAlert(Guid alertId) { // Connect // ======= Administration mom = Administration.GetAdministrationObject(); if (mom != null) { // Retrieve alert // ========================================================== AlertQuery aq = mom.GetAlertQueryObject(); // Create a query expression to only retrieve the alert we // want to update. // ======================================================== AlertQueryExpression alertQueryExpression = new AlertQueryExpression(); alertQueryExpression.ExpressionOperator = QueryExpression.ExpressionOperatorType.Equals; alertQueryExpression.LeftExpression = new AlertColumnNameExpression(AlertColumnNameExpression.ColumnName.Id); alertQueryExpression.RightExpression = new ValueExpression(alertId.ToString()); AlertsCollection ac = aq.GetAlerts(alertQueryExpression); // Find alert with matching GUID // ============================= foreach (Alert alert in ac) { if (alert.Id == alertId) { return alert; } } } // No matching alert was found! // ============================ return null; } } }
Code using the approach illustrated in the above sample could be in a MCR, or put in EXE form for use from other response types.