5 Replies Latest reply on Jun 9, 2014 11:08 AM by Ryan Baker

    CLI for Members of a Provision Device Group?



      I'm trying to create a NSH script to set a property on provisioning devices all provisioning devices in a smart group.  The smart group is configured with to include servers in a specific location.  I then want to use that specific location to assign a client to the device group so that it can be used in scripts while provisioning the device.


      I am able to do this with server objects using the following NSH script:




      for groupName in ${staticGroups} do

          blcli_execute Server listServersInGroup "${groupName}"


          blcli_storeenv serverList


          for server in ${serverList} do

              blcli_execute Server setPropertyValueByName "${server}" Client "client_A"




      However - it doesn't look like there is a "listDevicesInGroup" commands available for "Devices."  I've poked around looking for different ways that I can do it, but I haven't come across much should of listing all PM devices, then getting the custom attribute from each device, and checking that for the attribute value(s) I am looking for.


      This presents 2 problems.  Problem 1, I would really like to avoid having the logic for values I am looking contained inside of the script for easy maintainability.  Problem 2, this would be really expensive and time consuming to iterate through every provisioning devices, then make another call to retrieve the custom attribute value, evaluate it, then set another attribute.


      Is there a CLI I am missing?  I certainly hope so, as it looks like every object has the listXinGroup excite for devices .  This is 8.3, by the way.



        • 1. Re: CLI for Members of a Provision Device Group?
          Yanick Girouard

          Doesn't seem like you can do it, even with unreleased commands. You should post this as an Idea.


          If you are knowledgable in SQL, you should take a look at those tables in the BSA core database:


          blgroup:  contains group information, including smartgroups


          smart_group_query: contains the sql that is run by smartgroups

          object_overflow_details: if the query is to long, it will be split into multiple overflow records, this is where they are stored. Look at the "is_overflow" field in the smart_group_query table, and if it' s1, then use the object_overflow_id to get the additional SQL to build the whole query. They are ordered using the sequence_id field.


          With this you should be able to run the smartgroup artificially and return the list of devices that match, and then run through them using blcli to set property values.

          • 2. Re: CLI for Members of a Provision Device Group?
            Bill Robinson

            look at ProvisionDevice.findAllByPmDeviceGroup

            1 of 1 people found this helpful
            • 3. Re: CLI for Members of a Provision Device Group?
              Yanick Girouard

              D'oh ! How did I miss that ? /facepalm


              Ryan, here's something you could use:


              blcli_execute Group groupNameToId "/Imported" 5044 > /dev/null
              blcli_storeenv PM_SMART_GROUP_ID > /dev/null
              blcli_execute ProvisionDevice findAllByPmDeviceGroup $PM_SMART_GROUP_ID false > /dev/null
              blcli_execute ProvDevice getName > /dev/null
              blcli_execute Utility setTargetObject > /dev/null
              blcli_execute Utility listPrint


              Just change the /Imported with the path/name of your PM device smart group.

              • 4. Re: CLI for Members of a Provision Device Group?

                Thanks - I actually had tried that, but was having some issues then getting the group ID from a device smart group.  I then went to the database and got it from the DB, but they I was getting an error about returning "null".


                I'll try this and report back.  Thanks again!

                • 5. Re: Re: CLI for Members of a Provision Device Group?

                  Thanks Bill and Yanick - this worked great.


                  For anyone else trying to do this same thing, here is the code I am using.  I added a for loop at the end to set the values on each provisioning device.  Other than that - it's the code Yanick provided.


                  #Get the ID of the Group

                  blcli_execute Group groupNameToId "/Location_A" 5044 > /dev/null

                  #Store the results in to a variable to use later

                  blcli_storeenv PM_SMART_GROUP_ID > /dev/null 

                  #Get all the Devices in the group

                  blcli_execute ProvisionDevice findAllByPmDeviceGroup $PM_SMART_GROUP_ID false > /dev/null 

                  #Get the mac addresses from the group

                  blcli_execute ProvDevice getName > /dev/null 


                  #List out all of the mac addresses to iterate through them

                  blcli_execute Utility setTargetObject > /dev/null 

                  blcli_execute Utility listPrint > /dev/null

                  blcli_storeenv macAddresses


                  # Iterate through each mac address and add the client value

                  for device in ${macAddresses}


                      echo ${device}

                      blcli_execute ProvisionDevice setPropertyValue $device Client "CLIENT_A"


                  1 of 1 people found this helpful