Hi folks! My name is Felipe Binotto, Cloud Solution Architect, based in Australia.
This is part 2 of Monitoring Storage Replication, if you missed part 1 you can find it HERE.
In part 1, we configured an Automation Runbook to collect replication data for Storage Accounts and stored it in a custom table in a Log Analytics workspace.
In this post, I will demonstrate how you can leverage that data stored in Log Analytics to generate Azure Alerts which trigger a Logic App and send a customized email to the owner of the Storage Account which is defined as a tag value of the Storage Account.
Before we begin, please ensure that you have the following prerequisites in place:
Log Analytics workspace
The process of notifying the owner of the storage account can be broken down in a couple of steps, which we will go through in the following order:
Create and configure an Azure Alert.
Configure the Logic App.
From the Azure Portal, navigate to your Log Analytics workspace where you have the custom table with the Storage Account replication data, click on Alerts, click on Create and select Alert Rule.
From the Select a signal page, select Custom log search.
Next paste the following query in the Search query box.
| where TimeGenerated >= ago(23h)
| where todatetime(Storage_LastSyncTime_s) < ago(24h)
This means we want all the events that were generated in the last 23 hours and from those events only storage accounts that have not synchronized in the last day. Adapt it to your requirements.
For the aggregation granularity select 1 day.
For dimensions, I am selecting Storage_Name_s, Storage_LastSyncTime_s and Owner_s, but you could select other dimensions if you are collecting them. Also note that in Dimension values you may not have anything if you do not have any Storage Accounts which match the query parameters.
Finally, on Threshold value select 1 which means if the query returns more than 1 result the alert should be triggered.
Now, on Actions, select Create action group.
On the Basics tab, provide the basic details and skip to the Actions tab. On the Actions tab, as the Action type choose Logic App, give it a name, and select the Logic App you have created previously.
Create the Action group.
Note: you must have a “When a HTTP request is received” configured in your Logic App. Otherwise, you will not be able to select it in the previous step.
Once that is done. The only remaining step on the alert rule is to configure the Details tab and click to create it.
Now it is time to configure the Logic App. First step is to Initialize some variable which will be used during the workflow. If you have added extra dimensions in the previous steps, make sure you initialize variables for those too.
All variables should be of type string and no value is required.
In this next step, you may have to zoom in a bit because there is a lot going on. Here are the steps:
Create a Foreach and select allOf as the output from previous steps.
Create a nested Foreach and select dimensions.
Create a Switch inside the second Foreach and select name.
Create one case for each of the variables, in the picture below is an example of creating the first case where it equals to Owner_s.
Inside the case, create a Set variable, with name Owner and Value value.
Repeat the previous step for each variable you want to set based on your dimensions.
The last two steps are to compose the email and send it out.
For the compose, I recommend you use an example from Sandro Pereira, which you can get it from HERE.
Copy and paste the content in your Compose. Then you can adapt the HTML (Hyper Text Markup Language) code and include the variables you want like shown below.
The last step is to create a Send an email (V2) and connect with your M365 account. Once that is done, select Outputs for the Body of the email and the Owner variable for the To field.
In conclusion, monitoring the replication of your Azure Storage Account is crucial to ensure that your data is always available and secure. By configuring alerts and setting up a Logic App to send email notifications, you can stay on top of any potential issues and act before they cause significant problems.
Through this article and part 1, we have discussed step-by-step instructions on how to set up monitoring and alerting for Azure Storage Account replication using Azure Monitor and Logic Apps. This approach provides a reliable and straightforward way to receive notifications whenever replication issues arise, giving you the chance to investigate and fix the problem promptly.
With this process in place, you can have peace of mind knowing that your data is continuously replicated and available, even in the event of an outage or other issues. We hope this article has been helpful in guiding you through the process of monitoring Azure Storage Account replication and implementing an effective alerting system to keep you informed of any potential problems.
Thanks for reading!
The sample scripts are not supported under any Microsoft standard support program or service. The sample scripts are provided AS IS without warranty of any kind. Microsoft further disclaims all implied warranties including, without limitation, any implied warranties of merchantability or of fitness for a particular purpose. The entire risk arising out of the use or performance of the sample scripts and documentation remains with you. In no event shall Microsoft, its authors, or anyone else involved in the creation, production, or delivery of the scripts be liable for any damages whatsoever (including, without limitation, damages for loss of business profits, business interruption, loss of business information, or other pecuniary loss) arising out of the use of or inability to use the sample scripts or documentation, even if Microsoft has been advised of the possibility of such damages.