Summary
- Reports can be created by use of individual cmdlets, see
- Each report is added as an individual worksheet to an Excel report file.
- This use case explains how to automate creation of reports and how to send reports by mail.
Download
- Download the sample of a job chain for Windows: daily_report.zip
- Unzip the archive to the JobScheduler Master's
./config/live
folder - The extracted files are offered from a sub-directory
./config/live/daily_report
Building Blocks
- For starters the jobs to be used are explained with individual articles, see Summary.
- Next a job chain Daily_Report is created that serializes execution of the above jobs.
- Keep in mind that you will not need all reports as they provide redundant data, e.g. the Task History Report includes similar report data as the Job Stream History Report.
- Purpose of the reports is to allow different perspectives on historic data, therefore make your choice which report you will need.
- Then a
send_mail
job is added. - Finally an order is created to parameterize and to schedule execution of the job chain.
Job Chain: daily_report
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?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> |
...
- There is no specific sequence in which the reporting jobs are executed. Each job writes result to an individual worksheet in 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 for later processing.
Job: send_report
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?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> |
...
- 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:
subject
: is mapped to the subject of the e-mail.content_type
: depends on the content of thebody
. When using HTML for the e-mail body then thecontent_type
istext/html
.body
: defines a few lines of HTML output for the e-mail body.attachment
: consider use of the syntax\${REPORT_FILE_PATH}
that indicates that the value of theattachment
parameter is thereport_file_path
parameter. The leading backslash is required to prevent the value to be substituted as an environment variable. Thereport_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 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
<?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> |
...