5 Replies Latest reply on Oct 5, 2012 6:50 PM by Bill Robinson

    One job - many targets - getLogItemsByJobRunId



      I have a problem with command getLogItemsByJobRunId from namespace JobRun.


      I wrote such script in jython



      import sys

      import os

      import string as s

      import re

      import bladelogic.cli.CLI as blcli

      jli = blcli.CLI()




      JOB_FOLDER = "/TEST"

      JOB_NAME = "test1"

      # job key

      job_key = jli.run(['NSHScriptJob', 'getDBKeyByGroupAndName', JOB_FOLDER, JOB_NAME]).returnValue

      print job_key

      # run keys

      job_run_keys = jli.run(['JobRun', 'findAllRunKeysByJobKey', job_key]).returnValue

      job_run_keys = s.rstrip(job_run_keys)

      job_run_keys = re.split('\n',job_run_keys)

      for job_run_key in job_run_keys:

                start_time = jli.run(['JobRun', 'getStartTimeByRunKey', job_run_key, 'yyyyMMdd']).returnValue

             print start_time

              # run id

              job_run_id = jli.run(['JobRun', 'jobRunKeyToJobRunId', job_run_key]).returnValue

              print job_run_id

              # run log items

              log_items = jli.run(['JobRun', 'getLogItemsByJobRunId', job_key, job_run_id]).returnValue

               print log_items




      And in case of job is running on one target - script get full output - means "print log_items" prints corrent messages.



      (Type: Info Date: Thu Sep 27 16:06:03 CEST 2012 Message: Exit Code 0)


      And in case of job is running on many targets command getLogItemsByJobRunId doesn't get any output.

      Shuld I use another structure?, some kind of array? or sth?

        • 1. Re: One job - many targets - getLogItemsByJobRunId



          The issue seems to be with JobRun getLogItemsByJobRunId $JobKey $RunId command. I am able to reproduce, and here is what happening. As the time goes by, you may modify and save your job numerous times. When you change the Job the Job Key of it changes. The findAllRunKeysByJobKey command works fine, and it give you all job run keys, however getLogItemsByJobRunId does not correctly work if the passed JobKey does not match one of the historic runs, which were made prior to the Job change.


          Basically, add few targets to your job, run it, then run your script, and you will see that job run logging. If you add another target, then you have modified the job (causing the job key to change). Now when you run your script, it picks up the new job key, and the old job run logs can no longer be retrieved using this new job key - only the run logs after the last job change can be retrieved. As soon as you modify the job again, all previous job runs can no longer be retrieved.


          I filed defect QM001768475 for this.


          As a workaround or alternative solution review the Utility name space for blcli commands to export logs for various job runs.

          • 2. Re: One job - many targets - getLogItemsByJobRunId
            Bill Robinson

            robert, can you explain the purpose of the script - you are trying to dump the log items from the script for what purpose ?


            and how do you know you want the latest run of the job ?  what is executing your jython ?

            • 3. Re: One job - many targets - getLogItemsByJobRunId

              I have a jobs (a lof of) which I execute many times ( > 100 runs). And I just try to get one raport (csv) with

              execution date; status; logs items. Why? mayby I found some kind of erros/wornings.

              Despite the job exit with exit code 0, something might have gone wrong.

              GUI clicking is time consuming task.

              • 4. Re: One job - many targets - getLogItemsByJobRunId

                Robert, have you looked into Utility namespace?

                getLogItemsByJobRunId has a bug and unless you would be able to supply the correct historic that matches the runId, you will only get the results after the last job modification (aka: last jobKey)

                • 5. Re: One job - many targets - getLogItemsByJobRunId
                  Bill Robinson

                  if you want the job run logs you need to know the job run id for the run you want to get logs for.  how do you plan to get that?  or are you looking to get all job runs ?  that does not seem very efficient so you should consider using some sort of filter to only pull the last X runs.  you could still use most of your script logic above, but as lazar suggests, i'd consider using something from the Utility namespace.  you may still run into a problem if you are trying to export the log for a job run that is in progress when you are running the export.

                  1 of 1 people found this helpful