Questions? Feedback? powered by Olark live chat software
Hopp over navigasjon

Azure Automation: Create Reports of Your Automation Activity

Posted on 2 mars, 2015

Program Manager, Azure Automation
For DevOps and IT professionals, Azure Automation allows you to create and launch runbooks to automate repetitive, complex, and time-consuming tasks on your critical resources.  Due to the importance of the automated tasks, it's important for you and your team to be up-to-date on how your runbooks are performing.  You'll want to know for the previous day or week, which runbook ran, what was the status of the jobs, are there issues that need investigation, and have any runbooks changed?  One way to keep up-to-date is to use Azure Automation itself to create and send reports.  In this post, I'll introduce a runbook - New-AutomationReport - that puts information about the runbooks and jobs in your Automation accounts into reports that can be emailed to you on a recurring schedule.

Key Data

Runbooks and jobs are key objects in Azure Automation that you want to keep track of.  Runbooks are the PowerShell Workflows that contain your logic for the automation of important processes, and jobs are the individual runs of your runbooks.  Thus, it is no surprise that any report on the system will have a focus on runbooks and their jobs.

The Report

General Info

At the top of the report you will see information that orients you to the scope of the report – the time period, subscription, and Automation account. The time period always ends at the time when the report runbook kicked off; the start time will be one or more whole days prior to that, depending on your configuration. Note that each report is for a single Automation account.  If you have more than one account, then to get reports on all of the accounts you will want to import and configure the New-AutomationReport runbook in each account. General information

Runbooks with Jobs

One of the first pieces of information you'll want to know is – Which runbooks have been running? You want to quickly scan a list of the runbooks that had jobs during the time period and see how each job turned out. Because the runbooks contain the logic for your business processes, the name of each runbook (along with your knowledge of the inner workings of each runbook) will inform you about which processes were run and what changes were made in Azure or third-party systems.  If one or more jobs have a potentially non-happy status – “failed”, “suspended”, “stopped”, “completed with errors”, or “queued” – then you will see these highlighted as something to investigate. This information is presented in a table with a row for each runbook that has had one or more jobs in the report time period.  For each runbook you can see the count of jobs that had a certain status. This table will give you a quick overview of the runbook job health, and allow you quickly to see if there are any jobs that require further investigation. Runbooks With Jobs

Jobs

After the quick overview of runbooks with jobs during the reporting period, the report gives you a section that focuses on jobs specifically, with data useful for drilling down into problem jobs that may have occurred.  In this section of the report you will first see a summary of the total count of jobs that ran and the count of jobs for each job status.  If there are any actionable jobs – jobs with status of “Completed with Errors”, “Failed”, “Queued”, “Stopped”, or “Suspended” – then the report will give details of those jobs in subsections by status.  You can use the runbook name and job id within the Azure Automation portal to find the job and drill into the job details to troubleshoot the issue.
Note: The job statuses shown are those present in the database at the time the report was run. Thus, a queued job may have started and completed by the time you look at the report, and a running job may have reached a final state. Both of these would appear in the next report along with their final state.
Jobs

Modified Runbooks

The final section of the report will let you know about any runbooks that have been modified or whose status has changed in the time period of the report.  This includes any “new” runbooks that have been created, any runbooks “published” during the time period, and any “in edit” runbooks that are being modified. If you have a team that works on runbooks in Azure Automation, this can help you keep tabs on which runbooks are being worked on and any runbooks recently published.   ModifiedRunbooks  

Importing and Configuring the New-AutomationReport Runbook

You can import the New-AutomationReport runbook from the Automation gallery into your Automation account.  Just click +New in the Azure portal to create a new Automation Runbook.  Click to import it From Gallery, and then select New-AutomationReport in the wizard. Once you have the runbook imported, you need to set up a few assets (which can also be useful in many of your other runbooks):
  1. A credential asset that contains an Azure AD credential with administrative access to the Azure subscription. For more information see this post.
  2. A variable asset which contains the Azure Subscription name.
  3. A variable asset which contains the Automation Account name.
  4. A credential asset that contains the credential for the SMTP service.
  Assets that you need to create   Also, to send the report by email, you will need to edit the runbook and configure some SMTP mail properties.  You can learn more online about Send-MailMessage and its parameters.   Configuration for SMTP email  

Running the Automation Report on a Schedule

You will probably want to set up a recurring schedule that will kick off this runbook automatically.  For example, if you want to check up on your automation daily, then create a daily schedule and link the runbook to it.  In the wizard where you link the runbook to a schedule you will need to set the three parameters that the runbook takes for input – NumberOfDaysForReport is an integer that indicates the period of days for the report; OutputHtml is a Boolean that indicates whether to format the report as HTML or as plain text; and SentReportByEmail is a Boolean that indicates if the report should be sent via SMTP or just stored in the job output.  The screenshots below illustrate this. No schedules

1

Select the schedule

2

Set input parameters for the runbook

3

Schedule is now associated with the runbook

4

Summary

Using the New-AutomationReport runbook in each of your Azure Automation accounts will allow you to automatically receive reports on the health of your runbooks and jobs.  By linking the runbook to a schedule and opting to receive the reports by email, you can set up hands-free reporting and receive key information in your inbox daily. Note that this runbook is a work in progress, and we have ideas for more reports to add in the future; so check the gallery occasionally for updates, and leave comments with your own report ideas. Just getting started with Azure Automation? Learn about the service here, and follow Azure Automation on Twitter.