6 Replies Latest reply on Jul 9, 2013 11:41 AM by Bill Robinson Branched to a new discussion.

    Create ComponentException with referenceNumber by script

    Magnus Ruschpler

      Hi,

      we are running BL 8.2.4 and want to create ComponentExceptions with reference numbers using scripts (data is comming from a 3rd party CMDB and we want to sync Exceptions from CMDB to BL). Released commands in namespace ComponentException cannot add a reference number. So I checked unreleased commands and found createComponentException, which accepts a referenceNumber.

       

      However, in this command it also requires a com.bladelogic.om.infra.model.base.header.SBLRoleHeader. To get this objects I use RBACRole findHeaderByName which should returns a com.bladelogic.om.infra.model.base.header.SBLRoleHeader (by documentation) but actually returns a com.bladelogic.om.infra.model.base.header.SBLRoleHeaderImpl@123456 . Strange thing about this command is that it returns different values with every call:

      blcli_execute RBACRole findHeaderByName BLAdmins
      com.bladelogic.om.infra.model.base.header.SBLRoleHeaderImpl@b524aa

      blcli_execute RBACRole findHeaderByName BLAdmins
      com.bladelogic.om.infra.model.base.header.SBLRoleHeaderImpl@789d63

      blcli_execute RBACRole findHeaderByName BLAdmins
      com.bladelogic.om.infra.model.base.header.SBLRoleHeaderImpl@1ec41c0

       

      When I use this for the createComponentException command, then it results in this error:

      Command execution failed. com.bladelogic.om.infra.cli.factory.CommandNotFoundException: ComponentException,createComponentException Method found but with mismatching arguments. Error was : Input 'com.bladelogic.om.infra.model.base.header.SBLRoleHeaderImpl@f1b25e' cannot be converted to expected type : interface com.bladelogic.om.infra.model.base.header.SBLRoleHeader

       

      Does anybody know how to deal with com.bladelogic.om.infra.model.base.header.SBLRoleHeader in this context? Or does anybody know a different way to create ComponentExceptions with referenceNumber in a script?

       

      Regards

      Magnus

        • 1. Re: Create ComponentException with referenceNumber by script
          Jim Wilson

          Moving to Server Automation Scripting space

          • 2. Re: Create ComponentException with referenceNumber by script
            Bill Robinson

            if you generate the unreleased docs and look at the createComponentExceptionWithOneRule command you see the sequence of commands that get run:

             

            RBACRole.findHeaderByName     $Role$    roleHeader

            RBACUser.findHeaderByName     $User$    userHeader

            Template.findComplianceRule     $templateGroupName$ $templateName$ $ruleName$    complianceRule

            ComplianceRule.createMutableComplianceRule     NAMED_OBJECT=complianceRule    complianceRuleBean

            ComponentException.createComponentExceptionBean     no input    componentExceptionBeanObject

            ComponentExceptionBean.setName     $Name$    -

            ComponentExceptionBean.setDescription     $Description$    -

            ComponentExceptionBean.setRole     NAMED_OBJECT=roleHeader    -

            ComponentExceptionBean.setUser     NAMED_OBJECT=userHeader    -

            ComponentExceptionBean.setComment     $Comment$    -

            ComponentExceptionBean.addComplianceRule     NAMED_OBJECT=complianceRuleBean    -

            ComponentException.createComponentException     NAMED_OBJECT=componentExceptionBeanObject    componentExceptionObject

            Component.findByDBKey     $componentKey$    -

            Component.addComponentException     NAMED_OBJECT=componentExceptionObject    -

            Component.update     no input    -

            Component.getDBKey     no input    -

            so probably in there you need to add a ComponentExceptionBean setReferenceNumber.

             

            and do like this:

            blcli_execute Component getComponentKeyByTemplateKeyAndServerId "${templateKey}" ${deviceId} 0

            blcli_storeenv componentKey

            blcli_execute RBACRole findHeaderByName ${rbacRole}

            blcli_execute Utility storeTargetObject roleHeader

            blcli_execute RBACUser findHeaderByName ${rbacUser}

            blcli_execute Utility storeTargetObject userHeader

            blcli_execute Template findComplianceRule "${templateGroupName}" "${templateName}" "${ruleName}"

            blcli_execute Utility setTargetObject

            blcli_execute Utility storeTargetObject complianceRule

            blcli_execute ComplianceRule createMutableComplianceRule NAMED_OBJECT=complianceRule

            blcli_execute Utility storeTargetObject complianceRuleBean

            blcli_execute ComponentException createComponentExceptionBean

            blcli_execute Utility storeTargetObject componentExceptionBeanObject

            blcli_execute ComponentExceptionBean setName ${exName}

            blcli_execute ComponentExceptionBean setDescription  ${exDesc}

            blcli_execute ComponentExceptionBean setRole NAMED_OBJECT=roleHeader

            blcli_execute ComponentExceptionBean setUser NAMED_OBJECT=userHeader

            blcli_execute ComponentExceptionBean setComment "${exComment}"

            blcli_execute ComponentExceptionBean setReferenceNumber "${exRefNum}"

            blcli_execute ComponentExceptionBean addComplianceRule NAMED_OBJECT=complianceRuleBean

            blcli_execute ComponentException createComponentException NAMED_OBJECT=componentExceptionBeanObject

            blcli_execute Utility storeTargetObject componentExceptionObject

            blcli_execute Component findByDBKey ${componentKey}

            blcli_execute Component addComponentException NAMED_OBJECT=componentExceptionObject

            blcli_execute Component update

            blcli_execute Component getDBKey

             

            however, there seems to be a problem w/ the 'Template findComplianceRule' command - it's not returning the correct output and it appears that the 'ComponentException.createComponentExceptionWithOneRule' is also broken because of this.

             

            can you open up a support ticket for this and let me know the number - we can get a defect created, fix the underlying problem and go from there ?

             

            unfortunately I don't see any other way to get the compliance rule object.

            1 of 1 people found this helpful
            • 3. Re: Create ComponentException with referenceNumber by script
              Magnus Ruschpler

              Hi Bill,

               

              see PM for ticket number. Hopefully the command gets fixed.

               

              Thanks a lot

              Magnus

              • 4. Re: Create ComponentException with referenceNumber by script
                Bill Robinson

                so it would probably help if i read our own docs...  the 'rule name' needs to be fully qualified - eg 'group/rulename' not just 'rulename'. so can you try the blcli snippet above ?

                1 of 1 people found this helpful
                • 5. Re: Re: Create ComponentException with referenceNumber by script
                  Magnus Ruschpler

                  Thanks for the hints, Bill. It's working now and I can also set an expireDate for the exception:

                   

                  templGroup="/Compliance"

                  templName="Security Checks"

                  rule="rule group/rule name"

                  rbacUser=BLAdmin

                  rbacRole=BLAdmins

                  exRefNum="1234567890"

                  exComment="Exception as per ticket $exRefNum"

                  exName="Some exception name"

                  exDesc="Some exception description"

                  exDate="2013-12-31 23:59:59"

                  serverName="someserver.domain"

                   

                  blcli_execute Utility stringToDate "${exDate}"

                  blcli_execute Utility setTargetObject

                  blcli_execute Utility storeTargetObject objDateNow

                  blcli_execute Template getDBKeyByGroupAndName "$group" "$template"

                  blcli_storeenv templateKey

                  blcli_execute Server getServerIdByName "$serverName"

                  blcli_storeenv serverId

                  blcli_execute Component getComponentKeyByTemplateKeyAndServerId "${templateKey}" ${serverId} 0

                  blcli_storeenv componentKey

                  blcli_execute RBACRole findHeaderByName "${rbacRole}"

                  blcli_execute Utility storeTargetObject roleHeader

                  blcli_execute RBACUser findHeaderByName "${rbacUser}"

                  blcli_execute Utility storeTargetObject userHeader

                  blcli_execute Template findComplianceRule "${group}" "${template}" "${rule}"

                  blcli_execute Utility setTargetObject

                  blcli_execute Utility storeTargetObject complianceRule

                  blcli_execute ComplianceRule createMutableComplianceRule NAMED_OBJECT=complianceRule

                  blcli_execute Utility storeTargetObject complianceRuleBean

                  blcli_execute ComponentException createComponentExceptionBean

                  blcli_execute Utility storeTargetObject componentExceptionBeanObject

                  blcli_execute ComponentExceptionBean setName "${exName}"

                  blcli_execute ComponentExceptionBean setDescription  "${exDesc}"

                  blcli_execute ComponentExceptionBean setRole NAMED_OBJECT=roleHeader

                  blcli_execute ComponentExceptionBean setUser NAMED_OBJECT=userHeader

                  blcli_execute ComponentExceptionBean setComment "${exComment}"

                  blcli_execute ComponentExceptionBean setExpirationDate NAMED_OBJECT=objDateNow

                  blcli_execute ComponentExceptionBean setReferenceNumber "${exRefNum}"

                  blcli_execute ComponentExceptionBean addComplianceRule NAMED_OBJECT=complianceRuleBean

                  blcli_execute ComponentException createComponentException NAMED_OBJECT=componentExceptionBeanObject

                  blcli_execute Utility storeTargetObject componentExceptionObject

                  blcli_execute Component findByDBKey "${componentKey}"

                  blcli_execute Component addComponentException NAMED_OBJECT=componentExceptionObject

                  blcli_execute Component update

                  blcli_execute Component getDBKey