Deploying Alerts and Action Groups

Preview

During Public Preview you can use the Team plan for free, and get an early-adopter discount at GA. Sign in

Deploying Alerts and Action Groups

This guide shows you how to set up an Action Group with a webhook and an Activity Log alert against Locally, then trigger the alert and watch it arrive at the webhook. After that we'll add a metric alert and a log search alert on an Application Insights component and fire those too, then look at Prometheus rule groups, alert processing rules and smart detector alert rules. As with the other guides we're going to use the Azure CLI, but the same resources can be provisioned with HashiCorp Terraform, Pulumi or Bicep too.

Before you start

Plugins required

Locally v2026.10+ automatically installs these Resource Provider plugins when their Resource Providers are registered, but you can also install them via:

$ locally plugin install --name Microsoft.AlertsManagement
$ locally plugin install --name Microsoft.Insights
$ locally plugin install --name Microsoft.Monitor
$ locally plugin install --name Microsoft.OperationalInsights

1. Start Locally

Firstly, we need to launch Locally which we can do from a terminal by running:

$ locally build

Once Locally has started, the Locally Dashboard will open automatically:

Screenshot of the Locally Dashboard

2. Create a Resource Group

Next we can create the Resource Group to hold the Action Group and the alert:

$ locally run az group create -n sample-alerts -l berlin

There's two things to note here:

  1. The Azure CLI supports Automatic Configuration, meaning that it can automatically be configured to work against Locally just by prefixing commands with locally run.
  2. Locally intentionally uses a different set of locations to Azure as a safety precaution, so that you can be confident you're deploying against Locally rather than regular Azure. You can also configure Locally to use the Azure locations too, but you'll want to be extra sure that you're prefixing commands with locally run when you do.

3. Start a webhook receiver

An alert needs somewhere to go. We'll run a small echo server that logs every request it receives, listening on port 8099:

$ podman run -d --rm --name sample-alerts-webhook -p 8099:8080 docker.io/mendhak/http-https-echo

Locally sends webhook notifications from your machine, so a URL like http://localhost:8099 is reachable from it - there's no need to expose anything to the internet.

4. Create the Action Group

The Action Group says who gets told when an alert fires. This one has a webhook pointing at our receiver, using the common alert schema, and an email address for the on-call team:

$ locally run az monitor action-group create -g sample-alerts -n docs1-ops --short-name ops --action webhook ops-webhook http://localhost:8099/alerts usecommonalertschema --action email oncall [email protected]
{
  "note": "some fields skipped for brevity",

  "emailReceivers": [
    {
      "emailAddress": "[email protected]",
      "name": "oncall"
    }
  ],
  "name": "docs1-ops",
  "type": "Microsoft.Insights/actionGroups",
  "webhookReceivers": [
    {
      "name": "ops-webhook",
      "serviceUri": "http://localhost:8099/alerts",
      "useCommonAlertSchema": true
    }
  ]
}

Note

Webhook, Azure Function and Logic App receivers get a real HTTP request. Email, SMS, voice and push receivers are accepted and recorded, but nothing is sent - so you can keep your real Action Group definitions without anyone's phone going off.

5. Create the Activity Log alert

Now for the alert itself. This one fires whenever the sample-alerts Resource Group is changed, and notifies the Action Group we just created:

$ locally run az monitor activity-log alert create -g sample-alerts -n docs1-group-changes --scope "/subscriptions/$(locally run az account show --query id -o tsv)/resourceGroups/sample-alerts" --condition category=Administrative and operationName=Microsoft.Resources/subscriptions/resourceGroups/write --action-group docs1-ops --description "Someone changed the sample-alerts resource group"
{
  "note": "some fields skipped for brevity",

  "condition": {
    "allOf": [
      {
        "equals": "Administrative",
        "field": "category"
      },
      {
        "equals": "Microsoft.Resources/subscriptions/resourceGroups/write",
        "field": "operationName"
      }
    ]
  },
  "enabled": true,
  "name": "docs1-group-changes",
  "scopes": [
    "/subscriptions/307d8f52-9719-460e-9f85-aa408e28ee55/resourceGroups/sample-alerts"
  ],
  "type": "Microsoft.Insights/activityLogAlerts"
}

