Udostępnij za pośrednictwem


How to Create or Remove a Connector by Using the Operations Manager Class Libraries

Applies To: Operations Manager 2007 R2, Operations Manager 2007 SP1, System Center Operations Manager 2007

You can use the Operations Manager class libraries to create a connector that allows Operations Manager to communicate with an external system. If the external system runs on a Windows-based computer, using the class libraries is the preferred method for creating the connector.

Example

The following example demonstrates how to create a connector and how to remove a connector by using the Operations Manager class libraries.

/// <summary>
/// Creates a new connector by using the Operations Manager 
/// class libraries.
/// </summary>
using System;
using System.Collections.ObjectModel;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.ConnectorFramework;
using System.IO;
using System.Text;
using System.Xml;

namespace SDKSamples
{
    class Program
    {
        static void Main(string[] args)
        {
            ManagementGroup mg = new ManagementGroup("localhost");

            ConnectorFrameworkAdministration omcf =
                mg.GetConnectorFrameworkAdministration();
            MonitoringConnector connector = null;
            Guid connectorId = Guid.NewGuid();

            // Create a new connector.
            ConnectorInfo myConnectorInfo = new ConnectorInfo();
            myConnectorInfo.Name = "myConnector";
            myConnectorInfo.DisplayName = "My Connector";
            myConnectorInfo.Description =
                "This connector was created using the Operations Manager class libraries.";
            connector = omcf.Setup(myConnectorInfo, connectorId);
            connector.Initialize();
            Console.WriteLine("Created " + connector.Name + " with ID: " + connector.Id);


            // Remove the connector when finished with it.
            Console.WriteLine("Removing " + connector.Name);
            connector.Uninitialize();
            omcf.Cleanup(connector);
            Console.WriteLine("Connector removed.");
        }
    }
}
' Creates a new connector by using the Operations Manager 
' class libraries.
Imports System
Imports System.Collections.ObjectModel
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.ConnectorFramework
Imports System.IO
Imports System.Text
Imports System.Xml

Namespace SDKSamples
    Class Program
        Public Overloads Shared Function Main(ByVal args() As String) As Integer

            Dim mg As ManagementGroup = New ManagementGroup("localhost")

            Dim omcf As ConnectorFrameworkAdministration = _
                mg.GetConnectorFrameworkAdministration()
            Dim connector As MonitoringConnector = Nothing
            Dim connectorId As Guid = Guid.NewGuid()

            ' Create a new connector.
            Dim myConnectorInfo As ConnectorInfo = New ConnectorInfo()
            myConnectorInfo.Name = "myConnector"
            myConnectorInfo.DisplayName = "My Connector"
            myConnectorInfo.Description = _
                "This connector was created using the Operations Manager class libraries."
            connector = omcf.Setup(myConnectorInfo, connectorId)
            connector.Initialize()
            Console.WriteLine("Created " & connector.Name & " with ID: " & connector.Id.ToString())

            ' Remove the connector when finished with it.
            Console.WriteLine("Removing " + connector.Name)
            connector.Uninitialize()
            omcf.Cleanup(connector)
            Console.WriteLine("Connector removed.")
        End Function
    End Class
End Namespace

See Also

Tasks

How to Create or Remove a Connector by Using the OMCF Web Service