Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Summary

Introduction

  • Users might be interested to automatically create reports about planning and execution of job scheduling.
  • Such reports Reports can be created by use of individual JS7 cmdlets, see the following use cases:
  • Each report is added as an individual worksheet to an Excel Use cases include to customize the ordering and format of reporting data. This includes use of output formats such as .csv, .xml, .json, .xlsx and individual formats. As Excel® is a frequent output format the use cases introduce a solution to create .xlsx files with Windows and with a number of Unix platforms. Reports can be added to individual worksheets of an Excel® report file.
  • This use case article explains how to automate the creation of reports and how to send reports by mail.

Download

  • Download the sample of a job chain for Windowsworkflowdaily_report.zipjdDailyReport.workflow.json
  • For use with

    Linux

    Unix environments you can use the

    same job chain and order, but replace the jobs with the respective Linux flavor that you find with the above mentioned use case articles.
  • Unzip the archive to the JobScheduler Master's ./config/live folder
  • The extracted files are available from a sub-directory ./config/live/daily_report

Building Blocks

  • sample workflow, however, you have to replace the first line of each job to make use of a Unix shebang.

    Code Block
    languagebash
    titleShebang for PowerShell Job with Unix
    #!/usr/bin/env pwsh

    Explanation:

    • Use of a shebang allows to invoke the pwsh PowerShell executable. 

Example

The sample workflow jdDailyReport is used that

  • serializes execution of the above jobs,
  • stores reporting output of each job to the same Excel® file each with a separate worksheet.

Image Added


Explanation:

  • The reporting For starters the jobs to be used are explained with individual the respective articles, see Summary Introdution.
  • Next a job chain daily_report is created that serializes The workflow jdDailyReport serializes execution of the above jobs.
    • Keep in mind that you will might not need all reports as they provide redundant data, e.g. for example the Task History Report partially includes similar reporting data as the Job Stream Order History Report.
    • The main purpose of the reports is to allow different perspectives on historic data, therefore make your choice which report you will need.
    • The job scripts are added three parameters, report_date_fromreport_date_to and report_file_path, that are provided by the order for the job chain, see below.workflow makes use of three variables, that are provided with a default value that can be modified by any order:
      • report_file: The path to the Excel® file that holds the reports. Each report is stored to a separate worksheet. The path is determined from the Agent's working directory.
      • report_past_period: This period is applied to reports that consider the past, for example the Task History Report.
      • report_future_period: This period is applied to reports that consider the future, for example the Daily Plan Report.
  • A final send-mail job is added that forwards the report_file by mailThen a send_report job is added.
  • Finally an order is created to parameterize and to schedule execution of the job chainworkflow.

Job

...

Code Block
languagexml
titleJob Chain: daily_report
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="UTF-8" ?>
<job_chain title="Daily Report">
  <job_chain_node job="report_daily_plan" next_state="report_order_history" error_state="error" on_error="suspend" state="report_daily_plan"/>
  <job_chain_node job="report_order_history" next_state="report_task_history" error_state="error" on_error="suspend" state="report_order_history"/>
  <job_chain_node job="report_task_history" next_state="report_jobstream_history" error_state="error" on_error="suspend" state="report_task_history"/>
  <job_chain_node job="report_jobstream_history" next_state="send_report" error_state="error" on_error="suspend" state="report_jobstream_history"/>
  <job_chain_node job="send_report" next_state="success" error_state="error" state="send_report"/>
  <job_chain_node state="success"/>
  <job_chain_node state="error"/>
</job_chain>

Explanations:

  • There is no specific sequence in which the reporting jobs have to be executed. Each job writes results to an individual worksheet of the Excel report file.
  • For the final job send_report no error handling is configured. Should this job fail to send an e-mail then the e-mail file is written to the ./mail folder and will later on be picked up by the /sos/sendMail/sendMail job chain that will retry to send unsuccessful mail.

Job: send_report

