Missing key in the discovery data item


The Error:

2016-02-15_4-53-46

The cause:
The cause for this error is that the Discovery data that is returned for the class instance needs to reference any primary key that is defined in the parent class.

Make sure the discovered class contains all the primary keys required.
Some things you need to check for:
• Make sure the PS script creates the correct number of instances, and they should be unique.
• Make sure that you are discovering key properties of hosting classes.

 
Details (example):
Consider that you have classes A, B and C. Class A is based on the Microsoft.Windows.ComputerRole and classes B and C are based on System.Entity. We have hosting relationships between the classes (A hosts B which hosts C) including the inherited relationship that Windows.Computer hosts Windows.ComputerRole which is the base class for Class A.
We use a Discovery script that discovers three different class instances:

2016-02-16_14-55-28

  1.  We create the ‘MOM.ScriptAPI’ object and create the Discovery bag to store the discovery data. We do a foreach loop on the items we need to check.
  2.  We create a new class instance of objects of type Class A and then we add the required properties. The first two properties we add are key properties from the classes that Class A is based on. As Windows Computer Role is based on Windows Computer class, the Windows Computer class has a Key Property that uniquely identifies the object. Also the System.Entity class is the root class which also has defined a key property called display name. All child instances inherit this property. The last line adds the instance data along with the properties to the Discovery bag data.
  3.  We create a new class instance of type Class B which inherits the key properties from System Entity and Windows Computer and also from Class A.
  4.  Again same thing new instance of class C with key properties from Class A, Class B and Windows Computer and System Entity.

Key properties are not always mandatory. If you create only one instance for a particular class you don’t need to specify one. Of course is you creating more than one then you need it in order to uniquely identify the instance and to which parent it belongs to. Here is a good example:
For the Windows operating system class you do not need a key property because you cannot have more than one operating system at a time (at a logical level). You might have more Logical Disks to that Operating System in which case you need a key to uniquely identify the disks.

2016-02-16_15-46-46

Windows Logical Disk is based in Windows Logical Device and inherits the key property from that class.

2016-02-16_15-50-10

Going back to the error, the conclusion is that if your discovery is missing a key property, like for example in step 4 you miss to specify the ClassA key property you will get this error.

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