App Service health check is 0% even when in browser website returns 200 - azure

I have enabled health check with path "/" for App Service slot.
This path in browser and using curl return 200 status code.
But App Service health check status displays 0.00% (Healthy 0 / Degraded 1)
How is this possible?

Just to highlight that if your application depends on a database and a messaging system, the Health check endpoint should connect to those components. If the application can't connect to a critical component, then the path should return a 500-level response code to indicate the app is unhealthy. See: Monitor App Service instances using Health check
Also: Please confirm to make sure that your health check path was added successfully:
From Azure Portal:
To enable Health check, browse to the Azure portal and select your App
Service app.
Under Monitoring, select Health check.
Select Enable and provide a valid URL path on your application, such as
/health or /api/health.
Select Save.
From Resource url:
You may use the following URL: https://resources.azure.com/ to check that you added the path correctly in your web application.
Follow the steps here:
Go to https://resources.azure.com/
Expand your subscription > Go to Resource Groups > Select the Resource
Group where the app service is hosted.
The select providers > Then select Microsoft Web > Open sites And open your
app service > Then open config > And lastly web.
You will need to scroll to the bottom to find the variable called
‘healthCheckPath’ and you will see the value there for the path you set in
the portal.
Also refer to this detailed document on Health check here might be helpful: https://learn.microsoft.com/en-us/azure/app-service/monitor-instances-health-check?tabs=dotnet#frequently-asked-questions
Addition:
Using curl to the heatlhCheckPath in the case of multiple running instances could be misleading as you might not receive status of each running instance of the app and might get result for random instance the load balancer directs to you.
Suggest you to fetch the values of Health Check Status metric by using the Azure CLI.
az monitor metrics list --resource myresource --resource-group myresourcegroup --resource-type "Microsoft.Web/sites" --metric "HealthCheckStatus" --interval 5m
Also please Note that the --interval property is important as health checks do not support the default 1m interval used by az monitor metrics list

Related

How to set alert on edit/delete of a file or folder in Azure Portal

Log files for my sample application is getting created in the following folder in azure portal
D:/home/LogFiles/sample_application/sample_application.log
sample_application.log can be both edited and deleted.
Is there a way in azure portal to trigger an email alert when someone tries to modify or delete the log file??
• Yes, you can surely configure an alert using the Azure Monitor regarding the deletion of the log file from the App service through the kudu console or by some other means. For this purpose, you will have to create an alert rule from the Azure Monitor alerts pane with the condition ‘ AppServiceFileAuditLogs | where OperationName == “Delete” and Path == “D:/home/LogFiles/sample_application/sample_application.log” ’ with the action of sending an alert to the email id as registered with this alert rule. Please find the link below on how to create an alert rule through Azure Monitor: -
https://learn.microsoft.com/en-us/azure/azure-monitor/alerts/alerts-activity-log
Also find the below snapshot below for reference: -
Also, ensure that condition is selected as ‘Custom Log Search’ for as below: -
Please find the link below for detailed instructions on implementing the integration between Azure app service and Azure monitor: -
https://azure.github.io/AppService/2019/11/01/App-Service-Integration-with-Azure-Monitor.html

How to pass a key to a service app through Azure application's gateway?

I have configured an application gateway in the Azure portal and I have added a function app in the backend pool. The authorization level on one of the function in the function app is set to "function", now I want to pass the function key of this function using application gateway instead of passing it through URL.
for example- http://20.0.0.1/api/HttpExample?code=XV2Js97D/Zy5aw6th2hr7iLzFbBiuZ4RfdKuT8nA==
Where, 20.0.0.1 is application gateway public IP and
/api/HttpExample?code=XV2Js97D/Zy5aw6th2hr7iLzFbBiuZ4RfdKuT8nA== is function URL
Is there any way to make this happen?
Please find the below two ways used to pass a key to function app from API and get the output without key in the URL.
Method 1:
Passing the Key to the service App in the form of Headers.
Steps:
Azure Portal > API Management Service > Your API > Your Service App >
Select Get HttpTrigger > Click on Test Pane
There you can copy the key -value or you can also copy from the
subscriptions pane in your API Service.
Pass these values to the header section in the developer portal of
your API, as shown below:
Then the output will be:
Method 2:
Go to Azure Portal > API Management Services > Your API > APIs pane
Select your service app ( I selected Function App)
Click on Settings > uncheck the box option 'Subscription required' on Subscription Menu and click on Save.
Note: Make Sure you have removed the key in the headers section.
Now run your API in developer portal, it should show 200 response code as below:
Unchecking the subscription key in the settings menu should not be
done on production side. It can be used for Dev and Testing Purposes.
Passing the key to a service app in the form of header is one of the best way, instead in the URL.

App service name in Azure DevOps shows No Results Found

I selected the Azure Subscription that matches the Subscription ID from my app service in Azure Portal, but I keep getting this message No Results Found when I try to select an App Service Name.
Please check if you Service connection is not limited to resource group. For instace this one is:
To check this please go to: Project Settings -> Service Connections -> end edit connection to see details.
Resource group should be empty if your choice is to do not limit connection to particular resource group.
So my guess is that your connection is limited to resource group which doesnt have app service.
I would suggest you to please check the App type i.e., webapp you created on window, or some other OS based on select the App type. I created my web app on Windows OS and can be able to see the app service name populating over here.
Search for the Task : AZURE APP SERVICE DEPLOY

How to know the origin resource group of a App Service Plan?

