The Utility.exportPatch* and related commands only pull out the patch analysis results.  That won't help if you want to look at the log messages to troubleshoot an error during the run.  For that you need to get the contents of the job run log.  There's no command to dump that (yet?).  Also it would make sense to only get the log messages for the servers that threw a warning or error, since you probably don't care about the successful ones.


The Patching Job is like a Batch Job - it contains the Analysis Job and possibly the Remediation and Download Jobs.  Since the Analysis Job is doing most of the work that's where the information we need will be stored.  So we start with getting the latest run of a Patching Job, getting the associated Analysis Job Run (there should be only one and we exclude the Download and Remediation), then finding the failed targets for that run and pulling out the log messages for each server and write it off to a file.


You could also

  • Look at a particular Patching Job run, not the latest, knowing the start date or if you just ran it and had the run key.
  • Email off the file(s), collect them, ship them to some other system
  • get the logs for all the servers in the job
  • get the top-level job run logs for the patching job and analysis job runs with the 'LogItem.getLogItemsByJobRun' or 'JobRun.getLogItemsByJobRunId' (second one calls the first actually)




blcli_setjvmoption -Dcom.bladelogic.cli.execute.quietmode.enabled=true
blcli_setoption serviceProfileName defaultProfile
blcli_setoption roleName BLAdmins

patchingJob="/Workspace/Patching Jobs/RedHat Patching Job"
blcli_execute PatchingJob getDBKeyByGroupAndName "${patchingJob%/*}" "${patchingJob##*/}"
blcli_storeenv jobKey
blcli_execute JobRun findLastRunKeyByJobKey ${jobKey}
blcli_storeenv jobRunKey
blcli_execute JobRun jobRunKeyToJobRunId ${jobRunKey}
blcli_storeenv jobRunId
blcli_execute JobRun findPatchingJobChildrenJobsByRunKey ${jobRunId}
blcli_execute JobRun getJobRunId
blcli_execute Utility setTargetObject
blcli_execute Utility listPrint
blcli_storeenv patchChildJobRunIds
patchChildJobRunIds="$(awk 'NF' <<< "${patchChildJobRunIds}")"
while read patchChildJobRunId
        blcli_execute JobRun findById ${patchChildJobRunId}
        blcli_execute JobRun getType
        blcli_storeenv jobRunType
        blcli_execute JobRun getJobKey
        blcli_storeenv analysisKey
        # skip remediation
        if [[ ${jobRunType} -ne 7033 ]] && [[ ${jobRuntype} -ne 7031 ]]
           blcli_execute JobRun getServersStatusByJobRun ${patchChildJobRunId}
           blcli_execute Utility mapPrint
           blcli_storeenv serverStatusMap
           serverStatusMap="$(awk 'NF' <<< "${serverStatusMap}")"
           while read serverStatus
                     serverKey="$(awk '{print $1}' <<< "${serverStatus}")"
                     echo "ServerKey: ${serverKey}"
                     serverResult="$(awk '{print $3}' <<< "${serverStatus}")"
                     # if it is an error get the job run log
                     if [[ ${serverResult} -eq 1 ]] || [[ ${serverResult} -eq 2 ]]
                          blcli_execute Server findByDBKey ${serverKey}
                          blcli_execute Server getName
                          blcli_storeenv serverName
                          blcli_execute Server getServerId
                          blcli_storeenv serverId
                          blcli_execute LogItem getLogItemsByDevice ${analysisKey} ${patchChildJobRunId} ${serverId}
                          blcli_execute Utility listPrint
                          blcli_storeenv jobRunLog
                          echo "${jobRunLog}" > "/tmp/${patchChildJobRunId}-${serverName}"
           done <<< "${serverStatusMap}"
done <<< "${patchChildJobRunIds}"