The scopes are prefixes: any activity log event for a resource ID under the Resource Group is checked against the condition.

6. Trigger the alert

Adding a tag to the Resource Group is a write, which is exactly what the alert is watching for:

$ locally run az group update -n sample-alerts --tags owner=platform-team

Locally checks alert rules about once a minute, so give it a minute and then look at what the webhook received:

$ podman logs sample-alerts-webhook

The echo server logs the whole request. The body is the alert in the common alert schema, with the activity log event that triggered it as the alertContext:

{
  "note": "some fields skipped for brevity",

  "schemaId": "azureMonitorCommonAlertSchema",
  "data": {
    "essentials": {
      "alertRule": "docs1-group-changes",
      "monitorCondition": "Fired",
      "severity": "Sev4",
      "signalType": "Activity Log",
      "configurationItems": [
        "sample-alerts"
      ]
    },
    "alertContext": {
      "operationName": "Microsoft.Resources/subscriptions/resourceGroups/write",
      "status": "Succeeded"
    }
  }
}

The alert is also recorded as an Alerts Management alert, which we can list for the Resource Group:

$ locally run az rest --method get --url "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alerts?api-version=2025-05-25-preview&targetResourceGroup=sample-alerts" --query "value[].properties.essentials.{Target:targetResourceName, Signal:signalType, Severity:severity, Condition:monitorCondition, State:alertState}" -o table
Target         Signal        Severity    Condition    State
-------------  ------------  ----------  -----------  -------
sample-alerts  Activity Log  Sev4        Fired        New

Activity Log alerts always fire at Sev4 and never resolve on their own - each matching event fires once, the same as in Azure.

We can see the Activity Log alert in the Locally Dashboard too:

Screenshot of the Activity Log alert in the Locally Dashboard

7. Create an app to watch

The next two alerts watch an application, so we need a Log Analytics Workspace and an Application Insights component that sends its telemetry there:

$ locally run az monitor log-analytics workspace create -g sample-alerts -n docs1-logs -l berlin $ locally run az monitor app-insights component create -g sample-alerts -a docs1-app -l berlin --application-type web --workspace docs1-logs

8. Create a metric alert

A metric alert checks one of a resource's metrics against a threshold. This one fires when the app has more than two failed requests in five minutes, and notifies the same Action Group:

$ locally run az monitor metrics alert create -g sample-alerts -n docs1-failed-requests --scopes $(locally run az monitor app-insights component show -g sample-alerts -a docs1-app --query id -o tsv) --condition "count requests/failed > 2" --window-size 5m --evaluation-frequency 1m --severity 2 --action docs1-ops --description "More than two failed requests in five minutes" --query "{name:name, severity:severity, windowSize:windowSize, evaluationFrequency:evaluationFrequency, condition:criteria.allOf[0].{metric:metricName, aggregation:timeAggregation, operator:operator, threshold:threshold}}"
{
  "condition": {
    "aggregation": "Count",
    "metric": "requests/failed",
    "operator": "GreaterThan",
    "threshold": 2.0
  },
  "evaluationFrequency": "PT1M",
  "name": "docs1-failed-requests",
  "severity": 2,
  "windowSize": "PT5M"
}

Locally evaluates metric alerts against the metrics it records, such as an Application Insights component's request counts, a Key Vault's API hits or a Service Bus queue's message count. A metric Locally has no data for is reported as an evaluation error rather than treated as healthy.

9. Create a log search alert

A log search alert runs a KQL query against a Log Analytics Workspace on a schedule, which lets it pick out things a metric can't - here, server errors from one endpoint. The command lives in the scheduled-query extension:

