5 Replies Latest reply on Mar 27, 2014 6:51 PM by Bill Robinson

    Add component smart group to compliance job via blcli

    Magnus Ruschpler

      Version 8.2.4: Is there a way to add component smart groups to compliance jobs via blcli? I found this command only:

      "ComplianceJob addSJobComponentGroup" but it does not accept a smart group.

       

      Code:

      ------------

      targetGroup="/some/path/to/component smartgroup"

      complianceJob="/some/path/to/compliance job"

      blcli_execute SmartComponentGroup findGroupByQualifiedName "$targetGroup"

      blcli_storeenv componentGroupKey

      blcli_execute ComplianceJob getDBKeyByGroupAndName "${complianceJob:h}" "${complianceJob:t}"

      blcli_execute Utility setTargetObject

      blcli_execute ComplianceJob addSJobComponentGroup "$componentGroupKey"

      ------------

       

      Error message:

      ------------

      Command execution failed. com.bladelogic.om.infra.cli.factory.CommandNotFoundException: Found command 'ComplianceJob.addSJobComponentGroup' but with mismatching arguments. : java.lang.IllegalArgumentException: Bad db key token : com.bladelogic.om.infra.model.group.smartgroup.SmartGroupImpl@e3c1b8d

      ------------

       

      The problem is that "addSJobComponentGroup" expects a com.bladelogic.om.infra.model.base.keys.SBLGroupKey. but I didn't find a command which accepts com.bladelogic.om.infra.model.group.smartgroup.SmartGroup.

       

      Any idea how to pass a smartgroup?

       

      Export/import could be an option but this does not include component smart groups so it doesn't help.

       

      Some background to this request:

      I want to automate creation of compliance jobs. Therefore I want to add a component smart group in order to schedule the compliance job and automatically execute it against new components which will pop up in this component smart group. Adding individual components to a compliance job would be static and adding servers or server smart groups instead of component smart groups do not reflect the discover rules in the underlying component template because the discover rules are based on extended objects, not server properties.

       

      Thanks

      Magnus

        • 1. Re: Add component smart group to compliance job via blcli
          Bill Robinson

          you don't have the key there for the group, you have a string representation of the java object.  i think you need to do this:

           

          targetGroup="/some/path/to/component smartgroup"

          complianceJob="/some/path/to/compliance job"

          blcli_execute SmartComponentGroup findGroupByQualifiedName "$targetGroup"

          blcli_execute Group getSBLGroupKey

          blcli_execute Utility setTargetObject

          blcli_storeenv componentGroupKey

          blcli_execute ComplianceJob getDBKeyByGroupAndName "${complianceJob:h}" "${complianceJob:t}"

          blcli_execute Utility setTargetObject

          blcli_execute ComplianceJob addSJobComponentGroup "$componentGroupKey"

          • 2. Re: Add component smart group to compliance job via blcli
            Magnus Ruschpler

            This gives a different error message: "object is not an instance of declaring class".

            For debugging I added some echos and 'set -x' before the last blcli_execute to see what is passed.

             

            Code:

            ------------------

            targetGroup="/some/path/to/component smartgroup"

            complianceJob="/some/path/to/compliance job"

            echo "SmartComponentGroup findGroupByQualifiedName: "

            blcli_execute SmartComponentGroup findGroupByQualifiedName "$targetGroup"

            echo ""

            echo "Group getSBLGroupKey: "

            blcli_execute Group getSBLGroupKey

            blcli_execute Utility setTargetObject

            blcli_storeenv componentGroupKey

            echo ""

            echo "ComplianceJob getDBKeyByGroupAndName: "

            blcli_execute ComplianceJob getDBKeyByGroupAndName "${complianceJob:h}" "${complianceJob:t}"

            blcli_execute Utility setTargetObject

            echo ""

            echo "ComplianceJob addSJobComponentGroup: "

            set -x

            blcli_execute ComplianceJob addSJobComponentGroup "$componentGroupKey"

            ------------------

             

            Result:

            ------------------

            SmartComponentGroup findGroupByQualifiedName:

            com.bladelogic.om.infra.model.group.smartgroup.SmartGroupImpl@98d4e9a5

            Group getSBLGroupKey:

            DBKey:SBLGroupModelKeyImpl:2000512-2883700DBKey:SBLGroupModelKeyImpl:2000512-2883700

            ComplianceJob getDBKeyByGroupAndName:

            DBKey:SJobModelKeyImpl:1119-2-2916794DBKey:SJobModelKeyImpl:1119-2-2916794

            ComplianceJob addSJobComponentGroup:

            +./createComplianceJobs.nsh:259> blcli_execute ComplianceJob addSJobComponentGroup DBKey:SBLGroupModelKeyImpl:2000512-2883700

            Command execution failed. java.lang.IllegalArgumentException: object is not an instance of declaring class

            ------------------

            • 3. Re: Add component smart group to compliance job via blcli
              Bill Robinson

              targetGroup="/Workspace/All Components"

              complianceJob="/Workspace/Test/Compliance/ParameterRemediation"

              blcli_execute SmartComponentGroup findGroupByQualifiedName "$targetGroup"

              echo "Group getSBLGroupKey: "

              blcli_execute Group getSBLGroupKey

              blcli_execute Utility setTargetObject

              blcli_storeenv componentGroupKey

              blcli_execute ComplianceJob getDBKeyByGroupAndName "${complianceJob:h}" "${complianceJob:t}"

              blcli_storeenv jobKey

              blcli_execute Job findByDBKey $jobKey

              blcli_execute Utility storeTargetObject job

              blcli_execute ComplianceJob addSJobComponentGroup "$componentGroupKey"

              blcli_execute Job update NAMED_OBJECT=job

              • 4. Re: Add component smart group to compliance job via blcli
                Magnus Ruschpler

                Awesome, thank you.

                 

                I would like to learn more theory from this example to get away from try-and-error:


                1. In which cases does the "update" command have to be used?
                2. What does the "S" in "getSBLGroupKey" or "addSJobComponentGroup" indicate?
                3. What is the difference between a) "blcli_execute Utility setTargetObject; blcli_storeenv componentGroupKey" and b) "blcli_storeenv componentGroupKey"? Is the outcome of a) a reference in the sense of a pointer to an object whereas the outcome of b) is just a string representation of the object? How do I know that commands like addSJobComponentGroup require a pointer rather than a string as parameter? Is it true that "Command Type = Load" require pointers and "Command Type = API" require strings?
                4. In which cases do I have to write "NAMED_OBJECT=something" instead of "something"? E.g. from the list of invoked commands for "JobGroup applyAclTemplate" I see command "Group.applyAclTemplate $groupName$ NAMED_OBJECT=gModType $templateName$ $replace$". gModType was the result of "Utility convertModelType" which returns a Integer, not an object like "com.bladelogic.om.infra.....". So why "NAMED_OBJECT=..." instead of "blcli_storeenv something" and pass "something" to next command without "NAMED_OBJECT="?
                5. Is there a debug option to get more insights about what is expected by a command (string vs. pointer vs. NAMED_OBJECT=)?
                • 5. Re: Add component smart group to compliance job via blcli
                  Bill Robinson

                  have you looked through everything here:

                  Unreleased blcli commands and documentation

                   

                  1 - typically after you load an object into memory and make changes it it w/ set commands.

                  2 - that's a good question.

                  3 - blcli_storeenv creates a global shell variable and sets the value to whatever string is in the current context

                  most of the load.  Utility storeTargetObject objName stores a java object in memory.  you need to look at the input the particular command takes.  some commands will take a mix of strings and objects.

                  4 - when you need to reference an object vs a string.  in that example you don't need to use the object reference you can use the string - if you follow that through to the Group.applyAclTemplate command you see it takes strings and ints

                  5 - not that i've seen.

                   

                  usually if it's not an int, string or dbkey you'll need a java object for the input.  this is why we have classified this stuff as 'unreleased'