Database MP Phase II

I decided to add database discovery to the MP.  The attached MP is an expansion of my prior post.

Start by creating a database to hold information about the objects.

And fill it with some rows

Next create a new custom datasource

Note in particular that the Query used the OleDB module, and the ClassId and InstanceSettings used by the Mapper are passed as parameters.  This allows you to reuse the datasource with lots of different discoveries where each discovery only has to know its database query, classtype, and the mapping between the two.

Next, create a class that we’ll discover with a database query.

Next, create a discovery using the datasource.

Here’s the XML for the Configuration:

<Configuration p1:noNamespaceSchemaLocation="C:\Documents and Settings\Administrator\Local Settings\Temp\DBMP.DiscoverMyClass.xsd" xmlns:p1="http://www.w3.org/2001/XMLSchema-instance">
  <IntervalSeconds>600</IntervalSeconds>
  <Query>
  Select
  [ID] as [1],
  [Description] as [2],
  [Color] as [3],
  [AlcoholContent] as [4]
  from ObjectTable
  </Query>
  <ClassId>$MPElement[Name=’DBMP.MyClassStoredInDB’]$</ClassId>
  <InstanceSettings>
    <Settings>
      <Setting>
        <Name>$MPElement[Name=’DBMP.MyClassStoredInDB’]/ID$</Name>
        <Value>$Data/Columns/Column[1]$</Value>
      </Setting>
      <Setting>
        <Name>$MPElement[Name=’DBMP.MyClassStoredInDB’]/Description$</Name>
        <Value>$Data/Columns/Column[2]$</Value>
      </Setting>
      <Setting>
        <Name>$MPElement[Name=’DBMP.MyClassStoredInDB’]/Color$</Name>
        <Value>$Data/Columns/Column[3]$</Value>
      </Setting>
      <Setting>
        <Name>$MPElement[Name=’DBMP.MyClassStoredInDB’]/AlcoholContent$</Name>
        <Value>$Data/Columns/Column[4]$</Value>
      </Setting>
      <Setting>
        <Name>$MPElement[Name=’System!System.Entity’]/DisplayName$</Name>
        <Value>$Data/Columns/Column[3]$ object number $Data/Columns/Column[1]$ </Value>
      </Setting>
    </Settings>
  </InstanceSettings>
</Configuration>

 

Note the embedded SQL Query and mapping details. 

I added a column to the MessageLog table called ItemID to act as a foreign key to the the ObjectTable table.  I also added a rule to the attached MP targeting the discovered objects from the database, and monitoring the MessageLog table.  So now the objects are described and stored in the database, and the health data about those objects also comes from the database.  I’ve also posted the SQL code to create the database, but you’ll have to stick some data in it.

Please let me know if this is useful. 

-Mike

 

http://cid-f2cbe6bae5bb51e1.skydrive.live.com/embedrowdetail.aspx/Public/DBMP2.ziphttp://cid-f2cbe6bae5bb51e1.skydrive.live.com/embedrowdetail.aspx/Public/CreateMyAppDB.sql

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s