$ locally run az extension add --name scheduled-query $ locally run az monitor scheduled-query create -g sample-alerts -n docs1-checkout-errors --scopes $(locally run az monitor log-analytics workspace show -g sample-alerts -n docs1-logs --query id -o tsv) --condition "count 'Errors' > 0" --condition-query Errors="AppRequests | where Name == 'GET /checkout' and ResultCode startswith '5'" --window-size 5m --evaluation-frequency 1m --severity 1 --action-groups $(locally run az monitor action-group show -g sample-alerts -n docs1-ops --query id -o tsv) --description "The checkout endpoint is returning errors" --query "{name:name, severity:severity, windowSize:windowSize, evaluationFrequency:evaluationFrequency, query:criteria.allOf[0].query, operator:criteria.allOf[0].operator, threshold:criteria.allOf[0].threshold}"
{
  "evaluationFrequency": "0:01:00",
  "name": "docs1-checkout-errors",
  "operator": "GreaterThan",
  "query": "AppRequests | where Name == 'GET /checkout' and ResultCode startswith '5'",
  "severity": 1,
  "threshold": 0.0,
  "windowSize": "0:05:00"
}

Locally runs the query against the workspace's data each time the rule is evaluated, and fires when the result crosses the threshold.

10. Trigger the metric and log search alerts

Both alerts are waiting for failed requests, so let's send some. First we need the component's instrumentation key:

$ export IKEY=$(locally run az monitor app-insights component show -g sample-alerts -a docs1-app --query instrumentationKey -o tsv)

Then we can send three failed requests for GET /checkout to the ingestion endpoint, the same way an Application Insights SDK would:

$ for i in 1 2 3; do curl -sk https://ingest.appinsights.locally:5668/v2/track -H "Content-Type: application/json" -d "{\"name\":\"Microsoft.ApplicationInsights.Request\",\"time\":\"$(date -u +%Y-%m-%dT%H:%M:%SZ)\",\"iKey\":\"${IKEY}\",\"data\":{\"baseType\":\"RequestData\",\"baseData\":{\"ver\":2,\"id\":\"checkout-$i\",\"name\":\"GET /checkout\",\"duration\":\"00:00:00.250\",\"responseCode\":\"500\",\"success\":false}}}"; done

Give it a minute, then list the alerts again:

$ locally run az rest --method get --url "/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/alerts?api-version=2025-05-25-preview&targetResourceGroup=sample-alerts" --query "value[].properties.essentials.{Target:targetResourceName, Signal:signalType, Severity:severity, Condition:monitorCondition, State:alertState}" -o table
Target         Signal        Severity    Condition    State
-------------  ------------  ----------  -----------  -------
docs1-app      Metric        Sev2        Fired        New
docs1-logs     Log           Sev1        Fired        New
sample-alerts  Activity Log  Sev4        Fired        New

Both new alerts went to the webhook too, so podman logs sample-alerts-webhook now shows a Metric and a Log alert alongside the first one. Unlike the Activity Log alert, the metric alert resolves on its own a few minutes after the failures drop out of its five minute window, and the webhook gets a Resolved notification.

11. Other alert rules

Locally accepts the other alert rule types too, so your existing definitions deploy unchanged, but it can't evaluate all of them:

  • Prometheus rule groups are stored but never evaluated, since Locally has no Prometheus metrics store to run the PromQL against.
  • Alert processing rules are stored but not applied, so they don't add, remove or suppress any notifications.
  • Smart detector alert rules never fire on their own, because Azure doesn't publish how its detectors work. You can fire one from the Locally Dashboard instead.

The Prometheus and alert processing rule commands are in the alertsmanagement extension, and the commands below use the Action Group's ID a few times, so let's grab both:

$ locally run az extension add --name alertsmanagement $ export ACTION_GROUP_ID=$(locally run az monitor action-group show -g sample-alerts -n docs1-ops --query id -o tsv)

Prometheus rule group

A Prometheus rule group runs against an Azure Monitor Workspace, so we'll create one first:

