Azure REST API VM LicenseType parameter - azure

I'm trying to get LicenseType property of running VMs, but the value is not returned as part of query.
How to get it? Is it some kind of "lazy" property?
https://learn.microsoft.com/en-us/rest/api/compute/virtualmachines/get
I tried the standard query and with &expand option..
Really need this setting for Azure VM reporting, if they using AHUB or not.
Powershell returns this value...

The property LicenseType is only used for images that contain the Windows operating system. In other words, we just can get the property with Azure Windows VM.
Besides, if you want to get the property with Rest API, we just need to run a standard query.
For example

Related

Subscription-id, resourceGroupName and name of the App from inside the web-app PowerShell

I have an application hosted in Azure PAAS. The connection string for the application is stored under 'Configuration' -> 'Connection strings'
My application has a PowerShell instance. I want to iterate through all the Connection strings present under 'Configuration' -> 'Connection strings'
I have seen the Azure document. As my application itself is the app, can there be a way to skip the details like 'subscriptionId', 'resourceGroupName' and 'name'?
This will help to make the code more generic.
As my application itself is the app, can there be a way to skip the
details like 'subscriptionId', 'resourceGroupName' and 'name'?
AFAIK, Its not possible to acquire the connection strings using Rest API, or PowerShell of an Azure web application without providing Resource group name or subscription.
The MS DOCUMENT you have followed is to list the connection strings which is correct but we need to pass those credentials to achieve the same.
If my understanding is correct as its your own application and if its publicly hosted then anyone will not be able to get the resource group name, application name(If you are using custom domain) or subscription details.
Alternatively, we can use the Az cli by providing the resource group only :-
For more information please refer the below links:-
SO THREAD|Get the list of azure web app settings to be swapped using PowerShell
If you are going to use the REST API calls for your code, then the simple answer is just: No.
I think in all cases the answer is going to be no honestly..
You can't drop those unique IDs, because those are required parameters to retrieve the correct data.
If you want to make the code more generic, then you should write the code to retrieve the values for those parameters. Instead of hardcoding the values.
Your powershell code will always need to authenticate, or use a Managed Identity, and the identity used to authenticate will always have the subscriptionid as value in its object. As for the rest, well i think you get the gist of what im suggesting.

How to retreive memory cache in Azure app service

I am hosting a Net core application as as Azure app service. The app uses Microsoft.Extensions.Caching.Memoryto set and get string values to cache. Is there a way I can see the key-values stored in my server's in-memory cache ?
Reason:- The values I set, always seem to be null when I retrieve them.
Is there anything like Redis console in azure portal to check the key values present in memory cache?
the part of code used to set and get.
_memoryCache.Set("key1", "value1", TimeSpan.FromHours(1))
_memoryCache.TryGetValue("key1", out string result)
There is no function you mentioned on the azure portal.
Follow below steps, you can retrieve the value.
You need add services.AddMemoryCache(); in ConfigureServices.
And you also change your controller like below. Then you will get the value. It will not be null.

Cross-resource query with app() expression from the portal, “The following application isn’t available anymore”

Is it possible to use the cross-resource query (with 2 subscriptions) from the an Application-Insights resource's, Logs(Analytics) blade in the Azure portal?
I've managed to use the full qualified name for the same app I'm using!
i.e. using
app("/subscriptions/sub1/resourceGroups/rg1/providers/microsoft.insights/components/apptelemetry1").requests in apptelemetry1 returns the same result as the query requests. But trying to use a similar query for an app in another subscription doesn't work (I've double checked the resources names many times).
I've Tried using the all of the options listed in app-expression,
cross-workspace-query.
(Resource name, Qualified Name, ID, Azure Resource ID).
The only response I'm getting is: "The following application isn’t available anymore".
Since you cannot use this query app("/subscriptions/sub1/resourceGroups/rg1/providers/microsoft.insights/components/apptelemetry1").requests in the application insights instance apptelemetry1 itself, there must be some problem with the instance apptelemetry1.
You can check if you have the read access to the application.
And if it's still cannot after assign read access, you can submit a support ticket where you can get professional help from Microsoft.

Cannot create Collection Information -- error when trying to test Cosmos DB trigger locally

I am testing out developing an Azure Function to read the change feed of a Cosmos DB database. I have created such a function from the Azure portal, but I would like to use VS or VS Code to do so. I have my environment set up using v2.0.3 of the Azure Function Core Tools, but when I try to test the function, I get the following error:
[10/9/2018 4:33:34 PM] Error indexing method
'Functions.workordersTrigger'
[10/9/2018 4:33:34 PM] Microsoft.Azure.WebJobs.Host: Error indexing
method 'Functions.workordersTrigger'.
Microsoft.Azure.WebJobs.Extensions.CosmosDB: Cannot create Collection
Information for workorders in database htm with lease wo_leases in
database htm : Entity with the specified id does not exist in the
system.
Both collections "workorders" and "wo_leases" exist in the db. If I just create a function with a simple HTTP trigger, it works fine, and I can debug in VS Code. It seems to be an issue with the CosmosDB trigger. Can anyone point me in the right direction?
The error message appears if:
Any of the collections do not exist in the target account within the specified database
Your account has a Firewall rule (either Virtual Network or IP rules) that block access to your current workstation.
For #1, verify if the Connection String is pointing to the correct account and that you can see the collections exist within the database (for this you can use the Azure Portal or browse Cosmos Explorer with your connection string).
For #2, verify in the Account there is a rule blocking your access. You can either disable the Firewall rule or add your current IP address (there is a quick link for that in the Portal).

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