locked
Identifying an EnterpriseManagementObject as being a Group or a single Object RRS feed

  • Question

  • Does anyone know exactly which property am I supposed to check to know whether an EnterpriseManagementObject is a group or not using the SCOM 2012 SDK?

    For 2007R2, there was the MonitoringObjectGroup class and a MonitoringObject class. And this is the separation I'm looking for.

    Any tip would be greatly appreciated.

    Tuesday, October 23, 2012 9:20 AM

Answers

  • Interesting results - I'm surprised the second one works when the Guid doesn't represent a group!

    Try using MonitoringObject as the type, so GetObject<MonitoringObject>(...). This seems to hit a code path that constructs the specific type (MonitoringObject or MonitoringObjectGroup) depending on the object, like the 2007R2 methods used to. You can also use PartialMonitoringObject, which can return objects of type PartialMonitoringObjectGroup and is faster if you don't need any object properties.

    Let me know if this doesn't work for you. Good luck!

    Cheers, Richard


    Richard Benwell www.squaredup.com

    • Marked as answer by PMMagalhães Tuesday, October 23, 2012 2:25 PM
    Tuesday, October 23, 2012 2:08 PM

All replies

  • This works the same in 2012. See http://msdn.microsoft.com/en-us/library/hh327683.aspx.

    From MSDN, the inheritance hierarchy in 2012 is:

    System.Object 
       Microsoft.EnterpriseManagement.Common.MonitoringBase
         Microsoft.EnterpriseManagement.Common.MonitoringBaseWithId
           Microsoft.EnterpriseManagement.Common.EnterpriseManagementBase
             Microsoft.EnterpriseManagement.Common.EnterpriseManagementObjectBaseWithProperties
               Microsoft.EnterpriseManagement.Common.EnterpriseManagementObject
                 Microsoft.EnterpriseManagement.Monitoring.PartialMonitoringObjectBase
                   Microsoft.EnterpriseManagement.Monitoring.PartialMonitoringObject
                     Microsoft.EnterpriseManagement.Monitoring.MonitoringObject
                      Microsoft.EnterpriseManagement.Monitoring.MonitoringObjectGroup

    So you should still be able to do this:

    bool isGroup = (obj is MonitoringObjectGroup);

    Hope this helps.


    Richard Benwell www.squaredup.com

    Tuesday, October 23, 2012 11:22 AM
  • Hello, Richard.

    Thanks a lot for your reply. It is a very good idea.

    Although unfortunately, it seems to fail. The MonitoringObjectGroup is marked as deprecated and it seems it is no longer used in 2012. When I run that code for the EnterpriseManagementObject containing the "All Windows Computers" group, it returns false.

    Have you tested it successfully?

    Regards, Pedro

    Tuesday, October 23, 2012 12:28 PM
  • Hi Pedro,

    Yes, that works for me (I just tried it on the 'All Windows Computer' group). I wonder what the difference is in your setup. What code are you using to get the object?

    I also don't see any attribute on that class marking it as deprecated. What SCOM version are you using?

    Cheers, Richard


    Richard Benwell www.squaredup.com

    Tuesday, October 23, 2012 12:56 PM
  • Hello again, Richard.

    You are right, it isn't marked as deprecated. Only the CustomMonitoringObjectGroup is. My mistake.

    About the code I'm using, I have tested two different approaches and neither is working the way I intended. This probably has to do with some lack of knowledge on my side, but maybe you can point me in the right direction. My code is:

    EnterpriseManagementObject theObj = MG.EntityObjects.GetObject<EnterpriseManagementObject>(new Guid(/*Guid of a group or object*/), new ObjectQueryOptions(ObjectPropertyRetrievalBehavior.All));
    
     (theObj is MonitoringObjectGroup) //Always false
    
    EnterpriseManagementObject theObj = MG.EntityObjects.GetObject<MonitoringObjectGroup>(new Guid(/*Guid of a group or object*/), new ObjectQueryOptions(ObjectPropertyRetrievalBehavior.All));
    
     (theObj is MonitoringObjectGroup) //Always true

    So in both these cases, whether I pass it a Guid of a Group or an Object, the result is always the same for both. Should I pass other type to the GetObject method?

    Regards, Pedro

    Tuesday, October 23, 2012 1:41 PM
  • Interesting results - I'm surprised the second one works when the Guid doesn't represent a group!

    Try using MonitoringObject as the type, so GetObject<MonitoringObject>(...). This seems to hit a code path that constructs the specific type (MonitoringObject or MonitoringObjectGroup) depending on the object, like the 2007R2 methods used to. You can also use PartialMonitoringObject, which can return objects of type PartialMonitoringObjectGroup and is faster if you don't need any object properties.

    Let me know if this doesn't work for you. Good luck!

    Cheers, Richard


    Richard Benwell www.squaredup.com

    • Marked as answer by PMMagalhães Tuesday, October 23, 2012 2:25 PM
    Tuesday, October 23, 2012 2:08 PM
  • That does the trick!

    Thank you for your help! Really appreciate it.

    Best regards, Pedro

    Tuesday, October 23, 2012 2:26 PM