$ locally run az monitor account create -g sample-alerts -n docs1-amw -l berlin $ locally run az alerts-management prometheus-rule-group create -g sample-alerts -n docs1-prometheus --scopes "[$(locally run az monitor account show -g sample-alerts -n docs1-amw --query id -o tsv)]" --interval PT1M --rules "[{alert:TargetDown,expression:'up == 0',severity:2,for:PT5M,actions:[{actionGroupId:${ACTION_GROUP_ID}}]}]" --query "{name:name, interval:interval, rules:rules[].{alert:alert, expression:expression, severity:severity, for:for}}"
{
  "interval": "PT1M",
  "name": "docs1-prometheus",
  "rules": [
    {
      "alert": "TargetDown",
      "expression": "up == 0",
      "for": "PT5M",
      "severity": 2
    }
  ]
}

Alert processing rule

An alert processing rule changes what happens to alerts after they fire. This one sends every Sev0 and Sev1 alert in the Resource Group to the Action Group:

$ locally run az monitor alert-processing-rule create -g sample-alerts -n docs1-page-on-sev1 --rule-type AddActionGroups --action-groups ${ACTION_GROUP_ID} --scopes "/subscriptions/$(locally run az account show --query id -o tsv)/resourceGroups/sample-alerts" --filter-severity Equals Sev0 Sev1 --query "{name:name, conditions:properties.conditions, actionType:properties.actions[0].actionType}"
{
  "actionType": "AddActionGroups",
  "conditions": [
    {
      "field": "Severity",
      "operator": "Equals",
      "values": [
        "Sev0",
        "Sev1"
      ]
    }
  ],
  "name": "docs1-page-on-sev1"
}

Smart detector alert rule

Creating the Application Insights component also created a Failure Anomalies - docs1-app smart detector alert rule, the same way Azure does. Let's point it at our Action Group:

$ locally run az rest --method patch --url "/subscriptions/{subscriptionId}/resourceGroups/sample-alerts/providers/Microsoft.AlertsManagement/smartDetectorAlertRules/Failure Anomalies - docs1-app?api-version=2021-04-01" --body "{\"properties\":{\"actionGroups\":{\"groupIds\":[\"${ACTION_GROUP_ID}\"]}}}" --query "{name:name, detector:properties.detector.id, severity:properties.severity, actionGroups:properties.actionGroups.groupIds}"
{
  "actionGroups": [
    "/subscriptions/0f766306-391f-4f66-b9ee-927fb2db629c/resourceGroups/sample-alerts/providers/Microsoft.Insights/actionGroups/docs1-ops"
  ],
  "detector": "FailureAnomaliesDetector",
  "name": "Failure Anomalies - docs1-app",
  "severity": "Sev3"
}

To see how your code handles a Failure Anomalies alert, open the Alerts tab under Monitoring in the Locally Dashboard and press Fire alert next to the rule. The alert is sent to the webhook like any other, and Resolve sends the matching Resolved notification. The same tab lists every alert rule and the alerts they've fired:

Screenshot of the Alerts tab under Monitoring in the Locally Dashboard

12. Tidy up

Finally, we can tidy up. To remove the Resource Group and everything within it, including the smart detector alert rule:

$ locally run az group delete -n sample-alerts --yes

And stop the webhook receiver, which also removes the container:

$ podman stop sample-alerts-webhook

Doing this with other tooling

Whilst this guide used the Azure CLI, Action Groups and alerts work the same way through any of the tooling that Locally supports - Microsoft.Insights/actionGroups, Microsoft.Insights/activityLogAlerts, Microsoft.Insights/metricAlerts, Microsoft.Insights/scheduledQueryRules and the Microsoft.AlertsManagement rule types in HashiCorp Terraform or OpenTofu, Pulumi, Bicep or an ARM Template all provision against Locally in the same way, with only the location changed.

Point the webhook at your own service instead of the echo server and you can test how it handles a real alert, without waiting for something to go wrong in Azure.

Next steps

To keep the Activity Log rather than alert on it, a Diagnostic Setting can send it to a Log Analytics Workspace - the Log Analytics Emulator shows where it lands.

Should you encounter any issues, please take a look at the troubleshooting section, reach out in our Discord or open an issue and we'll take a look.

Preview

During Public Preview you can use the Team plan for free, and get an early-adopter discount at GA. Sign in

A local cloud for you and your AI agents.

Your Azure infrastructure, running on your machine. Deploy in seconds, break things freely, and ship to Azure when you're ready.