azurekqlazure-monitoring

Is there a way to get an automated email with the report of an Azure Monitor Log query


Is there a possible way to get any automated way, say any integration of other Azure services are also fine - to get a downloaded report or something throught an email Say my log output looks like this, I want this to run everyday at a certain time and email me the results in a tabular form or something Sample Lof query

I havent got an idea regarding what to do, I can download it as an excel file, but I need some automated way of getting it in my mail as a report or something


Solution

  • You can use Logic apps for automation. Create a logic app with consumption plan.

    You use "Schedule" connector's for "Recurrence" of the action automatically. You can add additional parameters to run at specific time.

    enter image description here

    enter image description here

    From "Azure Monitor Logs" select "Run query and list results".

    enter image description here

    Select "Resource Type". I have selected Application Insights here. you can select as per your requirement where you want to run your KQL Query.

    enter image description here

    Sample log query enter image description here

    enter image description here

    Select ** "Create HTML table"**. Next Action select "Compose".

    enter image description here

    Compose is used for styling the HTML table for sending in the mail

    Compose:

    <style>
    Table {
      font-family: "Times New Roman", Times, serif;
      background-color: #ffffff;
      border-collapse: collapse;
      width: 100%;
    }
    
    Table td, Table th {
      border: 1px solid #ddd;
      padding: 4px 4px;
    }
    
    Table th {
      font-size: 16px;
      font-weight: bold;
      padding-top: 10px;
      padding-bottom: 10px;
      text-align: left;
      background-color: #4fb2f2;
      color: white;
    }
    </style>
    

    Select "Send an Email v2": First Outputs value is from "Compose" and second Output is from "Create HTML table":

    enter image description here

    Result: You will get an email with the table in ascending order on timestamp.

    enter image description here

    enter image description here