Trigger Azure logic app on resource creation - azure

I'm working on an Azure Logic app that should trigger when a new resource is created.
However, if I trigger the app based on a webhook using monitor alerts or an event subscription, I run into the problem of each creation event will have 2 identical events with all the output being identical which means I can't filter it out and therefore triggers the logic app twice.
If there a different route around to just get the app to trigger once?

I believe the multiple events are because the event type for both create or update is the same as documented.
One way to workaround this would be to keep track of resourceIds touched by your Logic App, OR add a tag to your resource which signals that it has been touched. This way you wouldn't need an extra store for this metadata.

Related

React to all Function App Slot Swaps across Subscription/Resource Group

I want to react to my Function App Events, specifically when a slot is swapped. I have hundreds of Function Apps which I want to Monitor but I want all the events to be handled by a single Event Handler (probably a Logic App).
I have multiple Logic Apps and Function Apps stored in a Subscription. I want to be able to use Event Grid to monitor them and react to changes. For the Logic Apps, I wanted to know every time a Logic App is saved which was fairly easy to do - I created an Event Grid which looks at Resources across a subscription and is triggered when any Resources are written successfully. And then I added some filtering so that it only reacts to Logic Apps (Microsoft.Logic/workflows) which works very well.
Where I am struggling is with the Function Apps. I want to monitor all the Function Apps and look out for any slots being swapped. I can do this by creating an event grid for each Function App but this seems wasteful to do for every singe one, whereas for the Logic App I can just have a single Event Grid which monitors everything.
What's the best way to go about this?
You can use Azure Event Grid to monitor the events from multiple Function Apps and have a single Event handler as a Logic App to process the events.
Created event grid as shown in below image by taking Endpoint type as Azure function and Endpoint as EventGridTrigger1.
After that In Event Grid Enable Subject Filtering in Filters and then take Microsoft. Web/sites/*/slots/swapped in Subject begins with field to allow the Event Grid to subscribe to all slot swapped events across all your Function Apps in the subscription.
In function app we are taking Azure Event Grid Trigger as function.
Then Create a logic App in the same subscription ,resource group and same region as function App and EventGrid taken .
When a resource event occurs Event grid trigger and Filter array action taken.
In the When a resource event occurs trigger configuration, select the Resource Type as Microsoft.EventGrid.Topics and Resource Name as you created EventGridName.
Then add an "Filter array" action to filter the events to only include events from Function Apps.
AFAIK currently the wildcard for all azure function apps is not supported so you can create as mentioned in above process or else raise a Microsoft support for this.

Automatically link newly created logic apps to an existing alert rule

I have created an Alert action group which will simply call a "error" logic app when the conditions are met. And I have set up an event grid which will be called whenever an logic app gets created for the first time.
Now the challenge is that I want to somehow automatically link this newly created logic app to the action group.
I have searched for way to do this but had no luck, anyone knows if this is possible?
One way of updating an action group would be by using the management API, see the docs.
However, you might want to think about this a bit differently.
How are you going to deploy everything?
Assuming you're not going to be doing this manually, you will be using ARM-/Bicep-files. So, you could include the configuration of an action group in these deployment files.
Meaning, when you initially deploy the Logic App, it will immediately be added to an action group, allowing it to trigger the required alerts. Next to that, it also allows you to create the event subscriptions in your Azure Event Grid topic.
This way you avoid missing the first alert because the action group wasn't updated before the first run of the Logic App.
The template to create an action group can be found here.
The template to create an event grid subscription can be found here.

Azure automatically edit resource after deployment

I am trying to create an automation with an event grid on a subscription so that whenever a resource is deployed it will send the event to a webhook that belongs to a runbook that adds a tag to the resource.
(resource deployed -> event grid -> runbooks webhook -> add tag)
However, when I add the tag it triggers a similar event which triggers the event grid again and a cycle begins. The event grid only allow write/action success type of event and there is no way of filtering only the creation events from the other event created by editing the resource.
I want to know if there's a workaround or maybe an alternative to using automation (I don't want to use a modify policy because I want to change other fields in the future not just change tags)
Thanks
You can use Azure Policy for that although you say you don't want. With a custom Azure Policy, you can modify the different properties of a resource.
Another advantage is that Azure Policy is free whereas you will pay for Automation Account.
On the other hand, for your current situation, I guess the Event Grid is triggered even when the resource is modified. So you need to modify that in order to avoid the loop.

Trigger Azure Action Group from a Logic App

I have a Logic App running every minute that checks the time that data was last received in a table. If it has been enough time since the data was updated I want to receive an alert. I really like the Action Groups used by the Alerts in Azure. They are clean and have lots of options like email, SMS, and Phone. How can I trigger an Action Group from my Logic App?
I know I can recreate the email, SMS, and Phone connections in the Logic App, but then it's harder to maintain. I'm already using the same Action Group for other Alerts. It would be easier to maintain if I could reuse this Action Group.
There is ton online about triggering a Logic App from an Action Group. This is NOT what I'm trying to do. I want the reverse. I want to trigger an Action Group from a Logic App.
How can I trigger an Action Group from my Logic App?
Currently as per the documentation We can trigger a particular logic app using the action group but there is no way to trigger a particular action group using logic app.
It would be easier to maintain if I could reuse this Action Group.
Yes, you can use same action group in multiple alert mechanisms.
Would suggest you to raise a feature request using this azure support link.
You should be able to send data to a custom log in Log Analytics from your Logic App using Azure Log Analytics Data Collector.
Then you can use a Log Analytics query to evaluate resources logs every set frequency, and fire an alert based on the results. Rules can trigger one or more actions using Action Groups. - see Create, view, and manage log alerts using Azure Monitor.

Is it possible to receive an event when a new resource is created

I would like to run some automation to take some actions whenever a new resource is created in One of my subscriptions in Azure. Is this possible?
You can use Azure Event grid for this, a solution that is built for exactly this purpose. Taken from https://learn.microsoft.com/en-us/azure/event-grid/overview
Azure Event Grid allows you to easily build applications with event-based architectures. You select the Azure resource you would like to subscribe to, and give the event handler or WebHook endpoint to send the event to. Event Grid has built-in support for events coming from Azure services, like storage blobs and resource groups.
You basically create a subscription to a certain event (such as specific resources being created) that can then be picked up by a webhook, or processed by Azure Automation or Azure Functions

Resources