I have an Azure App Service Plan and a Web App. I want to move them to another subscription. There is a limitation that app service plan and app service must be moved together from the origin resource group of the app service plan. Someone had moved the resources from their origin resource group and deleted the resource group. Now, how can I find the name of the origin resource group ?
In some cases it can be found in the WebSpace property of app service plan. For example [ "webSpace": "RG-SK-MarkIII-CentralUSwebspace" ], RG-SK-MarkIII is the origin resource group of the app plan. But in my case the webSpace is like this ["webSpace": "AustraliaEastwebspace" ]. Is there any other way to find it through CloudShell ?
You can look up the actions taken by a particular user, even for a resource group that no longer exists.
az monitor activity-log list -g ExampleGroup --caller someone#contoso.com --offset 5d
Kindly try these steps:
If you don't remember the original resource group, you can find it through diagnostics.
For your web app, select Diagnose and solve problems.
Then, select Configuration and Management.
Select Migration Options.
Select the option for recommended steps to move the web app.
You see the recommended actions to take before moving the resources. The information includes the original resource group for the web app.
- I understand you're referring to RG deletion scenario, kindly try this and let me know how it goes.
Reference document move across subscription.
Furthermore, you can only change to a plan that was created in the same "webspace" as your original app. Webspace is an internal concept that's not exposed, but you can verify whether your source and destination plans are in the same webspace or not.
To verify, do the following:
https://resources.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/serverfarms/{serverFarmName}
Confirm whether the webSpace property of your source plan matches the webSpace property of your new plan

How can I programatically (C#) read the autoscale settings for a WebApp?

I'm trying to build a small program to change the autoscale settings for our Azure WebApps, using the Microsoft.WindowsAzure.Management.Monitoring and Microsoft.WindowsAzure.Management.WebSites NuGet packages.
I have been roughly following the guide here.
However, we are interested in scaling WebApps / App Services rather than Cloud Services, so I am trying to use the same code to read the autoscale settings but providing a resource ID for our WebApp. I have already got the credentials required for making a connection (using a browser window popup for Active Directory authentication, but I understand we can use X.509 management certificates for non-interactive programs).
This is the request I'm trying to make. Credentials already established, and an exception is thrown earlier if they're not valid.
AutoscaleClient autoscaleClient = new AutoscaleClient(credentials);
var resourceId = AutoscaleResourceIdBuilder.BuildWebSiteResourceId(webspaceName: WebSpaceNames.NorthEuropeWebSpace, serverFarmName: "Default2");
AutoscaleSettingGetResponse get = autoscaleClient.Settings.Get(resourceId); // exception here
The WebApp (let's call it "MyWebApp") is part of an App Service Plan called "Default2" (Standard: 1 small), in a Resource Group called "WebDevResources", in the North Europe region. I expect that my problem is that I am using the wrong names to build the resourceId in the code - the naming conventions in the library don't map well onto what I can see in the Azure Portal.
I'm assuming that BuildWebSiteResourceId is the correct method to call, see MSDN documentation here.
However the two parameters it takes are webspaceName and serverFarmName, neither of which match anything in the Azure portal (or Google). I found another example which seemed to be using the WebApp's geo region for webSpaceName, so I've used the predefined value for North Europe where our app is hosted.
While trying to find the correct value for serverFarmName in the Azure Portal, I found the Resource ID for the App Service Plan, which looks like this:
/subscriptions/{subscription-guid}/resourceGroups/WebDevResources/providers/Microsoft.Web/serverfarms/Default2
That resource ID isn't valid for the call I'm trying to make, but it does support the idea that a 'serverfarm' is the same as an App Service Plan.
When I run the code, regardless of whether the resourceId parameters seem to be correct or garbage, I get this error response:
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
{"Code":"SettingNotFound","Message":"Could not find the autoscale settings."}
</string>
So, how can I construct the correct resource ID for my WebApp or App Service Plan? Or alternatively, is there a different tree I should be barking up to programatially manage WebApp scaling?
Update:
The solution below got the info I wanted. I also found the Azure resource explorer at resources.azure.com extremely useful to browse existing resources and find the correct names. For example, the name for my autoscale settings is actually "Default2-WebDevResources", i.e. "{AppServicePlan}-{ResourceGroup}" which I wouldn't have expected.
There is a preview service https://resources.azure.com/ where you can inspect all your resources easily. If you search for autoscale in the UI you will easily find the settings for your resource. It will also show you how to call the relevant REST Api endpoint to read or update that resorce.
It's a great tool for revealing a lot of details for your deployed resources and it will actually give you an ARM template stub for the resource you are looking at.
And to answer your question, you could programmatically call the REST API from a client with updated settings for autoscale. The REST API is one way of doing this, the SDK another and PowerShell a third.
The guide which you're following is based on the Azure Service Management model, aka Classic mode, which is deprecated and only exists mainly for backward compatibility support.
You should use the latest
Microsoft.Azure.Insights nuget package for getting the autoscale settings.
Sample code using the nuget above is as below:
using Microsoft.Azure.Management.Insights;
using Microsoft.Rest;
//... Get necessary values for the required parameters
var client = new InsightsManagementClient(new TokenCredentials(token));
client.AutoscaleSettings.Get(resourceGroupName, autoScaleSettingName);
Besides, the autoscalesettings is a resource under the "Microsoft.Insights" provider and not under the "Microsoft.Web" provider, which explains why you are not able to find it with your serverfarm resourceId.
See the REST API Reference below for getting the autoscale settings.
GET
https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-name}/providers/microsoft.insights/autoscaleSettings/{autoscale-setting-name}?api-version={api-version}

Resources