Assembly: Microsoft.EnterpriseManagement.OperationsManager (in microsoft.enterprisemanagement.operationsmanager.dll)
Usage
Visual Basic |
---|
Dim instance As MonitoringConnector Dim batchSize As Integer Dim returnValue As ReadOnlyCollection(Of ConnectorMonitoringAlert) returnValue = instance.GetMonitoringAlerts(batchSize) |
Syntax
Visual Basic |
---|
Public Function GetMonitoringAlerts ( _ batchSize As Integer _ ) As ReadOnlyCollection(Of ConnectorMonitoringAlert) |
C# |
---|
public ReadOnlyCollection<ConnectorMonitoringAlert> GetMonitoringAlerts ( int batchSize ) |
C++ |
---|
public: ReadOnlyCollection<ConnectorMonitoringAlert^>^ GetMonitoringAlerts ( int batchSize ) |
J# |
---|
public ReadOnlyCollection<ConnectorMonitoringAlert> GetMonitoringAlerts ( int batchSize ) |
JScript |
---|
public function GetMonitoringAlerts ( batchSize : int ) : ReadOnlyCollection<ConnectorMonitoringAlert> |
Parameters
- batchSize
-
The approximate max batch size to return.
Return Value
An array of ConnectorMonitoringAlert objects that contain the alerts for the specified monitoring connector.Example
The following example uses the GetMonitoringAlerts method to get the first alert that is marked for this connector and display that alert. Then it repeats the same operation except that it gets the array in batches.
This example assumes that a monitoring connector exists and that alerts are marked for this connector.
C# | Copy Code |
---|---|
using System; using System.Collections.ObjectModel; using System.Text; using Microsoft.EnterpriseManagement; using Microsoft.EnterpriseManagement.Monitoring; using Microsoft.EnterpriseManagement.ConnectorFramework; using Microsoft.EnterpriseManagement.Common; using Microsoft.EnterpriseManagement.Configuration; namespace ConnectorSample { class Program { static void Main(string[] args) { // Connect to a management group. ManagementGroup mgmtGroup = new ManagementGroup("localhost"); // Gets a reference to the connector framework administration object. ConnectorFrameworkAdministration cfAdmin = mgmtGroup.GetConnectorFrameworkAdministration(); // Get a collection of all connectors ReadOnlyCollection<MonitoringConnector> connectors = cfAdmin.GetMonitoringConnectors(); Console.WriteLine("There are " + connectors.Count + " connectors"); // Get the alerts of the first connector MonitoringConnector connector = connectors[0]; ReadOnlyCollection<ConnectorMonitoringAlert> alerts = connector.GetMonitoringAlerts(); if (alerts.Count > 0) { Console.WriteLine("There are " + alerts.Count + " alerts subscribed to by " + connector.Name); } // Get the same collection as above except using batchSize int batchSize = 2; int alertCount = batchSize; while (alertCount >= batchSize) { ReadOnlyCollection<ConnectorMonitoringAlert> alerts_batch = connector.GetMonitoringAlerts(batchSize); Console.WriteLine("There are " + alerts_batch.Count + " alerts in this batch"); // If the batchSize and the collection count is the same, you // need to go back and read the next batch. You did not get // all of the alerts. alertCount = alerts_batch.Count; if (alerts_batch.Count > 0) { connector.AcknowledgeMonitoringAlerts(alerts_batch); } } } } } |
Remarks
This method will only retrieve up to the number of alerts that are specified by the batchSize parameter. This limitation allows you to perform the get monitoring alerts operation in small batches, thereby avoiding a time-out failure.
This method only gets alerts that are marked for the monitoring connector from the bookmark time to the current time less 30 seconds.
It is good practice to limit the number of alerts obtained by a single call. When you perform this GetMonitoringAlerts method you should check to see if the count property of the returned collection equals or exceeds the batchSize. If the count property of the returned collection equals or exceeds the batchSize then you should acknowledge the alerts received, and call this function again to get the next batch of alerts. Only when the returned collection is smaller than the batchSize can you be sure that you have received all of the alerts.
After you retrieve the monitoring alert, you need to acknowledge that alert with an AcknowledgeMonitoringAlerts, or one of the overloaded methods. Failure to acknowledge an alert will result in subsequent calls to get new alerts returning the already received alerts.
This method only gets alerts that are marked for the monitoring connector from the bookmark time to the current time less 30 seconds.