Mar 15 2024 06:09 AM
Good day,
I'm trying to find a way to establish if a given appservice or function app has application insight enabled or not, I can easily check it trough the portal, but I would like to do it programmatically via cli (either az cli, or powershell, or rest api), but I cannot find the proper way to do it, so to recap, given an app service I would like to execute a command that returns whether application insight is on or not on the specific app service.
Any help will be appreciated
Thanks
M.
Mar 17 2024 07:14 PM - edited Mar 17 2024 07:16 PM
To use the Azure API Management REST API to check if Application Insights is enabled for an Azure App Service (including Function Apps), you can follow these steps:
Get the Subscription ID and Resource Group Name:
You'll need the Subscription ID and Resource Group Name where your Azure App Service is located.
Get the Azure App Service ID:
You'll need the ID of your Azure App Service. You can find this by navigating to the Azure portal, selecting your App Service, and copying the ID from the URL. It will look something like this:
/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{appName}
Get the Application Insights Component ID:
You'll need the ID of the Application Insights component associated with your App Service. You can find this in the Azure portal by navigating to your App Service, selecting "Application Insights" under Monitoring, and copying the Instrumentation Key from the overview page. The Instrumentation Key is part of the Application Insights Component ID.
Check if Application Insights is Enabled:
Use the Azure API Management REST API to check if Application Insights is enabled for your App Service. You can do this by making a GET request to the following endpoint:
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/p...
Replace {subscriptionId}, {resourceGroupName}, and {appInsightsComponentId} with your Subscription ID, Resource Group Name, and Application Insights Component ID, respectively.
If the GET request returns a successful response (200 OK), it means Application Insights is enabled for your App Service.
Please note that you'll need to authenticate your API requests using Azure AD credentials with appropriate permissions to access the Azure API Management API.
Mar 18 2024 01:43 AM
Mar 18 2024 10:26 AM - edited Mar 18 2024 10:26 AM
You can use the Azure CLI or Azure Resource Manager (ARM) templates to query the resources associated with your App Service. Here's a general approach to determine if an App Service has an active Application Insights component:
Use Azure CLI to list resources: First, list the resources associated with your App Service using the Azure CLI. You can filter the results to include only resources related to Application Insights.
az resource list --tag Microsoft.Web/serverFarmId="<app_service_id>"
Replace <app_service_id> with the ID of your App Service.
Check for Application Insights resource: Look for an Application Insights resource in the list of resources returned by the command. If an Application Insights resource is listed, it indicates that your App Service is linked to an active Application Insights component.
If no Application Insights resource is found, it means that your App Service does not have an active Application Insights component associated with it.
Automate the process: You can automate this process using scripts or Azure Automation to regularly check the status of Application Insights for your App Services.
Note: This approach assumes that the Application Insights component is directly linked to the App Service. If the linking is done at a higher level (e.g., through an Azure Resource Manager template), additional steps may be required to determine the association.
Apr 30 2024 06:50 AM