Code Block
languagexml
titleJob: send_report
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="UTF-8" ?>
<job title="Send report by mail" order="yes" stop_on_error="false">
  <params>
    <param name="subject" value="JobScheduler Daily Report"/>
    <param name="content_type" value="text/html"/>
    <param name="body" value="<html><body><div><p>Hi,<br><br>please find attached report generated by JobScheduler for Order History, Task History, and Daily Plan.<br><br>Have a great day<br>JobScheduler Team</div></p></body></body></html>"/>
    <param name="attachment" value="\${REPORT_FILE_PATH}"/>
  </params>
  <environment/>
  <script language="java" java_class="sos.scheduler.managed.JobSchedulerManagedMailJob"/>
  <monitor name="configuration_monitor" ordering="0">
    <script language="java" java_class="com.sos.jitl.jobchainnodeparameter.monitor.JobchainNodeSubstituteMonitor"/>
  </monitor>
  <run_time/>
</job>

Explanations:

: send-mail

The send-mail job makes use of the following arguments:

Image Added


Explanation:

  • The send-mail job is based on the JS7 - JITL MailJob template.
  • This job is assigned a Job Resource with the name eMailDefault, see JS7 - Job Resources.
    • No settings for the SMTP server, port, authentication etc. are used as such settings are used from the Job Resource, see below.
  • This job
  • The send_report job is based on the JobSchedulerManagedMailJob template.
  • The job makes use of a number of parameters that are independent from the content of the report and from recipients of the report:
    • to: is effectively the recipient's mail address.
    • subject: is mapped to the subject of the e- mail.
    • content_type: depends on the content of the body. When using HTML for the e- mail body then the content_type is should be text/html.
    • body: defines determines the mail boy from a few lines of HTML output for the e-mail bodyplain text or HTML code.
    • attachment: consider use of the syntax \${REPORT_FILE_PATH} that indicates that the value of the attachment parameter is the report_file_path parameter. The leading backslash is required to prevent the value to be substituted as an environment variable. The report_file_path parameter is added by the order, see below.
    • No settings for the SMTP server, port, authentication etc. are used as such settings default to the configuration of the JobScheduler Master to send mail.

Order: daily_report

Code Block
languagexml
titleOrder: daily_report
linenumberstrue
collapsetrue
<?xml version="1.0" encoding="UTF-8" ?>
<order>
  <params>
    <param name="report_file_path" value="/tmp/jobscheduler_reporting.xlsx"/>
    <param name="report_date_from" value="-1d+TZ"/>
    <param name="report_date_to" value="+1d+TZ"/>
    <param name="to" value="info@sos-berlin.com"/>
  </params>
  <run_time/>
</order>
    • the assigned value that is the variable $report_file declared with the workflow that holds the resulting report file.

The Job Resource eMailDefault can be located in any inventory folder and can be defined like this:

Image Added


Explanation:

  • The screenshot shows the configuration of the eMailDefault Job Resource, see JS7 - Job Resources.
    • Mail parameters are specific for a user's environment.
    • Check the JS7 - JITL MailJob for applicable parameters, such as host, port, use of TLS protocols etc.

Schedule: daily-report



ExplanationExplanations:

  • The order carries the following parameters:
    • report_file_path: the path - including the name - of the Excel report file. This parameter is forwarded to all jobs in the job chain that therefore will write to the same Excel report file.
    • report_date_frompast period: a relative date specification for the begin of the reporting period is used. The above value -1d+TZ translates to a date range starting 1 day ago at midnight in the timezone that is specified by the reporting jobs with the -Timezone parameter for the respective reporting cmdlet.
    • report_datefuture_toperiod: a relative date specification for the end of the reporting period is used. The above value +1d+TZ translates to a date range one day after the current date at midnight in the timezone that is specified by the reporting jobs with the -Timezone parameter for the respective reporting cmdlet.
    • to: the recipient of the e-mail. Multiple recipients are separated by comma ",".
  • The above order can be added a run-time to specify automated execution, e.g. on a daily basis or more/less frequently.
  • Additional orders can be created with different parameter sets for date range an recipients that  use the same job chain.

...