2 Replies Latest reply on Jun 12, 2018 3:49 AM by Roy Ong

    get jobdbkey from deploy jobs created from Patch Remediation Jobs

    Roy Ong

      I'm trying to use BLCLI to automate creating a patch deploy from for a target server from a previous patch analysis run. The PatchRemediationJob executeJobAndWait function returns the DBKey of the JobRun as a result which isn't what im looking for. Can someone advise how do i get the jobDBKey of the Deploy Jobs that was created from the PatchRemediationJob executeJobAndWait function?  Or is my blcli commands wrong? Thanks

        • 1. Re: get jobdbkey from deploy jobs created from Patch Remediation Jobs
          Bill Robinson

          you will need to process the log output of the remediation job to find the generated deploy jobs and from there you can get the dbkey of each.  i've been working on a blog post for this but haven't had time to finish it... anyway you'll run something like this:

           

                  blcli_execute JobRun findPatchingJobChildrenJobsByRunKey ${PATCHING_JOB_RUN_ID}
                  blcli_execute JobRun getJobRunId
                  blcli_execute Utility setTargetObject
                  blcli_execute Utility listPrint
                  blcli_storeenv PATCH_ANALYSIS_JOB_RUN_IDS
                  for JOB_RUN_ID in ${PATCH_ANALYSIS_JOB_RUN_IDS}
                          do
                          blcli_execute JobRun findById ${JOB_RUN_ID}
                          blcli_execute JobRun getType
                          blcli_storeenv JOB_RUN_TYPE_ID
                          if [[ ${JOB_RUN_TYPE_ID} = 7033 ]]
                                  then
                                  break
                          fi
                  done
          
          
                  blcli_execute JobRun findById ${JOB_RUN_ID}
                  blcli_execute JobRun getJobKey
                  blcli_storeenv REMEDIATION_JOB_KEY
                  blcli_execute LogItem getLogItemsByJobRun ${REMEDIATION_JOB_KEY} ${JOB_RUN_ID}
                  blcli_execute Utility storeTargetObject logItems
                  blcli_execute Utility listLength
                  blcli_storeenv LIST_LENGTH
                  if [[ ${LIST_LENGTH} -gt 0 ]]
                          then
                          for i in {0..$((${LIST_LENGTH}-1))}
                                  do
                                  blcli_execute Utility setTargetObject logItems
                                  blcli_execute Utility listItemSelect ${i}
                                  blcli_execute Utility setTargetObject
                                  blcli_execute JobLogItem getMessage
                                  blcli_storeenv MESSAGE
                                  if ( grep -q "Created deploy job" <<< "${MESSAGE}" )
                                          then
                                          DEPLOY_JOB_NAME="$(grep "Created deploy job" <<< "${MESSAGE}" | cut -f2- -d: | sed "s/^ Jobs//")"
                                          echo "DEPLOY_JOB_NAME: ${DEPLOY_JOB_NAME}"
                                          blcli_execute DeployJob getDBKeyByGroupAndName "${DEPLOY_JOB_NAME%/*}" "${DEPLOY_JOB_NAME##*/}"
                                          blcli_storeenv DEPLOY_JOB_KEY
                                          DEPLOY_JOB_KEYS+=${DEPLOY_JOB_KEY}
                                  fi
                          done
                  else
                          check_errs $? "Could not find job logs for ${REMEDIATION_JOB_KEY}..."
                  fi
          

           

          w/ the patching job run key you can get the child analysis and remediation job run keys.  from the remediation run key you can get the log entries and look for the line(s) where the deploy job(s) are generated.  line 36 is what scrapes the remediation job log - that string is different depending on if you are using the 'single job mode' added in 8.8 or you generate multiple deploy jobs (<=8.7 default), so look at one of your remediation job runs.  there may be some unreleased commands that can directly pull the dbkeys for the deploy jobs instead of scraping the log text but i haven't had time to dig around for those.  this will get you an array (DEPLOY_JOB_KEYS) with the ....deploy job keys... that were generated.