This discussion has been locked. The information referenced herein may be inaccurate due to age, software updates, or external references.
You can no longer post new replies to this discussion. If you have a similar question you can start a new discussion in this forum.

Multiple groups - Is there a simple way

Hi all,

I have a slight challenge within my environment that might have a simple solution... I need to create various groups for nodes that are separated via building or location but cannot find a simple way of creating multiples other than one at a time (1-by-1).

Within the setup,I have a custom property on all the nodes that defines the location of the device. Other than 1-by-1 group builder, is there a method that can be used to create multiple groups by passing dynamic variables? ... Please see the basic example below of what I am trying to achieve:

Top Level Group - Dynamic Query Selected by customer (The top-level group has been created)

     Sub Group - (Location 1)

          Nodes in this group require a dynamic query for the "Location A"

     Sub Group - (Location 2)

          Nodes in this group require a dynamic query for the "Location B"

     Sub Group - (Location 3)

          Nodes in this group require a dynamic query for the "Location C"

... and so forth ...

I am happy to create all groups separately if there is no other method. However, I have a minimum list of 50 + locations that I would like to separate into groups, it will become time consuming very quickly.

If there is another method via scripting that would work for the creation of the multiple sub-groups by using dynamic, please walk me through how I can set this up as it will save me a lot of setup time. (I do have some knowledge and experience with PowerShell scripting, but haven't yet looked if I can interact directly or apply the correct variables).

Thanks in advance,

Tom

  • Check out the github for the SDK, it has examples of manipulating the groups.  Particularly of interest I think would be the create group with parent verb.   Back when I didn't even know powershell I was able to take those examples and build a script that walks through a list of custom properties and nests groups inside each other to build out a tree like you describe.  the current version of it has a lot of internal extra logic in it now that I think would just complicate it to others but I can probably dig up a sanitized simple example after I get done today.

  • Yes.

    Downloading the SKD and looking at how to write the SQL is on my many list of things to do emoticons_happy.png

    Generally would be legend to even see a simple version of the idea to get my head around this better... I feel its because its a new language to me I am just like "uhhhh, i don't know". XD

  • This is a sanitized example of a powershell script that creates a tree with 5 nested layers.  It's pretty overkill for most use cases and the specific example here assumes you have a stack of custom properties and SAM and WPM so most people would be able to just copy this and run it in their environment, mostly just useful as an example of using the verbs.

    <#------------- CONNECT TO SWIS -------------#>

    # load the snappin if it's not already loaded (step 1)

    if (!(Get-PSSnapin | Where-Object { $_.Name -eq "SwisSnapin" })) {

      Add-PSSnapin "SwisSnapin"

    }

    #define target host and credentials

    $hostname = 'localhost'

    #$user = "admin"

    #$password = "password"

    # create a connection to the SolarWinds API

    #$swis = connect-swis -host $hostname -username $user -password $password -ignoresslerrors

    $swis = Connect-Swis -Hostname $hostname -Trusted

    <#------------- ACTUAL SCRIPT -------------#>

    ##### Phase 1 - Create groups tree #######

    ###get businessunits list

    $businessunits = get-swisdata $swis2 @"

    select distinct n.CustomProperties.BusinessUnit

    from orion.nodes n

    left join orion.Container c on c.name= n.CustomProperties.BusinessUnit

    where n.CustomProperties.BusinessUnit is not null and n.CustomProperties.BusinessUnit not in ('','unknown','N/A','not applicable')

    --and c.name is null

    order by n.CustomProperties.BusinessUnit

    "@

    foreach($unit in $businessunits)

      {

      #get groupid for parent folder

      $parent = get-swisdata $swis "select top 1 containerid from orion.container where name='Business Units'"

      While ( $parent.length -eq 0 ) {

      "Creating group for Business Units"

      $members = @()

      $parent = (invoke-swisverb $swis "orion.container" "CreateContainer" @(

      "Business Units",

      "Core",

      300,

      0,

      "$application child nodes",

      "true",

      ([xml]@("<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion'>",

    [string]($members |% {

      "<MemberDefinitionInfo><Name>$($_.Name)</Name><Definition>$($_.Definition)</Definition></MemberDefinitionInfo>"

      }

      ),

      "</ArrayOfMemberDefinitionInfo>"

      )).DocumentElement

      )).innertext

      }

      

      "Creating group for $unit"

      $members = @(

      )

      $unitid = (invoke-swisverb $swis "orion.container" "CreateContainerWithParent" @(

      "$parent",

      "$unit",

      "Core",

      300,

      0,

      "",

      "true",

      ([xml]@("<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion'>",

    [string]($members |% {

      "<MemberDefinitionInfo><Name>$($_.Name)</Name><Definition>$($_.Definition)</Definition></MemberDefinitionInfo>"

      }

      ),

      "</ArrayOfMemberDefinitionInfo>"

      )).DocumentElement

      )).innertext

    ######get environments list

      $environments = get-swisdata $swis2 @"

    select distinct concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment) as Environment

    from orion.nodes n

    left join orion.Container c on c.name= concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment)

    where n.CustomProperties.BusinessUnit is not null and n.CustomProperties.BusinessUnit not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.Environment is not null and n.CustomProperties.Environment not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.BusinessUnit = '$unit'

    --and c.name is null

    order by concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment)

    "@

      foreach($env in $environments)

      {

      #get groupid for parent folder

      $parent = get-swisdata $swis "select top 1 containerid from orion.container where name='$unit'"

      "Creating group for $env"

      $members = @(

      )

      $envid = (invoke-swisverb $swis "orion.container" "CreateContainerWithParent" @(

      "$parent",

      "$env",

      "Core",

      300,

      0,

      "",

      "true",

      ([xml]@("<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion'>",

    [string]($members |% {

      "<MemberDefinitionInfo><Name>$($_.Name)</Name><Definition>$($_.Definition)</Definition></MemberDefinitionInfo>"

      }

      ),

      "</ArrayOfMemberDefinitionInfo>"

      )).DocumentElement

      )).innertext

    #########get applications list

      $applications = get-swisdata $swis2 @"

    select distinct concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment,' ',n.CustomProperties.ImpactedApplications) as Applications

    from orion.nodes n

    left join orion.Container c on c.name= concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment)

    where n.CustomProperties.BusinessUnit is not null and n.CustomProperties.BusinessUnit not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.Environment is not null and n.CustomProperties.Environment not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.ImpactedApplications is not null and n.CustomProperties.ImpactedApplications not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.BusinessUnit = '$unit' and concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment) = '$env'

    --and c.name is null

    order by concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment,' ',n.CustomProperties.ImpactedApplications)

    "@

      foreach($app in $applications)

      {

      #get groupid for parent folder

      $parent = get-swisdata $swis "select top 1 containerid from orion.container where name='$env'"

      "Creating group for $app"

      $members = @(

      )

      $appid = (invoke-swisverb $swis "orion.container" "CreateContainerWithParent" @(

      "$parent",

      "$app",

      "Core",

      300,

      0,

      "",

      "true",

      ([xml]@("<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion'>",

    [string]($members |% {

      "<MemberDefinitionInfo><Name>$($_.Name)</Name><Definition>$($_.Definition)</Definition></MemberDefinitionInfo>"

      }

      ),

      "</ArrayOfMemberDefinitionInfo>"

      )).DocumentElement

      )).innertext

    ############get components list

      $components = get-swisdata $swis2 @"

    select distinct concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment,' ',n.CustomProperties.ImpactedApplications,' ',n.CustomProperties.Local_Application_Component) as Components

    from orion.nodes n

    left join orion.Container c on c.name= concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment)

    where n.CustomProperties.BusinessUnit is not null and n.CustomProperties.BusinessUnit not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.Environment is not null and n.CustomProperties.Environment not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.ImpactedApplications is not null and n.CustomProperties.ImpactedApplications not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.Local_Application_Component is not null and n.CustomProperties.Local_Application_Component not in ('','unknown','N/A','not applicable')

    and n.CustomProperties.BusinessUnit = '$unit' and concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment) = '$env' and concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment,' ',n.CustomProperties.ImpactedApplications) = '$app'

    --and c.name is null

    order by concat(n.CustomProperties.BusinessUnit,' ',n.CustomProperties.Environment,' ',n.CustomProperties.ImpactedApplications,' ',n.CustomProperties.Local_Application_Component)

    "@

      foreach($comp in $components)

      {

      #get groupid for parent folder

      $parent = get-swisdata $swis "select top 1 containerid from orion.container where name='$app'"

      #creating variables for definitions

      $env2 = $env -replace "$unit ",''

      $app2 = $app -replace "$env ",''

      $comp2 = $comp -replace "$app ",''

      

      "Creating group for $comp"

      $members = @(

      @{ Name = "$comp Nodes"; Definition = "filter:/Orion.Nodes[CustomProperties.BusinessUnit='$unit' AND CustomProperties.Environment='$env2' AND CustomProperties.ImpactedApplications='$app2' AND CustomProperties.Local_Application_Component='$comp2']" },

      @{ Name = "$comp Applications"; Definition = "filter:/Orion.APM.GenericApplication[CustomProperties.BusinessUnit='$unit' AND CustomProperties.Environment='$env2' AND CustomProperties.ImpactedApplications='$app2' AND CustomProperties.Local_Application_Component='$comp2']" },

      @{ Name = "$comp IIS"; Definition = "filter:/Orion.APM.IIS.Application[CustomProperties.BusinessUnit='$unit' AND CustomProperties.Environment='$env2' AND CustomProperties.ImpactedApplications='$app2' AND CustomProperties.Local_Application_Component='$comp2']" },

      @{ Name = "$comp SQL"; Definition = "filter:/Orion.APM.SqlServerApplication[CustomProperties.BusinessUnit='$unit' AND CustomProperties.Environment='$env2' AND CustomProperties.ImpactedApplications='$app2' AND CustomProperties.Local_Application_Component='$comp2']" },

      @{ Name = "$comp WPM"; Definition = "filter:/Orion.SEUM.Transactions[CustomProperties.Transaction_Group='$comp']" }

      )

      $envid = (invoke-swisverb $swis "orion.container" "CreateContainerWithParent" @(

      "$parent",

      "$comp",

      "Core",

      300,

      0,

      "$comp child nodes and applications",

      "true",

      ([xml]@("<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion'>",

    [string]($members |% {

      "<MemberDefinitionInfo><Name>$($_.Name)</Name><Definition>$($_.Definition)</Definition></MemberDefinitionInfo>"

      }

      ),

      "</ArrayOfMemberDefinitionInfo>"

      )).DocumentElement

      )).innertext

      }

      }

      }

    }