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.

Groups Dynamic Query created via SDK, but not applied??

I have the following script that creates my missing groups in Orion:

#Creating a table with sites creation needed: 
$GroupsToCreate = $allnbsites | Where-Object { $_.name -in $MissingGroups.DefinedEng } | Select-Object url, name, status, region, facility, physical_address, latitude, longitude

foreach ($gtc in $groupsToCreate) {
    $BMR_Eng_Number = $gtc.Name
    $groupName = $gtc.facility
    $longitude = $gtc.Longitude
    $latitude = $gtc.Latitude

    #creating the group:
    Invoke-SwisVerb $swis "Orion.Container" "CreateContainer" @(
        # group name
        $groupname, 
        # owner, must be 'Core'
        "Core",
        # refresh frequency
        60,
        # Status rollup mode: 0 = Mixed status shows warning, 1 = Show worst status, 2 = Show best status
        0,
        # group description
        "Created by Provisioning Script (PL) v1.0",
        # polling enabled/disabled = true/false (in lowercase)
        $true, 
        ([xml]"<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion' />").DocumentElement)

    #Getting newly group information: 
    $groupData = Get-SwisData $swis @"
    SELECT gcp.ContainerID, g.Name, g.LastChanged, gcp.BMR_Eng_Number, gcp.BMR_Site_Type, gcp.Longitude, gcp.Latitude, gcp.LMRN_Description, gcp.LMRN_Zone, g.URI, CASE WHEN g.URI IS NOT NULL THEN CONCAT(g.URI,'/CustomProperties') ELSE NULL END AS CP_URI 
    FROM Orion.GroupCustomProperties gcp
    LEFT JOIN Orion.Groups g on gcp.ContainerID = g.ContainerID
    WHERE g.Name = '$groupname'
"@

    #Populating custom properties of the new group:
    $CP = @{
        "BMR_Eng_Number"   = $BMR_Eng_Number
        "Longitude"        = $longitude
        "Latitude"         = $latitude
    }
    Set-SwisObject $swis $groupData.CP_URI $CP

    # Creating dynamic to populate group:
    $members = @(
        @{ Name = "BMR_Eng_Number is $BMR_Eng_Number"; Definition = "filter:/Orion.Nodes[CustomProperties.BMR_Eng_Number=$BMR_Eng_Number]" }
    )
    Invoke-SwisVerb $swis "Orion.Container" "AddDefinitions" @(
        # group ID
        $groupData.ContainerID,
        # group member to add
        ([xml]@(
            "<ArrayOfMemberDefinitionInfo xmlns='http://schemas.solarwinds.com/2008/Orion'>",
            [string]($members | % {
                    "<MemberDefinitionInfo><Name>$($_.Name)</Name><Definition>$($_.Definition)</Definition></MemberDefinitionInfo>"
                }
            ),
            "</ArrayOfMemberDefinitionInfo>"
        )).DocumentElement
    ) | Out-Null
}

This is mostly inspired by https://github.com/solarwinds/OrionSDK/blob/master/Samples/PowerShell/Groups.ps1

As expected, the groups gets created properly, the groups has the custom properties assigned, and a dynamic Query is attached to the group.

My problem is that once created, the dynamic query has no effect and does not populate the group.

If I go and look group properties, and click on "View Dynamic Query Results", I have a never ending spinning wheel:

To fix this issue, I found that if i click on "Edit Dynamic Query", and click Save right away, I can then click on "View Dynamic Query Results" and the expected nodes are there!!

Not sure if it is an API issue or a platform one... Am I missing something?

Running: Orion Platform HF2, UDT HF2, NCM HF1, NPM HF2, SAM HF2, NTA HF1: 2020.2.6

Parents
  • I Heart that people are using the API this way.  From a casual a look, it appears that your logic is sound, but I want to try it in my own lab.  Any chance you can attach an example of your $GroupsToCreate variable (Export-Csv output is fine) so I understand the properties you are passing?

  • , Have you had the chance to try it in your lab? Should I open a ticket on this or the chance of being told "API use is not supported" is too high?

  • Sorry, no.  Been doing Livecasts and other things.  I'll take a look soon.  Sorry about the delay.  Life got in the way.

  • Dont be sorry, I love those Livecasts. In fact, the last one using the Orion Alerting Engine as an automation was an eye opening for me. I will probably move some of my group & custom properties cleanup task to the alerting engine instead of trying to maintain those script/cron jobs. Sunglasses

  • These are my results:

    Dynamic Definition:

    I noticed that you are assigning the custom properties to a "Group",

    But this line says: Filter based on a Node:

    There's a defined limitation that you can't have a dynamic Group within another Group (though you can create one in the API).  The problem we're trying to avoid is exactly what you are describing - the chance that it could recursively call itself indefinitely.

    I'm attaching the script I used (basically it's yours, but I refactored it a little for ease of my reading).

    Working.GroupCreation.ps1

  • Thanks for looking into this! Much appreciated! :)

    The custom property BMR_Eng_Number exists for both groups and nodes. Sorry, that was not obvious in my description. So, all my nodes have a mandatory BMR_Eng_Number custom property filled with one of those location codes.

    When I create the group, it gets the Name, description and other custom properties like BMR_Eng_Number and GPS coordinates... All good!

    What I want to achieve, once the group is created, is to have a dynamic query that will populate the group with nodes having the same BMR_Eng_Number. In this case, I am not trying to nest a group in there, but simply add nodes.

    If I manually create a group and create a Dynamic Query based on node BMR_Eng_Number, it's all good. As expected, nodes having the specified BMR_Eng_Number location (ie A1111) code are automagically added to the group.

    If I do it using the script, it creates the Dynamic Query but it does not apply it. The group stays empty (and the query preview endlessly spins without providing results). I have to manually go in the group definition, edit the dynamic query (without modifying anything) and save it so it gets applied. Once that manual intervention is done, Nodes are appearing in the group...

    Could it be related to the same logic happening when I try to remove a volume from a node and Orion doesn't know it's gone (CORE-17992) ? To bypass that issue, I had to unmanage the volume first than remove it like if the API was making the change, but Orion was not aware of it...

Reply
  • Thanks for looking into this! Much appreciated! :)

    The custom property BMR_Eng_Number exists for both groups and nodes. Sorry, that was not obvious in my description. So, all my nodes have a mandatory BMR_Eng_Number custom property filled with one of those location codes.

    When I create the group, it gets the Name, description and other custom properties like BMR_Eng_Number and GPS coordinates... All good!

    What I want to achieve, once the group is created, is to have a dynamic query that will populate the group with nodes having the same BMR_Eng_Number. In this case, I am not trying to nest a group in there, but simply add nodes.

    If I manually create a group and create a Dynamic Query based on node BMR_Eng_Number, it's all good. As expected, nodes having the specified BMR_Eng_Number location (ie A1111) code are automagically added to the group.

    If I do it using the script, it creates the Dynamic Query but it does not apply it. The group stays empty (and the query preview endlessly spins without providing results). I have to manually go in the group definition, edit the dynamic query (without modifying anything) and save it so it gets applied. Once that manual intervention is done, Nodes are appearing in the group...

    Could it be related to the same logic happening when I try to remove a volume from a node and Orion doesn't know it's gone (CORE-17992) ? To bypass that issue, I had to unmanage the volume first than remove it like if the API was making the change, but Orion was not aware of it...

Children
No Data