5 Replies Latest reply on Sep 25, 2017 3:42 PM by Bill Robinson

    Patch Analysis Results via blcli

    Clinton Baker

      Hi,

       

      I am trying to figure out how to retrieve Patch Analysis Results via blcli without using the blcli Utility commands. Namely, I am trying get a count and a list of missing patches from the results.

      I have managed to put together code to seemingly get the number of missing patches, as well as an array that gets returned from the CLI of what looks like DB keys.

       

      Here is the code I have so far:

       

      #!/bin/nsh

      serverName=${NSH_RUNCMD_HOST}

      blcli_execute PatchingJob getDBKeyByGroupAndName "/Patching/Jobs" "WindowsPatchAnalysis" > NUL && blcli_storeenv analysisTemplate

      echo "[INFO] Running Patch Analysis"

      blcli_execute Job executeAndWaitAgainstServers "${analysisTemplate}" "${serverName}" > NUL && blcli_storeenv patchAnalysisRunKey

      blcli_execute JobRun getJobRunHadErrors ${patchAnalysisRunKey} > NUL && blcli_storeenv targetJobHadErrors

      if [ "${targetJobHadErrors}" = "false" ]; then

      blcli_execute JobRun jobRunKeyToJobRunId ${patchAnalysisRunKey} > NUL && blcli_storeenv targetJobRunId

      blcli_execute JobRun findPatchingJobChildrenJobsByRunKey ${targetJobRunId} > NUL

      blcli_execute JobRun getJobRunId > NUL

      blcli_execute Utility setTargetObject > NUL

      blcli_execute Utility listPrint > NUL && blcli_storeenv analysisJobRunId

      blcli_execute PatchAnalysisResult findJobResultByAnalysisJobRunId ${analysisJobRunId} > NUL

      blcli_execute JobResult getResultId > NUL && blcli_storeenv analysisJobResultId

      blcli_execute PatchAnalysisResult findServersWithMissingPatches ${analysisJobResultId} > NUL

      blcli_execute Utility storeTargetObject serversWithMissingPatches > NUL

      blcli_execute Utility listLength > NUL && blcli_storeenv missingServersListLength

      if [ ${missingServersListLength} -gt 0 ]; then

      for item in {0..$((${missingServersListLength}-1))}; do

      blcli_execute Utility setTargetObject serversWithMissingPatches > NUL

      blcli_execute Utility listItemSelect ${item} > NUL

      blcli_execute Utility setTargetObject > NUL

      blcli_execute SDeviceHeader getName > NUL && blcli_storeenv analysisServerName

      blcli_execute SDeviceHeader getDeviceId > NUL && blcli_storeenv analysisDeviceId

      blcli_execute SDeviceHeader getOsId > NUL && blcli_storeenv analysisOsId

      blcli_execute PatchAnalysisResult getAnalysisResultsByResultsId ${analysisOsId} ${analysisJobResultId} ${analysisDeviceId} > NUL

      blcli_execute Utility storeTargetObject analysisResults > NUL

      blcli_execute Utility setTargetObject > NUL

      blcli_execute Utility listLength > NUL && blcli_storeenv numMissingPatches

      if [ ${numMissingPatches} -gt 0 ]; then

      for mPatch in {0..$((${numMissingPatches}-1))}; do

      blcli_execute Utility setTargetObject analysisResults > NUL

      blcli_execute Utility listItemSelect ${mPatch} > NUL

      blcli_execute Utility setTargetObject > NUL && blcli_storeenv testKey

      ##No command has worked to pull info from the "keys" I've gotten from the array

      done

      fi

      done

      fi

      else

      echo "[ERROR] Patch Analysis Had an Error. Cannot display results"

      fi

       

      A few things to note:

      Each patch analysis has only one target. I just use findServersWithMissingPatches because it seems to be more reliable than other unpublished commands I have tried.

      I have also tried using other commands such as: blcli_execute PatchAnalysisResult getAllMissingPatchIDList but I cannot find any information on some input parameters such as entryType, modelType, pagingSpec, and patchingTool

        • 1. Re: Patch Analysis Results via blcli
          Bill Robinson

          if you put

          blcli_setjvmoption -Dcom.bladelogic.cli.execute.quietmode.enabled=true

          before any other blcli_xxx calls you don't need the redirect to NUL to hide stdout.

           

           

           

          I am trying to figure out how to retrieve Patch Analysis Results via blcli without using the blcli Utility commands. Namely, I am trying get a count and a list of missing patches from the results.

          why don't you want to use the Utility commands ?

           

          for the patch list, do you want the list per device or how?

           

          you can do like:

          blcli_execute PatchAnalysisResult getAllMissingPatchIDList ${patchAnalysisResultId} 7 114
          blcli_execute Utility listPrint
          

          for per server you need to load the server object and convert it into a list like:

          blcli_execute Server findByName ${server}
          blcli_execute Server getServerId
          blcli_execute Utility setTargetObject
          blcli_execute Utility objectToList
          blcli_execute Utility setTargetObject
          blcli_execute Utility storeTargetObject serverList
          blcli_execute PatchAnalysisResult getMissingPatchIDListByDeviceList ${patchAnalysisResultId} 7 114 NAMED_OBJECT=serverList
          blcli_execute Utility setTargetObject
          blcli_execute Utility listPrint
          
          1 of 1 people found this helpful
          • 2. Re: Patch Analysis Results via blcli
            Clinton Baker

            Hi Bill,

             

            Thanks for the help! Those seem to be what I was looking for.

            why don't you want to use the Utility commands ?

            We have a huge amount of automation built into our patching system and, with the way it is put together, everything needs to be handled in thread without having to temporarily save temp files.

             

            Another question:

            How would I go about getting the entryType and modelType ofr other types of Patch Analysis Jobs to retrieve results in a similar fashion? (I.E. SuSE, RedHat, etc)

             

            I recognize 114 as the DepotObject Type for the Windows Patches. Not sure how all that would apply to Non-Windows OS jobs.

            • 3. Re: Patch Analysis Results via blcli
              Bill Robinson

              How would I go about getting the entryType and modelType ofr other types of Patch Analysis Jobs to retrieve results in a similar fashion?

              i believe you will always want entry type 7.  that's the only one i have in my bl_patch_analysis_res_data table.

               

              the modelType ids are listed here:

              Object type IDs - BMC Server Automation 8.9

              for linux it should be RPM_INSTALLABLE (68).  what other oses are you using ?

              • 4. Re: Patch Analysis Results via blcli
                Clinton Baker

                Thanks again, Bill. I believe I got this going now.

                 

                what other oses are you using ?

                Currently, we are only using Windows Patch Catalogs. We will eventually be migrating over to SuSE, Red Hat, and "Other Linux" patch catalogs. And once those are migrated, then AIX and Solaris. So my additional question was just for future reference so I can make the code re-usable and modular.

                • 5. Re: Patch Analysis Results via blcli
                  Bill Robinson

                  Ok.  for solaris it should be like solaris_patch_installable.  Not sure for aix.  i’m pretty sure that the bl_patch_id in bl_patch_analysis_res_data column is also the dept_object_id from depot_object, so if there’s some question about the object type id to use you can also run the analysis and then track down your result in the bl_patch_analysis_res_data table and correlate w/ the depot_object table.  i think that’s what i did when i was messing around in here.

                  1 of 1 people found this helpful