locked
How can I get the location of an Alert programmatically C#? RRS feed

  • Question

  • Hello,

    I am trying to get the location of the alerts that occur via C# & SCOM SDK. I can see this information from the operation manager but when using the SDK I don't see anything that would point me to the location. Any help would be great.

    Tuesday, March 18, 2014 3:11 AM

Answers

  • Hi 

    you can use below code to get alert properties.

    /// <summary> /// Displays information about health service alerts /// that have occurred in the management group. /// </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.Monitoring; using System.Text; namespace SDKSamples { class Program { static void Main(string[] args) { ManagementGroup mg = new ManagementGroup("localhost"); //----------------------------------------------------------- // Display alerts. Console.WriteLine("Displaying alert data..."); MonitoringAlertCriteria alertCriteria = new MonitoringAlertCriteria("Description LIKE '%health service%'"); ReadOnlyCollection<MonitoringAlert> alerts = mg.GetMonitoringAlerts(alertCriteria); if (alerts.Count > 0) { foreach (MonitoringAlert alert in alerts) { Console.WriteLine(); Console.WriteLine("Name: " + alert.Name); Console.WriteLine("Description: " + alert.Description); Console.WriteLine("Severity: " + alert.Severity.ToString()); Console.WriteLine("Resolution state: " + alert.ResolutionState.ToString()); } } else { Console.WriteLine("No alerts found."); } //----------------------------------------------------------- // Display events. Console.WriteLine("Displaying events..."); MonitoringEventCriteria eventCriteria = new MonitoringEventCriteria("Number = 187"); ReadOnlyCollection<MonitoringEvent> events = mg.GetMonitoringEvents(eventCriteria); if (events.Count > 0) { foreach (MonitoringEvent OMEvent in events) { Console.WriteLine(); Console.WriteLine("Number: " + OMEvent.Number.ToString()); Console.WriteLine("Description: " + OMEvent.Description); Console.WriteLine("Channel: " + OMEvent.Channel); Console.WriteLine("Computer: " + OMEvent.LoggingComputer); } } else { Console.WriteLine("No events with number 187 found."); } } } }

    refer below link for alert property

    http://technet.microsoft.com/en-us/library/hh549297.aspx

    Regards


    sridhar v

    Tuesday, March 18, 2014 4:40 PM

All replies

  • Hi 

    you can use below code to get alert properties.

    /// <summary> /// Displays information about health service alerts /// that have occurred in the management group. /// </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.Monitoring; using System.Text; namespace SDKSamples { class Program { static void Main(string[] args) { ManagementGroup mg = new ManagementGroup("localhost"); //----------------------------------------------------------- // Display alerts. Console.WriteLine("Displaying alert data..."); MonitoringAlertCriteria alertCriteria = new MonitoringAlertCriteria("Description LIKE '%health service%'"); ReadOnlyCollection<MonitoringAlert> alerts = mg.GetMonitoringAlerts(alertCriteria); if (alerts.Count > 0) { foreach (MonitoringAlert alert in alerts) { Console.WriteLine(); Console.WriteLine("Name: " + alert.Name); Console.WriteLine("Description: " + alert.Description); Console.WriteLine("Severity: " + alert.Severity.ToString()); Console.WriteLine("Resolution state: " + alert.ResolutionState.ToString()); } } else { Console.WriteLine("No alerts found."); } //----------------------------------------------------------- // Display events. Console.WriteLine("Displaying events..."); MonitoringEventCriteria eventCriteria = new MonitoringEventCriteria("Number = 187"); ReadOnlyCollection<MonitoringEvent> events = mg.GetMonitoringEvents(eventCriteria); if (events.Count > 0) { foreach (MonitoringEvent OMEvent in events) { Console.WriteLine(); Console.WriteLine("Number: " + OMEvent.Number.ToString()); Console.WriteLine("Description: " + OMEvent.Description); Console.WriteLine("Channel: " + OMEvent.Channel); Console.WriteLine("Computer: " + OMEvent.LoggingComputer); } } else { Console.WriteLine("No events with number 187 found."); } } } }

    refer below link for alert property

    http://technet.microsoft.com/en-us/library/hh549297.aspx

    Regards


    sridhar v

    Tuesday, March 18, 2014 4:40 PM
  • I don't see how this would return Location information?
    Thursday, March 20, 2014 5:26 AM