Search code examples
azurepowershellazure-cliazure-log-analytics

Creating Azure Monitor Log Search Alert Rules via Powershell


I'm trying to create some azure monitor rules for the output of log searches, doing this through the web UI is simple enough but I want to automate this through the CLI.

Looking through the documentation there doesn't seem to be a way that I can see to do this, but AFAIK everything is possible through the CLI?

I've tried creating the alert rule manually and then looking at the output of Get-AzureRmAlertRule but this shows no results for the log search alert.

Has anyone managed to do this via the CLI?


Solution

  • Hello and welcome to Stack Overflow! :)

    Custom log search alerts are of type microsoft.insights/scheduledqueryrules. And so you may use Get-AzScheduledQueryRule to get all the Scheduled Query resources.

    Although creating a Log Search rule could get a bit tricky as it involves multiple PS cmdlets, it is still possible with New-AzScheduledQueryRule.

    Please give it a try and let me know if you run into issues. I can work up a sample script in that case.

    Hope this helps!