How to Create Inbound Connectors

System Center

Updated: May 22, 2009

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

Inbound connectors allow you to insert performance, event, and alert data into Operations Manager from an external management system. The following process describes how to implement an inbound connector:

  1. Create a new instance of the MonitoringConnector class. This process is shown in the CreateConnector method in the code example below.

  2. Write a Management Pack that describes the application model for the application that the data is inserted into. Define the health model for the application by defining monitors and rules that interpret the performance and event data that is inserted through the connector. The code example below uses the following XML for the Management Pack that is saved in the C:\Program Files\System Center Operations Manager 2007\SdkDemo.DiscoveryDataInsertion.xml file.

    <ManagementPack xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ContentReadable="true">
      <Manifest>
        <Identity>
          <ID>SdkDemo.DiscoveryDataInsertion</ID>
          <Version>1.0.0.0</Version>
        </Identity>
        <Name>System Health Library</Name>
        <References>
          <Reference Alias="System">
            <ID>System.Library</ID>
            <Version>6.0.5000.0</Version>
            <PublicKeyToken>9396306c2be7fcc4</PublicKeyToken>
          </Reference>
          <Reference Alias="SystemCenter">
            <ID>Microsoft.SystemCenter.Library</ID>
            <Version>6.0.5000.0</Version>
            <PublicKeyToken>9396306c2be7fcc4</PublicKeyToken>
          </Reference>
        </References>
      </Manifest>
      <TypeDefinitions>
        <EntityTypes>
          <ClassTypes>
            <ClassType ID="SdkDemo.DiscoveryDataInsertion.RouterFan" Accessibility="Public" Abstract="false" Base="System!System.LogicalHardware" Hosted="false" Singleton="false">
              <Property ID="FanId" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="1" />
            </ClassType>
            <ClassType ID="SdkDemo.DiscoveryDataInsertion.Router" Accessibility="Public" Abstract="false" Base="System!System.LogicalHardware" Hosted="false" Singleton="false">
              <Property ID="RouterId" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="1" />
            </ClassType>
            <ClassType ID="SdkDemo.DiscoveryDataInsertion.RouterPort" Accessibility="Public" Abstract="false" Base="System!System.LogicalHardware" Hosted="true" Singleton="false">
              <Property ID="PortId" Type="string" Key="true" CaseSensitive="false" Length="256" MinLength="1" />
            </ClassType>
          </ClassTypes>
          <RelationshipTypes>
            <RelationshipType ID="SdkDemo.DiscoveryDataInsertion.RouterHostsPort" Accessibility="Public" Abstract="false" Base="System!System.Hosting">
              <Source>SdkDemo.DiscoveryDataInsertion.Router</Source>
              <Target>SdkDemo.DiscoveryDataInsertion.RouterPort</Target>
            </RelationshipType>
            <RelationshipType ID="SdkDemo.DiscoveryDataInsertion.RouterContainsFan" Accessibility="Public" Abstract="false" Base="System!System.Containment">
              <Source>SdkDemo.DiscoveryDataInsertion.Router</Source>
              <Target>SdkDemo.DiscoveryDataInsertion.RouterFan</Target>
            </RelationshipType>
          </RelationshipTypes>
        </EntityTypes>
      </TypeDefinitions>
      <Presentation>
        <Views>
          <View ID="View_2e1517f838d44e87892c28fb4aa4c9dd" Accessibility="Public" Enabled="true" Target="SdkDemo.DiscoveryDataInsertion.Router" TypeID="SystemCenter!Microsoft.SystemCenter.StateViewType" Visible="true">  
            <Category>Operations</Category>
              <Criteria>
                <InMaintenanceMode>false</InMaintenanceMode>
              </Criteria>
              <Presentation>
                <ColumnInfo Index="0" SortIndex="0" Width="100" Grouped="false" Sorted="true" IsSortable="true" Visible="true" SortOrder="Descending">
                  <Name>State</Name>
                  <Id>SdkDemo.DiscoveryDataInsertion.Router</Id>
                </ColumnInfo>
                <ColumnInfo Index="1" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
                  <Name>Maintenance Mode</Name>
                  <Id>InMaintenanceMode</Id>
                </ColumnInfo>
                <ColumnInfo Index="2" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
                  <Name>Name</Name>
                  <Id>Name</Id>
                </ColumnInfo>
                <ColumnInfo Index="3" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
                  <Name>Path</Name>
                  <Id>Path</Id>
                </ColumnInfo>
                <ColumnInfo Index="4" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
                  <Name>RouterId</Name>
                  <Id>RouterId</Id>
                </ColumnInfo>
                <ColumnInfo Index="5" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="true" Visible="true" SortOrder="Ascending">
                  <Name>Display Name</Name>
                  <Id>DisplayName</Id>
                </ColumnInfo>
                <ColumnInfo Index="6" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="false" Visible="false" SortOrder="Ascending">
                 <Name>SdkDemo.DiscoveryDataInsertion.RouterPort</Name>
                 <Id>SdkDemo.DiscoveryDataInsertion.RouterPort</Id>
                </ColumnInfo>
                <ColumnInfo Index="7" SortIndex="-1" Width="100" Grouped="false" Sorted="false" IsSortable="false" Visible="false" SortOrder="Ascending">
                  <Name>SdkDemo.DiscoveryDataInsertion.RouterFan</Name>
                  <Id>SdkDemo.DiscoveryDataInsertion.RouterFan</Id>
                </ColumnInfo>
              </Presentation>
            <Target />
          </View>
        </Views>
        <Folders>
          <Folder ID="Folder_8af62648e14e43b5be50724d5ab94d0a" Accessibility="Public" ParentFolder="SystemCenter!Microsoft.SystemCenter.Monitoring.ViewFolder.Root" />
        </Folders>
        <FolderItems>
          <FolderItem ElementID="View_2e1517f838d44e87892c28fb4aa4c9dd" Folder="Folder_8af62648e14e43b5be50724d5ab94d0a" />
        </FolderItems>
      </Presentation>
      <LanguagePacks>
        <LanguagePack ID="ENU" IsDefault="false">
          <DisplayStrings>
            <DisplayString ElementID="SdkDemo.DiscoveryDataInsertion">
              <Name>SDK Demo - Inserting Discovery Data</Name>
              <Description></Description>
            </DisplayString>
            <DisplayString ElementID="Folder_8af62648e14e43b5be50724d5ab94d0a">
              <Name>Sdk Demo Views</Name>
            </DisplayString>
            <DisplayString ElementID="View_2e1517f838d44e87892c28fb4aa4c9dd">
              <Name>Router State</Name>
              <Description></Description>
            </DisplayString>
          </DisplayStrings>
        </LanguagePack>
      </LanguagePacks>
    </ManagementPack>
    
    
  3. Import the Management Pack into Operations Manager.

  4. Insert the discovery data.

  5. Insert performance and event data.

