4 Replies Latest reply on Mar 25, 2015 1:14 PM by Bill Robinson

    Snapshot getSnapshotKey blcli not finding Template

    Mike Reider

      BSA 8.5.1

       

      Trying to create an Audit job to compare a live server vs Master snapshot.

       

      1.  created an 'implicit'/invisible Tempalte called $TARGET-GOLD with all my files and parts to scan against and generate a 'Gold' snapshot image

       

      blcli_execute Template createEmptyTemplate $TARGET-GOLD $CT_FOLDER_KEY false

       

      2.  created Snapshot job called $TARGET GOLD SNAP to run against this $TARGET-GOLD template,

       

      blcli_execute Template getDBKeyByGroupAndName "${CONSOLE_PATH}/${TARGET}" "$TARGET-GOLD"

      blcli_storeenv TEMPL_GOLD_KEY

      blcli_execute SnapshotJob createAssetBasedSnapshotJob "$TARGET GOLD SNAP" ${JOB_GROUP_ID} ${TEMPL_GOLD_KEY} ${TARGET}

       

       

      3.  execute the snapshot Job

       

      ##  execute Snapshot job to generate Snap

      blcli_execute SnapshotJob getDBKeyByGroupAndName "${CONSOLE_PATH}/${TARGET}" "$TARGET GOLD SNAP"

      blcli_storeenv JOB_KEY

      blcli_execute SnapshotJob executeJobGetJobResultKey ${JOB_KEY}

       

      Everything works up to this point, now trying to create an Audit job to run against this generated Snapshot image

       

      4.

      ## create Audit job vs Snapshot

      ## get Run ID of the SnapshotJob

      blcli_execute SnapshotJob getDBKeyByGroupAndName "${CONSOLE_PATH}/${TARGET}" "$TARGET GOLD SNAP"

      blcli_storeenv JOB_KEY

      echo "job key is $JOB_KEY" returns: job key is DBKey:SJobModelKeyImpl:2125-1-2361892

       

      blcli_execute JobRun findAllRunKeysByJobKey ${JOB_KEY}

      blcli_storeenv RUN_KEY

      echo "run key is $RUN_KEY"   returns: DBKey:SJobRunModelKeyImpl:2847-2361893

       

      blcli_execute JobRun jobRunKeyToJobRunId ${RUN_KEY}

      blcli_storeenv RUN_ID

      echo "run id $RUN_IDreturns: run id 2847

       

      ## Making sure my $TARGET-GOLD template exists and returns a DB key

      blcli_execute Template getDBKeyByGroupAndName "${CONSOLE_PATH}/${TARGET}" $TARGET-GOLD

      blcli_storeenv TEMPL_GOLD_KEY

      echo "templ key $TEMPL_GOLD_KEY"   returns: templ key DBKey:STemplateModelKeyImpl:295-5-2361862

       

      5.

      now trying to get the SnapshotKey so I can create the Audit job with this key, but its saying my $TARGET-GOLD template doesnt exist, even though right above its returning its DB key ^^

       

      blcli_execute Snapshot getSnapshotKeyByJobRunId ${RUN_ID} $TARGET-GOLD ${TARGET}

      blcli_storeenv SNAP_KEY

      echo "snap key $SNAP_KEY"  returns:

       

      snap key

      Command execution failed. com.bladelogic.om.infra.mfw.util.NotFoundException: Th

      e list does not contain : ulvzndat21-GOLD

      Cannot store a failed command result

       

      Am I missing something or is this a bug? I tried both

       

      getSnapshotKeyByJobKeyAndRunId and

      getSnapshotKeyByJobRunId

      same results, it cant find the Template name even though the template clearly exists.

        • 1. Re: Snapshot getSnapshotKey blcli not finding Template
          Mike Reider

          it looks like

          getSnapshotKeyByJobRunId

          doesnt work with implicit templates. Template has to be visible in the console for it to pick it up,  I tried with an existing explicit/visible template and its returning the key. Not sure if this is by design or a bug.

          • 2. Re: Snapshot getSnapshotKey blcli not finding Template
            Bill Robinson

            so under the covers this is what is running:

             

            Command    Input    Return value stored name

            Snapshot.findAllByJobRun    $runId$    snapshotList

            Snapshot.getName    no input    snapshotNameList

            Utility.setTargetObject    snapshotNameList    -

            Utility.stringListGetIndexes    contains ($targetServerName$)    indexList

            Utility.setTargetObject    snapshotList    -

            Utility.listSelect    NAMED_OBJECT=indexList    snapshotList

            Utility.setTargetObject    snapshotList    -

            Snapshot.getName    no input    snapshotNameList

            Utility.setTargetObject    snapshotNameList    -

            Utility.stringListGetIndexes    contains $templateName$    indexList

            Utility.setTargetObject    indexList    -

            Utility.listItemSelect    0    snapIndex

            Utility.setTargetObject    snapshotList    -

            Utility.listItemSelect    NAMED_OBJECT=snapIndex    snapshot

             

            it looks like it's failing in what is in bold.  why are you using the invisible templates ?  why not just use an asset based snapshot job ?

            • 3. Re: Snapshot getSnapshotKey blcli not finding Template
              Mike Reider

              Im trying to automate Config Management, where the customer wants to constantly monitor their hosts for changes, and steamroll any out-of-band change with Gold snapshot rollback.

               

              The customer also wants to see what was changed specifically, so if the Snapshot captures /etc/sysctl.conf for example, they want to know what got modified inside the file (key, value). The only way to do this is through a Comp.Template and add that file as a Config.File part with a "auto" grammar to parse the file.

               

              We cant use an Audit vs. Snapshot for "diff checking"  because that only tells you if there was a checksum change, it doesnt parse the files and tell you what was added, deleted, etc.

               

              so what im trying to do is this,

               

              1. create a 'Difference' template - normal template with files added as Config.Objects (/etc/hosts, /etc/sysconfig/network, etc) with "auto" grammar

              2. create a 'Gold' template - implicit template - Config files are added as 'files', not Config.Objects

              3. create Snapshot Job vs implicit Gold template, execute it and generate a Golden snapshot

              4. create Discovery job vs "Difference" template to create components for each config.file

              5. run Audit vs. Components ("Difference" template) to get the exact changes that customer wants to see. (Export results to csv file)

              6. run Audit vs. Golden snashot (generated in step 3 above) to detect any changes. If checksum is different, steamroll or 'remediate' that file back to golden state.

               

              so Im using implicit because this cmd only works w implicit templates (step #3 above)

              createAssetBasedSnapshotJob

               

              SnapshotJob - createAssetBasedSnapshotJob - BMC Server Automation Command Line Interface 8.5 - BMC Documentation

               

              The templateKey argument provides a DBKey identifying the template that describes the assets on which the snapshot is based. This template must be an anonymous template. To create an anonymous template, use any template creation command from the Template namespace and supply a value of false to the bExplicit parameter of that command. For example,

              • 4. Re: Snapshot getSnapshotKey blcli not finding Template
                Bill Robinson

                yes - if you need to have multiple parts in the snapshot it looks like you would need a template.  you can of course snapshot a cfo in an asset based snapshot though - you don't need a template for that.  you can then use the 'createComponentBasedSnapshot' job after you run discovery for the template.

                 

                what i don't understand is why you are doing an audit job here and why you are making a job/template for each config file.

                 

                why not:

                - create a template w/ all the parts you want to check

                - discover the template on your servers

                - run the snapshot job w/ that list of targets

                - run the snapshot again against the same target list.  now you have 'change tracking' information.

                - create the 'rollback' package w/ the BlPackage.createPackageForChangeTracking when there is a difference and deploy that.

                 

                ?

                 

                this 'gold' - are you looking at one single server that is the 'gold master' or you just want to compare each server to a previous state of itself ?