4 Replies Latest reply on Sep 27, 2017 3:51 PM by Bill Robinson

    How to loop through a Component Template smartgroup?

    Stephen Sweeney

      I need to remove all the "everyone.read" permission from all the component Templates to close a serious security hole. I have added all the Component templates to a smartgroup and now need to loop through the list, check if the everyone permission is there, and then remove it.

      I do not see a category called ComponentTemplate in the blcli command list.... I am looking for the same sort of command as:

       

      blcli Server listServersInGroup /someCTfolder

       

      But for component Templates.... Once I have this, I should be able to work out the rest.

       

      Thanks Steve

       

        • 1. Re: How to loop through a Component Template smartgroup?
          Bill Robinson

          haha - i was about to post a blog entry about listing things in a group for the various namespaces...

           

          blcli_execute TemplateGroup groupNameToDBKey "${templateGroup}"

          blcli_storeenv templateGroupKey

          blcli_execute Template findAllByGroup ${templateGroupKey} true

          blcli_execute Template getDBKey

          blcli_execute Utility setTargetObject

          blcli_execute Utility listPrint

          blcil_storeenv templateKeys

          # remove empty last line

          templateKeys="$(awk 'NF' <<< "${templateKeys}")"

          while read templateKey

               do

               blcli_execute Template removePermission ${templateKey} 'Everyone' 'ComponentTemplate.Read'

          done << "${templateKeys}"

          • 2. Re: How to loop through a Component Template smartgroup?
            Stephen Sweeney

            Thanks Bill... You got me on the right track... Once again, I think I got confused between component and component Templates.

            I managed to use your script and rewrite it for components.

             

            I am trying to add all the components that need permissions fixed to a Group I created. Mostly for CR... I have tested the script to clean this up, and it does work directly.

             

            I have the Component ID, and the DBKey...

            I have the name and DBKey of the new group.

             

            The command appears to be:

             

            Command Name : addComponentToGroup

            Name space : ComponentGroup

             

            The Variables are:

             

            Command Input :

            Variable NameVariable TypeDescription
            g com.bladelogic.om.infra.model.group.ComponentGroup no description
            id Integer no description
            name String no description

             

             

            Not sure why the descriptions are not listed.... But here is what I came up with:

            g = group name

            id is the component id

            name not really sure

             

            If name is the name of the component... Is there a command to get name from ID or DBkey?

             

            Thanks for the help.

            • 3. Re: How to loop through a Component Template smartgroup?
              Stephen Sweeney

              So I found a way to. get the servers added to a group....

              Next problem, I created a backout situation based on the DBkey... However, looks like that changes and I get an error that the key has changed.

              Does the Component Template and Component ID also change, or only the DBkey.

               

              Thanks for the help

              Steve

              • 4. Re: How to loop through a Component Template smartgroup?
                Bill Robinson

                I would use StaticComponentGroup.addComopnentToComponentGroup.  that takes the group id and dbkey of the component.  or addComponentToComponentGroupByGroupAndDBKey which takes the path to the component group and the dbkey of the component.

                 

                I created a backout situation based on the DBkey

                to remove the component from the group ?

                 

                Does the Component Template and Component ID also change, or only the DBkey.

                generally DBKey = object id + object version id.  the dbkey will change when the object is altered (the version id is bumped) but the object id remains the same.

                 

                you remove the component some time later ?  how do you know which one to remove ?