The following example shows how to create an inbound connector that allows you to insert data into Operations Manager from an external management system.

Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Diagnostics
Imports Microsoft.EnterpriseManagement.Administration
Imports Microsoft.EnterpriseManagement
Imports Microsoft.EnterpriseManagement.ConnectorFramework
Imports Microsoft.EnterpriseManagement.Monitoring
Imports Microsoft.EnterpriseManagement.Configuration
Imports Microsoft.EnterpriseManagement.Configuration.IO
Imports System.Collections.ObjectModel
Imports System.IO


Namespace DiscoveryDataInsertion

    Class Program

        Public Overloads Shared Function Main(ByVal args() As String) As Integer
            Dim insertionSample As New DiscoveryDataInsertionSample("localhost")

            insertionSample.InsertDiscoveryData()
        End Function 'Main 
    End Class 'Program

    Class DiscoveryDataInsertionSample
        Private m_managementGroup As ManagementGroup
        Private m_monitoringConnector As MonitoringConnector
        Private m_routerMonitoringObject As MonitoringObject
        Private m_routerPortMonitoringObject As MonitoringObject
        Private m_routerFanMonitoringObject As MonitoringObject


        Public Sub New(ByVal managementServerName As String)
            Debug.Assert((managementServerName.Length > 0))

            ConnectToManagementGroup(managementServerName)

            CreateConnector()

            ImportMPIfNeed()
        End Sub 'New


        Public Sub InsertDiscoveryData()
            Dim discoveryData As New SnapshotMonitoringDiscoveryData()
            Dim routerClass As MonitoringClass
            Dim routerPortClass As MonitoringClass
            Dim routerFanClass As MonitoringClass
            Dim entityClass As MonitoringClass
            Dim fanContainedInRouterRelationshipClass As MonitoringRelationshipClass
            Dim routerMonitoringObject As CustomMonitoringObject
            Dim routerPortObject As CustomMonitoringObject
            Dim routerFanMonitoringObject As CustomMonitoringObject
            Dim relationshipObject As CustomMonitoringRelationshipObject
            Dim routerIdProp As MonitoringClassProperty
            Dim portIdProp As MonitoringClassProperty
            Dim fanIdProp As MonitoringClassProperty
            Dim displayNameProp As MonitoringClassProperty


            routerClass = GetMonitoringClass("SdkDemo.DiscoveryDataInsertion.Router")
            routerPortClass = GetMonitoringClass("SdkDemo.DiscoveryDataInsertion.RouterPort")
            routerFanClass = GetMonitoringClass("SdkDemo.DiscoveryDataInsertion.RouterFan")
            entityClass = GetMonitoringClass("System.Entity")
            fanContainedInRouterRelationshipClass = GetMonitoringRelationshipClass("SdkDemo.DiscoveryDataInsertion.RouterContainsFan")

            routerIdProp = routerClass.GetMonitoringProperty("RouterId")
            portIdProp = routerPortClass.GetMonitoringProperty("PortId")
            fanIdProp = routerFanClass.GetMonitoringProperty("FanId")
            displayNameProp = entityClass.GetMonitoringProperty("DisplayName")

            routerMonitoringObject = New CustomMonitoringObject(routerClass)
            routerPortObject = New CustomMonitoringObject(routerPortClass)
            routerFanMonitoringObject = New CustomMonitoringObject(routerFanClass)
            relationshipObject = New CustomMonitoringRelationshipObject(fanContainedInRouterRelationshipClass)

            routerMonitoringObject.SetMonitoringPropertyValue(routerIdProp, "1")
            routerMonitoringObject.SetMonitoringPropertyValue(displayNameProp, "Router 123")

            'There is a hosting relationship between the router and the router port.
            'For Operations Manager to know what router it needs to associate with the port object, 
            'we have to set the key prop of the router (RouterId) on the hosted object(RouterPort).
            'There is no need to explicitly create a relationship object for relationships of type hosting.
            'An instance of the relationship is created automatically.
            routerPortObject.SetMonitoringPropertyValue(routerIdProp, "1")
            routerPortObject.SetMonitoringPropertyValue(portIdProp, "1")
            routerPortObject.SetMonitoringPropertyValue(displayNameProp, "Port #1")

            routerFanMonitoringObject.SetMonitoringPropertyValue(fanIdProp, "1")
            routerFanMonitoringObject.SetMonitoringPropertyValue(displayNameProp, "Fan #1")

            relationshipObject.SetSource(routerMonitoringObject)
            relationshipObject.SetTarget(routerFanMonitoringObject)

            discoveryData.Include(routerPortObject)
            discoveryData.Include(routerMonitoringObject)
            discoveryData.Include(routerFanMonitoringObject)
            discoveryData.Include(relationshipObject)

            discoveryData.Commit(m_monitoringConnector)

            ' Obtain references to the newly created objects.
            ' They are used to insert events and performance data.
            m_routerMonitoringObject = m_managementGroup.GetMonitoringObject(CType(routerMonitoringObject.Id, Guid))
            m_routerPortMonitoringObject = m_managementGroup.GetMonitoringObject(CType(routerPortObject.Id, Guid))
            m_routerFanMonitoringObject = m_managementGroup.GetMonitoringObject(CType(routerFanMonitoringObject.Id, Guid))
        End Sub 'InsertDiscoveryData


        Private Sub ConnectToManagementGroup(ByVal managementServerName As String)
            m_managementGroup = New ManagementGroup(managementServerName)
        End Sub 'ConnectToManagementGroup

        '---------------------------------------------------------------------
        Private Sub CreateConnector()
            Dim mcfAdmin As ConnectorFrameworkAdministration
            Dim connectorGuid As New Guid("DE1FC259-FE16-44ce-B90E-708CADE55909")

            mcfAdmin = m_managementGroup.GetConnectorFrameworkAdministration()

            Try
                m_monitoringConnector = mcfAdmin.GetMonitoringConnector(connectorGuid)
            Catch e As Microsoft.EnterpriseManagement.Common.ObjectNotFoundException
                'The connector does not exist, so create it.
                Dim connectorInfo As New ConnectorInfo()

                connectorInfo.Description = "This is a sample connector to demonstrate discovery data insertion"
                connectorInfo.DisplayName = "Sample connector"
                connectorInfo.Name = "Sample connector"

                m_monitoringConnector = mcfAdmin.Setup(connectorInfo, connectorGuid)
            End Try

            If Not m_monitoringConnector.Initialized Then
                m_monitoringConnector.Initialize()
            End If
        End Sub 'CreateConnector


        Private Function GetMonitoringClass(ByVal className As String) As MonitoringClass
            Dim monitoringClasses As ReadOnlyCollection(Of MonitoringClass)

            monitoringClasses = m_managementGroup.GetMonitoringClasses(className)

            If monitoringClasses.Count = 0 Then
                Throw New ApplicationException("Failed to find monitoring class " + className)
            End If

            Return monitoringClasses(0)
        End Function 'GetMonitoringClass


        Private Function GetMonitoringRelationshipClass(ByVal relationshipName As String) As MonitoringRelationshipClass
            Dim relationshipClasses As ReadOnlyCollection(Of MonitoringRelationshipClass)

            relationshipClasses = m_managementGroup.GetMonitoringRelationshipClasses(relationshipName)

            If relationshipClasses.Count = 0 Then
                Throw New ApplicationException("Failed to find monitoring relationship " + relationshipName)
            End If

            Return relationshipClasses(0)
        End Function 'GetMonitoringRelationshipClass


        Private Sub ImportMPIfNeed()
            Dim criteria As New ManagementPackCriteria("Name = 'SdkDemo.DiscoveryDataInsertion'")

            If m_managementGroup.GetManagementPacks(criteria).Count = 0 Then

                Dim mgmtPackPath As String = "C:\Program Files\System Center Operations Manager 2007\SdkDemo.DiscoveryDataInsertion.xml"
                Dim mp As ManagementPack = New ManagementPack(mgmtPackPath)

                m_managementGroup.ImportManagementPack(mp)

            End If
        End Sub 'ImportMPIfNeed
    End Class 'DiscoveryDataInsertionSample
End Namespace 'DiscoveryDataInsertion

Show: