Search code examples
azure-log-analyticsazure-monitoringazure-monitorazure-log-analytics-workspace

How to programatically create functions for Log Analytics Workspace


The Functions in Azure Monitor log queries doc explains how to create functions in Log Analytics workspace manually, but doesn't explain how to do it automatically. What is the recommended way of doing it?

I tried to use .create-or-alter function from Kusto.Explorer but it didn't work (I have correct connection, as I can execute existing functions and read data). The documentation section on function supportability doesn't mention support for it, so no surprise here.

I did discover find or update saved searches API method that seems promising. But calling API directly is nowhere near as convenient as executing .create-or-alter function from my Kusto.Explorer.

Is there an easier way to create functions programmatically? If there is an SDK support for it, could I get links to the relevant methods?


Solution

  • Per this comment on GitHub issues I opened, titled 'The "Functions in Azure Monitor log queries" doc doesn't explain what is the recommended programmatic way of creating functions #94841'
    guywi-ms replied:

    There are SDKs that you can use to create functions programmatically, including:

    C# SDK:
    https://learn.microsoft.com/en-us/dotnet/api/microsoft.azure.management.operationalinsights.models.savedsearch?view=azure-dotnet

    Python SDK:
    https://learn.microsoft.com/en-us/python/api/azure-mgmt-loganalytics/azure.mgmt.loganalytics.models.savedsearch?view=azure-python