none
Create several groups from Discovery with dynamic membership RRS feed

  • Question

  • I'm trying to accomplish the following

    1 - I have a CSV file where I want to read out a bunch of names (clusters). Foreach name I want to create an instance group.

    2 - The group should have a dynamic membership.

    I don't know how to achieve number one. I have the knowledge to read out the CSV and populate SCOM with objects in a class. Just not sure how to create several Instance Groups. Anyone?



    • Edited by sweprs Tuesday, October 1, 2019 10:33 AM
    Tuesday, October 1, 2019 10:25 AM

Answers

  • There is, actually :

    - Declare a class for your group, using the regular Microsoft.SystemCenter.InstanceGroup base class but not as a singleton, which  mean you also have to declare a key property. That will allow you to create multiple instance of the same group class : 

    <ClassType ID="TEST.DynamicGroups.Group" Accessibility="Public" Abstract="false" Base="GroupLib!Microsoft.SystemCenter.InstanceGroup" Hosted="false" Singleton="false" Extension="false">

    <Property ID="GroupName" Type="string" AutoIncrement="false" Key="true" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" Scale="0" />

    </ClassType>


    - Then in the discovery script, add a loop that will create a discovery instance for each entry in your csv. Something like this : 

    # Load MOMScript API
    $momapi = New-Object -comObject MOM.ScriptAPI
    # Load SCOM Discovery module
    $DiscoveryData = $momapi.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)
    
    $Groups = ##whatever result from your CSV file containing at least a property with the group name
    
    foreach ($Group in $Groups)
    {
    $GroupName = $Group.Name
    
    $GroupInstance = $DiscoveryData.CreateClassInstance("$MPElement[Name='TEST.DynamicGroups.Group']$")
    
    $GroupInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $GroupName)
    
    $GroupInstance.AddProperty("$MPElement[Name='TEST.DynamicGroups.Group']/GroupName$", $GroupName)
    
    }
    
    # Return Discovery Items Normally           
     $DiscoveryData

    If you need a a full fragment, there are a few in Kevin Holman's fragment library but they are for single groups, so you will need to modify them with the loop shown here and with the class not declared as singleton+with a key property
    Thursday, October 3, 2019 12:30 PM

All replies

  • Hi,

    you can always use PowerShell and the scripts that are out there to accomplish this and create groups from a CSV in bulk. The biggest challenge (and here where it gets pretty complex) is to make thoise groups dynamic, meaning populate the groups with the help of a dynamic rule.

    You can read more about the possible (but very complex) approach in the comment section of the following article:

    Creating Groups in SCOM 2012 with PowerShell

    Here some additional information on the topic:

    Modifying Explicit Group Membership in SCOM 2012 with PowerShell

    and

    Automate SCOM Group Creation

    AS you will see all of the automation capabilities are limited to creating groups with static membership.

    Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov


    Tuesday, October 1, 2019 2:16 PM
    Moderator
  • Hi There,

    You could create SCOM group from CSV by taking reference of below links,

    https://www.systemcenterautomation.com/2018/01/automate-scom-group-creation/

    https://blogs.msdn.microsoft.com/rslaten/2013/06/06/creating-groups-in-scom-2012-with-powershell/

    Now coming back to second concern, Not sure if we can do or not as I have not find any set cmdlet for scom group. But we need to check all member for group using Get-SCOMGroup | GM , might be it has anything.



    Cheers, Gourav Please remember to mark the replies as answers if it helped.


    Tuesday, October 1, 2019 2:26 PM
  • Hi

    Actually I was looking to do it a Management Pack. Sorry for not being clear about that

    Thursday, October 3, 2019 8:23 AM
  • Hi

    Actually I was looking to do it a Management Pack. Sorry for not being clear about that

    Hi,

    maybe you can take this one and do some reverse engineering:

    SCOM 2007: Dynamically populating a group from txt file

    The only difference is that this MP uses a txt not a CSV file. In any case you will need a script discovery that reads the CSV (either PowerShell or VBScript).

    The other option would be to use a tool like this one:

    Group Creation Tool for Operations Manager

    but I cannot comment on it since I haven't tested it. 

    Regards,


    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer" where applicable. This helps the community, keeps the forums tidy, and recognizes useful contributions. Thanks!) Blog: https://blog.pohn.ch/ Twitter: @StoyanChalakov


    Thursday, October 3, 2019 8:36 AM
    Moderator
  • This is for populating a group. Not for creating new groups. 

    Doesn't seem to be a good solution out there regarding this :-(


    • Edited by sweprs Thursday, October 3, 2019 11:25 AM
    Thursday, October 3, 2019 11:24 AM
  • There is, actually :

    - Declare a class for your group, using the regular Microsoft.SystemCenter.InstanceGroup base class but not as a singleton, which  mean you also have to declare a key property. That will allow you to create multiple instance of the same group class : 

    <ClassType ID="TEST.DynamicGroups.Group" Accessibility="Public" Abstract="false" Base="GroupLib!Microsoft.SystemCenter.InstanceGroup" Hosted="false" Singleton="false" Extension="false">

    <Property ID="GroupName" Type="string" AutoIncrement="false" Key="true" CaseSensitive="false" MaxLength="256" MinLength="0" Required="false" Scale="0" />

    </ClassType>


    - Then in the discovery script, add a loop that will create a discovery instance for each entry in your csv. Something like this : 

    # Load MOMScript API
    $momapi = New-Object -comObject MOM.ScriptAPI
    # Load SCOM Discovery module
    $DiscoveryData = $momapi.CreateDiscoveryData(0, $SourceId, $ManagedEntityId)
    
    $Groups = ##whatever result from your CSV file containing at least a property with the group name
    
    foreach ($Group in $Groups)
    {
    $GroupName = $Group.Name
    
    $GroupInstance = $DiscoveryData.CreateClassInstance("$MPElement[Name='TEST.DynamicGroups.Group']$")
    
    $GroupInstance.AddProperty("$MPElement[Name='System!System.Entity']/DisplayName$", $GroupName)
    
    $GroupInstance.AddProperty("$MPElement[Name='TEST.DynamicGroups.Group']/GroupName$", $GroupName)
    
    }
    
    # Return Discovery Items Normally           
     $DiscoveryData

    If you need a a full fragment, there are a few in Kevin Holman's fragment library but they are for single groups, so you will need to modify them with the loop shown here and with the class not declared as singleton+with a key property
    Thursday, October 3, 2019 12:30 PM
  • Also note that since a group is an unhosted class, the discovery may run from any Management Server; which means that the CSV must be reachable from all of the MS.

    And since there is only one class, you can't use a dynamic discovery rule : you will also have to populate the groups from inside the script. Once again you have examples of such code in KEvin's fragments.



    • Edited by CyrAz Thursday, October 3, 2019 12:55 PM
    Thursday, October 3, 2019 12:54 PM
  • This works, I can now create group instances from the csv. Now for the tricky part with dynamic membership also... hmmm :-)
    Friday, October 4, 2019 7:30 AM