Log Analytics queries to CSV emailed using Azure Logic Apps can be used for automated reporting – using 4 steps! In this blog post, I will demo how this is done
What are Logic Apps?
A little resource with a big outcome, Logic Apps assist you with automated workflow; scheduling, automating, coposing a task or even rewiting a task.
Logic Apps run in a “trigger”-type fashion, it requires an event to happen or when something is specifically met, to begin the flow of the specific app.
What is Log Analytics?
A Log Query resource that collects data within Azure from numerous points, resources and also Azure Monitor. Data is then stored and Kusto query language is used to retrieve this data in various formats and displays.
Will consist of a Logic App, running the Kusto query on a schedule once a day. Once query is ran, the queried data will be converted to .csv and emailed.
Previous Blog Post
In a previous blog post; I detailed a similar approach but instead it had emailed the queried data with .html attachment. See here for further details on that blog post
This blog post also shows how to create a Logic App, review this blog post to see the creation steps.
Consists of 4 stages within my logic app.
Recurrence:- The trigger essential, to run at a specific hour or day etc
Run query and list results:- Run Log Analytics query
Create CSV Table:- Creates CSV table of the queried data from the Log Analytics Query
Send an email:- Sends email with attached .csv file
Logic App Break Down
Recurrence Task/Trigger Step
In this example, I have set it to run once per day
Run query and list results Step
Sign-in with user credentials or select Service Principal
Subscription: Select Subscription of Log Analytics Workspace
Resource Group: Log Analytics Resource Group
Workspaces Name: Log Analytics Workspace
Query: Enter Log Analytics query you want to report on
Time Range: Set in query
Log Analytics query showing data in Log Analytics:-
Create CSV Table Step
Value is taken from the above step
Send an email (V2) Step
Body:- test email text
Subject:- Subject for email
To:- Sender Address
Attachment Contents:- Contents output from Create CSV Table Step
Attachment Name: Name of csv
Select “see more” in Create CSV table tab to get the output for above
Lets run the Logic App to test
Reviewing the Create CSV Table Step , shows the output of Log Analytics query in .csv format
Sample data from test.csv file