Collects discovery data and merges the existing discovery data with the discovery information provided in the incremental update. Namespace: Microsoft.EnterpriseManagement.ConnectorFramework
Assembly: Microsoft.EnterpriseManagement.OperationsManager (in microsoft.enterprisemanagement.operationsmanager.dll)

Usage

Visual Basic
Dim instance As IncrementalMonitoringDiscoveryData

Syntax

Visual Basic
Public Class IncrementalMonitoringDiscoveryData
C#
public class IncrementalMonitoringDiscoveryData
C++
public ref class IncrementalMonitoringDiscoveryData
J#
public class IncrementalMonitoringDiscoveryData
JScript
public class IncrementalMonitoringDiscoveryData

Example

The following example:

  • Connects to a Management Group.

  • Creates a connector.

  • Initializes the newly created connector.

  • Imports a management pack (if it is not already loaded).

  • Gets the monitoring class for each of the defined IncrementalMonitoringDiscoveryData objects, MonitoringClass objects, CustomMonitoringObject, CustomMonitoringRelationshipObject, and MonitoringClassProperty objects for discovery.

  • Sets the monitoring property value for each of the objects.

  • Sets the source and target for the relationship object.

  • Adds the discovery data to the Operations Manager.

  • Commits the discovery data to the Operations Manager over the newly built connector.

C#  Copy Code
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using Microsoft.EnterpriseManagement.Administration;
using Microsoft.EnterpriseManagement;
using Microsoft.EnterpriseManagement.ConnectorFramework;
using Microsoft.EnterpriseManagement.Monitoring;
using Microsoft.EnterpriseManagement.Configuration;
using System.Collections.ObjectModel;
using System.IO;

namespace DiscoveryDataInsertion
{
	class DiscoveryDataInsertionSample
	{
		ManagementGroup	 m_managementGroup;
		MonitoringConnector m_monitoringConnector;
		MonitoringObject	m_routerMonitoringObject;
		MonitoringObject	m_routerPortMonitoringObject;
		MonitoringObject	m_routerFanMonitoringObject;

		public DiscoveryDataInsertionSample(
			string managementServerName
			)
		{
			Debug.Assert(managementServerName.Length > 0);

			ConnectToManagementGroup(managementServerName);

			CreateConnector();

			ImportMPIfNeed();
	}

		public void InsertDiscoveryData()
		{ 	 
			IncrementalMonitoringDiscoveryData  discoveryData = new IncrementalMonitoringDiscoveryData();
			MonitoringClass					 routerClass;
			MonitoringClass					 routerPortClass;
			MonitoringClass					 routerFanClass;
			MonitoringClass					 entityClass;
			MonitoringRelationshipClass		 fanContainedInRouterRelationshipClass;
			CustomMonitoringObject			routerMonitoringObject;
			CustomMonitoringObject			routerPortObject;
			CustomMonitoringObject			routerFanMonitoringObject;
			CustomMonitoringRelationshipObject  relationshipObject;
			MonitoringClassProperty			 routerIdProp;
			MonitoringClassProperty			 portIdProp;
			MonitoringClassProperty			 fanIdProp;
			MonitoringClassProperty			 displayNameProp;
		

			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.
			//In order for OpsMgr to know to what router it needs to associate with the port object, 
			//we need 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 will be 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.Add(routerPortObject);
			discoveryData.Add(routerMonitoringObject);
			discoveryData.Add(routerFanMonitoringObject);
			discoveryData.Add(relationshipObject);

			discoveryData.Commit(m_monitoringConnector);

			//Obtain references to the newly created objects
			//they will be used  to insert events and performance data
			m_routerMonitoringObject		= m_managementGroup.GetMonitoringObject((Guid)routerMonitoringObject.Id);
			m_routerPortMonitoringObject	= m_managementGroup.GetMonitoringObject((Guid)routerPortObject.Id);
			m_routerFanMonitoringObject	 = m_managementGroup.GetMonitoringObject((Guid)routerFanMonitoringObject.Id);
	}

		private void ConnectToManagementGroup(string managementServerName)
		{
			m_managementGroup = new ManagementGroup(managementServerName);
	}

		private void CreateConnector()
		{
			ConnectorFrameworkAdministration mcfAdmin;
			Guid connectorGuid = new Guid("DE1FC259-FE16-44ce-B90E-708CADE55909");

			mcfAdmin = m_managementGroup.GetConnectorFrameworkAdministration();

			try
			{
				m_monitoringConnector = mcfAdmin.GetMonitoringConnector(connectorGuid);
		}
			catch (Microsoft.EnterpriseManagement.Common.ObjectNotFoundException error)
			{
				//the connector does not exist, so create it

				ConnectorInfo connectorInfo = 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);
		}

			if (!m_monitoringConnector.Initialized)
			{
				m_monitoringConnector.Initialize();
		}
	}

		private MonitoringClass GetMonitoringClass(
			string className
			)
		{
			ReadOnlyCollection<MonitoringClass> monitoringClasses;

			monitoringClasses = m_managementGroup.GetMonitoringClasses(className);

			if (monitoringClasses.Count == 0)
			{
				throw new ApplicationException("Failed to find monitoring class " + className);
		}

			return (monitoringClasses[0]);
	}

		private MonitoringRelationshipClass GetMonitoringRelationshipClass(
			string relationshipName
			)
		{
			ReadOnlyCollection<MonitoringRelationshipClass> relationshipClasses;

			relationshipClasses = m_managementGroup.GetMonitoringRelationshipClasses(relationshipName);

			if (relationshipClasses.Count == 0)
			{
				throw new ApplicationException("Failed to find monitoring relationship " + relationshipName);
		}

			return (relationshipClasses[0]);
	}

		private void ImportMPIfNeed()
		{
			ManagementPackCriteria criteria = new ManagementPackCriteria("Name = 'SdkDemo.DiscoveryDataInsertion'");

			if (m_managementGroup.GetManagementPacks(criteria).Count == 0)
			{
				string mgmtPackPath;

				mgmtPackPath = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + @"\SdkDemo.DiscoveryDataInsertion.xml";
			
				m_managementGroup.ImportManagementPack(new ManagementPack(mgmtPackPath));
		}					
	}

		public static void Main(string[] args)
		{
			DiscoveryDataInsertionSample dataInsertion = 
				new DiscoveryDataInsertionSample("ManagementServerName");

			dataInsertion.InsertDiscoveryData();

	}
}
}

Remarks

An instance of the IncrementalMonitoringDiscoveryData class represents a list of monitoring objects and monitoring relationships to add to or remove from the Operations Manager.

The incremental discovery data is appended to the existing discovery data when the Commit is called.


Inheritance Hierarchy

System.Object
  Microsoft.EnterpriseManagement.ConnectorFramework.IncrementalMonitoringDiscoveryData

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 Server 2008, Windows Vista, Windows Server 2003, and Windows XP

Target Platforms

Windows Server 2008,Windows Server 2003,Windows Vista,Windows XP

See Also