6 Replies Latest reply on Apr 22, 2016 10:37 AM by Bill Robinson

    NSH Script to remove exceptions from a component template

    sachin Manjunath

      Version 8.2.4: We are trying to remove all the exceptions added for the rules for the specific template below is the script used and the error message.


      Code :


      TEMPLATE_GROUP="/component template folder"

      TEMPLATE_NAME="component template name"

      EXCEPTION_NAME="exception name"

       

      blcli_execute Template getDBKeyByGroupAndName "$TEMPLATE_GROUP" "$TEMPLATE_NAME"

      blcli_storeenv TEMPLATE_DBKEY

       

      blcli_execute Component getAllComponentKeysByTemplateKey $TEMPLATE_DBKEY

      blcli_storeenv COMPONENT_KEY

       

      for KEY in $COMPONENT_KEY

      do

           KEY=`echo $KEY | tr -d '[:cntrl:]'`

           blcli_execute ComponentException removeComponentExceptionByName "$EXCEPTION_NAME" "$KEY"

      done

       

      Error Message :

       

      Error 1:

      Command execution failed. com.bladelogic.om.infra.cli.factory.CommandNotFoundException: Found command 'ComponentException.removeComponentExceptionByName' but with mismatching arguments. : java.lang.IllegalArgumentException: Bad db key token

       

      Error 2:

      /app/bladelogic/NSH/tmp/"appservername"/scripts/job__5a5e1c95-986a-4fba-9aa8-6bacb45fc42c/script_DBKey-SJobKeyImpl-3935454-1__0ec2d07a-edee-4647-a5f4-a1a6e1124e7a.3464562.1_exceptions removal.sh:1: arg list too long: /app/bladelogic/NSH/bin/tr



      Any idea to get through this

        • 1. Re: NSH Script to remove exceptions from a component template
          Bill Robinson

          the 2nd error is probably because the COMPONENT_KEY variable is too large for the shell to handle..  so you might want to try this:

           

          ...

          blcli_storeenv TEMP_KEYS

          COMPONENT_KEYS="${TEMP_KEYS}"

          unset TEMP_KEYS

           

          for KEY in ${COMPONENT_KEYS}

          do

               blcli_execute ComponentException removeComponentExceptionByName "${EXCEPTION_NAME}" ${KEY}

          done

           

           

          --

           

          i don't think you need the tr

          1 of 1 people found this helpful
          • 2. Re: NSH Script to remove exceptions from a component template
            sachin Manjunath

            Hi Bill,

             

            It worked but now i am getting a different error because for a single rule there are different exception names.

             

            Is it possible to remove all the exception from a component template with exception name, please let me know,

             

            Thanks in Advance.

             

            Sachin

            • 3. Re: NSH Script to remove exceptions from a component template
              sachin Manjunath

              i had one more script but still i am facing issues

               

              TEMPLATE_GROUP="/FOLDER"

              TEMPLATE_NAME="NAME"

              EXCEPTION_NAME="NAME"

               

              blcli_execute Template getDBKeyByGroupAndName "$TEMPLATE_GROUP" "$TEMPLATE_NAME"

              blcli_storeenv TEMPLATE_DBKEY

               

              blcli_execute Component getAllComponentKeysByTemplateKey $TEMPLATE_DBKEY blcli_storeenv COMPONENT_KEY

               

              for KEY in $COMPONENT_KEY

              do

                   blcli_execute ComponentException removeComponentExceptionByName "$EXCEPTION_NAME" "$KEY"

              done

               

              below is the error:

               

              Command execution failed. com.bladelogic.om.infra.cli.factory.CommandNotFoundException: Found command 'Component.getAllComponentKeysByTemplateKey' but with mismatching arguments. : java.lang.IllegalArgumentException: Wrong number of arguments provided to method : getAllComponentKeysByTemplateKey expected : 1 received : 3

               

               

              Thanks,

              Sachin

              • 4. Re: NSH Script to remove exceptions from a component template
                Bill Robinson

                ?it looks like the blcli_storeenv is on the same line as the blcli_execute where you get the component keys...so it's being evaluated as an argument to the blcli_execute.  it should be on a separate line.

                • 5. Re: NSH Script to remove exceptions from a component template
                  Alan Russell

                  Old thread but I'll ask since this is the best hit from my search.  I want to list out all the rule exceptions in a compliance template by date added or just list them period.  I don't do much cli scripting but it seems that what I want to do can be done by manipulating the commands in this script.  Doesn't seem to be a way to get that information from the BL console gui very efficiently so I am thinking cli is preferable.    

                   

                   

                  Regards,

                  Alan

                  • 6. Re: NSH Script to remove exceptions from a component template
                    Bill Robinson

                    I think something like:

                     

                    blcli_execute Component getAllComponentKeysByTemplateKey $TEMPLATE_DBKEY blcli_storeenv COMPONENT_KEY

                     

                    for KEY in $COMPONENT_KEY

                    do

                         blcli_execute Component findByDBKey ${KEY}

                          blcli_execute Component getComponentExceptions

                         blcli_execute Utility storeTargetObject exceptions

                       blcli_execute Utility listLength

                         blcli_storeenv listLength

                         for i in {0..$((${listLength}-1))}

                         do

                         blcli_execute Utility setTargetObject exceptions

                         blcli_execute Utility listItemSelect ${i}

                         blcli_execute Utility setTargetObject

                         blcli_execute ComponentException getName

                         blclI_storeenv eName

                         blcli_execute ComponentException getDescription

                         blcli_storeenv eDescription

                    ....

                         done

                    done

                     

                    look at all the 'get***' commands in the ComponentException space in the unreleased blcli docs.