Get Job Log through Python Deadline API Python

Unable to figure out how to grab the information in the logs ^. Trying to avoid navigating to the /log files, matching dates, then searching the 100MB log for the specific job log.

If you’re using the internal scripting API, something like this should get you rolling. It’s a script I used in the past to figure out how much render time had been spent leading up to an Arnold license issue. It pulls down every job and then grabs every report from each job.

But it should be enough to get you rolling, let me know if you have any questions!

def __main__(*args):
    job_list = RepositoryUtils.GetJobs(True)

    print("job_id|job_name|instance_name|task_seconds|instance_type|report_type|report_date|watermark")

    for job in job_list:       
        job_report_collection = RepositoryUtils.GetJobReports(job.JobId)


        #all_reports = job_report.GetAllReports()
        
        log_reports = job_report_collection.GetLogReports()

        for report in log_reports:#all_reports:
            str_log = get_str_log(report)
            instance_type = get_instance_name_from_report(str_log)
            license_issue = arnold_license_issue(str_log)

            print(str(job.JobId) + "|" + str(job.JobName) + "|" + str(report.ReportSlaveName) + "|" + str(report.ReportTaskSecondsElapsed) + "|" + str(instance_type) + "|" + str(report.ReportTypeOf) + "|" + str(report.ReportDateTimeOf) + "|" + str(license_issue))

        # reqeue_reports = job_report.GetRequeueReports()
        # error_reports = job_report.GetErrorReports()

        # for requeue in reqeue_reports:
        #     instance_type = get_instance_name_from_report(requeue)
        #     print(str(requeue.ReportSlaveName) + "," + str(requeue.ReportTaskSecondsElapsed) + "," + str(instance_type) + "," + str(requeue.ReportTypeOf))
        #     #print("Worker Name: " + str(requeue.ReportSlaveName) + " Task Time: " + str(requeue.ReportTaskTimeElapsed) + " Instance Type: " + str(instance_type))
        
        # for error in error_reports:
        #     instance_type = get_instance_name_from_report(error)
        #     print(str(error.ReportSlaveName) + "," + str(error.ReportTaskSecondsElapsed) + "," + str(instance_type) + "," + str(error.ReportTypeOf))
        #     #print("Worker Name: " + str(error.ReportSlaveName) + " Task Time: " + str(error.ReportTaskTimeElapsed) + " Instance Type: " + str(instance_type))

def get_str_log(report):
    log = RepositoryUtils.GetJobReportLog(report)
    str_log = unicodedata.normalize('NFKD', log).encode('ascii','ignore')#this will quash any special characters, but we don't care
    
    return str_log

def arnold_license_issue(str_log):
    regex = r".*watermark.*"
    
    matches = re.finditer(regex, str_log, re.MULTILINE)
    
    for matchNum, match in enumerate(matches, start=1):
        return True

    return False

def get_instance_name_from_report(str_log):
    regex = r"^Instance Type: (.*)$"

    matches = re.finditer(regex, str_log, re.MULTILINE)
    
    for matchNum, match in enumerate(matches, start=1):
        return (match.group(1)).strip()
1 Like

Amazing! Thank you. I somehow glossed over this function and it’s exactly what I’m looking for. :slight_smile:

1 Like