|
| 1 | +--- |
| 2 | +title: Use Azure Monitor Logs with Azure Logic Apps and Power Automate |
| 3 | +description: Learn how you can use Azure Logic Apps and Power Automate to quickly automate repeatable processes by using the Azure Monitor connector. |
| 4 | +ms.service: azure-monitor |
| 5 | +ms.subservice: logs |
| 6 | +ms.topic: conceptual |
| 7 | +author: bwren |
| 8 | +ms.author: bwren |
| 9 | +ms.date: 03/13/2020 |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +# Azure Monitor Logs connector for Logic Apps and Flow |
| 14 | +[Azure Logic Apps](/azure/logic-apps/) and [Power Automate](https://ms.flow.microsoft.com) allow you to create automated workflows using hundreds of actions for a variety of services. The Azure Monitor Logs connector allows you to build workflows that retrieve data from a Log Analytics workspace or an Application Insights application in Azure Monitor. This article describes the actions included with the connector and provides a walkthrough to build a workflow using this data. |
| 15 | + |
| 16 | +For example, you can create a logic app to use Azure Monitor log data in an email notification from Office 365, create a bug in Azure DevOps, or post a Slack message. You can trigger a workflow by a simple schedule or from some action in a connected service such as when a mail or a tweet is received. |
| 17 | + |
| 18 | +## Actions |
| 19 | +The following table describes the actions included with the Azure Monitor Logs connector. Both allow you to run a log query against a Log Analytics workspace or Application Insights application. The difference is in the way the data is returned. |
| 20 | + |
| 21 | +> [!NOTE] |
| 22 | +> The Azure Monitor Logs connector replaces the [Azure Log Analytics connector](https://docs.microsoft.com/connectors/azureloganalytics/) and the [Azure Application Insights connector](https://docs.microsoft.com/connectors/applicationinsights/). This connector provides the same functionality as the others and is the preferred method for running a query against a Log Analytics workspace or an Application Insights application. |
| 23 | +
|
| 24 | + |
| 25 | +| Action | Description | |
| 26 | +|:---|:---| |
| 27 | +| [Run query and and list results](https://docs.microsoft.com/connectors/azuremonitorlogs/#run-query-and-list-results) | Returns each row as its own object. Use this action when you want to work with each row separately in the rest of the workflow. The action is typically followed by a [For each activity](../../logic-apps/logic-apps-control-flow-loops.md#foreach-loop). | |
| 28 | +| [Run query and and visualize results](https://docs.microsoft.com/connectors/azuremonitorlogs/#run-query-and-visualize-results) | Returns all rows in the result set as a single formatted object. Use this action when you want to use the result set together in the rest of the workflow, such as sending the results in a mail. | |
| 29 | + |
| 30 | +## Walkthroughs |
| 31 | +The following tutorials illustrate the use of the Azure Monitor connectors in Azure Logic Apps. You can perform these same example with Power Automate, the only difference being how to you create the initial workflow and run it when complete. Configuration of the workflow and actions is the same between both. See [Create a flow from a template in Power Automate](https://docs.microsoft.com/power-automate/get-started-logic-template) to get started. |
| 32 | + |
| 33 | + |
| 34 | +### Create a Logic App |
| 35 | + |
| 36 | +Go to **Logic Apps** in the Azure portal and click **Add**. Select a **Subscription**, **Resource group**, and **Region** to store the new logic app and then give it a unique name. You can turn on **Log Analytics** setting to collect information about runtime data and events as described in [Set up Azure Monitor logs and collect diagnostics data for Azure Logic Apps](../../logic-apps/monitor-logic-apps-log-analytics.md). This setting isn't required for using the Azure Monitor Logs connector. |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | + |
| 41 | +Click **Review + create** and then **Create**. When the deployment is complete, click **Go to resource** to open the **Logic Apps Designer**. |
| 42 | + |
| 43 | +### Create a trigger for the logic app |
| 44 | +Under **Start with a common trigger**, select **Recurrence**. This creates a logic app that automatically runs at a regular interval. In the **Frequency** box of the action, select **Day** and in the **Interval** box, enter **1** to run the workflow once per day. |
| 45 | + |
| 46 | + |
| 47 | + |
| 48 | +## Walkthrough: Mail visualized results |
| 49 | +The following tutorial shows you how to create a logic app that sends the results of an Azure Monitor log query by email. |
| 50 | + |
| 51 | +### Add Azure Monitor Logs action |
| 52 | +Click **+ New step** to add an action that runs after the recurrence action. Under **Choose an action**, type **azure monitor** and then select **Azure Monitor Logs**. |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | +Click **Azure Log Analytics – Run query and visualize results**. |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | + |
| 61 | +### Add Azure Monitor Logs action |
| 62 | + |
| 63 | +Select the **Subscription** and **Resource Group** for your Log Analytics workspace. Select *Log Analytics Workspace* for the **Resource Type** and then select the workspace's name under **Resource Name**. |
| 64 | + |
| 65 | +Add the following log query to the **Query** window. |
| 66 | + |
| 67 | +```Kusto |
| 68 | +Event |
| 69 | +| where EventLevelName == "Error" |
| 70 | +| where TimeGenerated > ago(1day) |
| 71 | +| summarize TotalErrors=count() by Computer |
| 72 | +| sort by Computer asc |
| 73 | +``` |
| 74 | + |
| 75 | +Select *Set in query* for the **Time Range** and **HTML Table** for the **Chart Type**. |
| 76 | + |
| 77 | + |
| 78 | + |
| 79 | +The mail will be sent by the account associated with the current connection. You can specify another account by clicking on **Change connection**. |
| 80 | + |
| 81 | +### Add email action |
| 82 | + |
| 83 | +Click **+ New step**, and then click **+ Add an action**. Under **Choose an action**, type **outlook** and then select **Office 365 Outlook**. |
| 84 | + |
| 85 | + |
| 86 | + |
| 87 | +Select **Send an email (V2)**. |
| 88 | + |
| 89 | + |
| 90 | + |
| 91 | +Click anywhere in the **Body** box to open a **Dynamic content** window opens with values from the previous actions in the logic app. Select **See more** and then **Body** which is the results of the query in the Log Analytics action. |
| 92 | + |
| 93 | + |
| 94 | + |
| 95 | +Specify the email address of a recipient in the **To** window and a subject for the email in **Subject**. |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | + |
| 100 | +### Save and test your logic app |
| 101 | +Click **Save** and then **Run** to perform a test run of the logic app. |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +When the logic app completes, check the mail of the recipient that you specified. You should have received a mail with a body similar to the following: |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | +## Next steps |
| 113 | + |
| 114 | +- Learn more about [log queries in Azure Monitor](../log-query/log-query-overview.md). |
| 115 | +- Learn more about [Logic Apps](/azure/logic-apps/) |
| 116 | +- Learn more about [Microsoft Flow](https://ms.flow.microsoft.com). |
| 117 | + |
0 commit comments