MonitoringConnector.GetMonitoringAlerts Method (Int32)
[This topic is pre-release documentation and is subject to change in future releases. Blank topics are included as placeholders.]
Gets alerts marked for the monitoring connector. The retrieved array is limited to the batchSize parameter.
Namespace: Microsoft.EnterpriseManagement.ConnectorFramework
Assembly: Microsoft.EnterpriseManagement.OperationsManager (in Microsoft.EnterpriseManagement.OperationsManager.dll)
Usage
'Usage
Dim instance As MonitoringConnector
Dim batchSize As Integer
Dim returnValue As ReadOnlyCollection(Of ConnectorMonitoringAlert)
returnValue = instance.GetMonitoringAlerts(batchSize)
Syntax
'Declaration
Public Function GetMonitoringAlerts ( _
batchSize As Integer _
) As ReadOnlyCollection(Of ConnectorMonitoringAlert)
public ReadOnlyCollection<ConnectorMonitoringAlert> GetMonitoringAlerts (
int batchSize
)
public:
ReadOnlyCollection<ConnectorMonitoringAlert^>^ GetMonitoringAlerts (
int batchSize
)
public ReadOnlyCollection<ConnectorMonitoringAlert> GetMonitoringAlerts (
int batchSize
)
public function GetMonitoringAlerts (
batchSize : int
) : ReadOnlyCollection<ConnectorMonitoringAlert>
Parameters
- batchSize
The approximate max batch size to return.
Return Value
Returns a ReadOnlyCollection 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.
using System;
using System.Collections.Generic;
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.
IConnectorFrameworkManagement cfAdmin = mgmtGroup.ConnectorFramework;
// Get a collection of all connectors
IList<MonitoringConnector> connectors = cfAdmin.GetConnectors();
Console.WriteLine("There are " + connectors.Count + " connectors");
// Get the alerts of the first connector
MonitoringConnector connector = connectors[0];
IList<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)
{
IList<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.
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Development Platforms
Windows Vista, Windows Server 2003, and
Target Platforms
Change History
See Also
Reference
MonitoringConnector Class
MonitoringConnector Members
Microsoft.EnterpriseManagement.ConnectorFramework Namespace