SOLVED

VM with Public IP

Brass Contributor

Hi All,

 

Can someone help me with query to get list of VM names and public IP address assigned to them.

 

Also how to create view in dashboard for the same as I dont have permission to modify or share existing shared dashboards, hence need the output in my private dashboard.

 

thanks in advance

8 Replies

Hi@Rahul_Mahajan Can you specify more details? Are these for Azure VMs? Also it is important to understand that Log Analytics does not have such information. Trough Heartbeat data you can get the public IP address from which the VM communicates to internet but it does not mean that the VM itself have such information. On the other hand this information should be possible to find via Resource Graph if it is only for Azure VMs. Data from Azure Resource Graph can be visualized in dashboard. Is that what you are looking for?

@Stanislav Zhelyazkov 

 

Yes, exactly that's what I am looking for.

 

@CliveWatson  and @Noa Kuperberg 

Also when I am trying to create visual using query all things pointing to Visual Designer but I am not able to find in Azure portal, seems to be depreciated. Do we have any alternative for it?

 

I am trying to create something like :

 

https://adinermie.com/using-azure-backup-logs-azure-log-analytics-aka-oms/

best response confirmed by Stanislav Zhelyazkov (MVP)
Solution

Hi@Rahul_Mahajan 

Here is a blog post about visualizing data from resource graph in Azure Dashboards: https://samcogan.com/visualise-your-azure-resource-with-resource-graph-explorer/

 

Azure Monitor workbooks can also visualize data from the resource graph:

https://docs.microsoft.com/en-us/azure/azure-monitor/app/usage-workbooks

 

Below you can find the resource graph query. Keep in mind you can get only the IP address of static ip address:

Resources | where type =~ "Microsoft.Network/networkInterfaces"
 | mv-expand properties.ipConfigurations
 | where isnotempty(properties_ipConfigurations.properties.publicIPAddress.id)
 | extend publicIpId = tostring(properties_ipConfigurations.properties.publicIPAddress.id)
  | join (
	Resources | where type =~ "microsoft.network/publicipaddresses"
 ) on $left.publicIpId == $right.id
 | extend ipAddress = tostring(properties1.ipAddress)
 | extend publicIPAllocationMethod = tostring(properties1.publicIPAllocationMethod)
 | extend publicIpName = tostring(name1)
 | extend vmId = tostring(properties.virtualMachine.id)
 | where notempty(vmId)
  | join  (
	 Resources | where type == "microsoft.compute/virtualmachines"
 ) on $left.vmId == $right.id
| extend name = name2
| extend resourceGroup = resourceGroup2
| project name, resourceGroup,publicIpName, publicIPAllocationMethod, ipAddress

@Stanislav Zhelyazkov  Thanks, will check and get back to you.

 

@Clive Watson  and @Noa Kuperberg  Can you please help me with what is alternative for view designer so I can create dashboards as required 

Anyone can update on above query?

Hi@Rahul_Mahajan 

Have you tried the links I have posted on visualizations ?

At the end it depends on what you want to visualize exactly and how. For example when you execute the below query in Resource Graph explorer you will click on Chart tab and there you can ping it to dashboard

Resources | where type =~ "Microsoft.Network/networkInterfaces"
 | mv-expand properties.ipConfigurations
 | where isnotempty(properties_ipConfigurations.properties.publicIPAddress.id)
 | extend publicIpId = tostring(properties_ipConfigurations.properties.publicIPAddress.id)
  | join (
	Resources | where type =~ "microsoft.network/publicipaddresses"
 ) on $left.publicIpId == $right.id
 | extend ipAddress = tostring(properties1.ipAddress)
 | extend publicIPAllocationMethod = tostring(properties1.publicIPAllocationMethod)
 | extend publicIpName = tostring(name1)
 | extend vmId = tostring(properties.virtualMachine.id)
 | where notempty(vmId)
  | join  (
	 Resources | where type == "microsoft.compute/virtualmachines"
 ) on $left.vmId == $right.id
| extend name = name2
| extend resourceGroup = resourceGroup2
| project name, resourceGroup,publicIpName, publicIPAllocationMethod, ipAddress
| summarize count()  by name

 For workbooks there are also some guidance on how to do it.

An update for anyone coming across this: I've checked with Microsoft Premier Support and they confirmed last month (Sep 2020) that "right now you can get both dynamic and static IPs for sure using Resource Graph, there's no limitation on this."

 

As for an Azure Resource Graph query that can retrieve all the private and public IPs for a VM, not just one, I wrote about how to build one step-by-step here https://mihai-albert.com/2020/10/01/get-the-list-of-all-azure-vms-with-all-their-private-and-public-....

@mihaialbert 

I did a Workbook for PublicIP a while back https://github.com/CliveW-MSFT/KQLpublic/tree/master/KQL/Workbooks/PublicIP  it has some ARG and KQL examples - sharing in case its useful.

1 best response

Accepted Solutions
best response confirmed by Stanislav Zhelyazkov (MVP)
Solution

Hi@Rahul_Mahajan 

Here is a blog post about visualizing data from resource graph in Azure Dashboards: https://samcogan.com/visualise-your-azure-resource-with-resource-graph-explorer/

 

Azure Monitor workbooks can also visualize data from the resource graph:

https://docs.microsoft.com/en-us/azure/azure-monitor/app/usage-workbooks

 

Below you can find the resource graph query. Keep in mind you can get only the IP address of static ip address:

Resources | where type =~ "Microsoft.Network/networkInterfaces"
 | mv-expand properties.ipConfigurations
 | where isnotempty(properties_ipConfigurations.properties.publicIPAddress.id)
 | extend publicIpId = tostring(properties_ipConfigurations.properties.publicIPAddress.id)
  | join (
	Resources | where type =~ "microsoft.network/publicipaddresses"
 ) on $left.publicIpId == $right.id
 | extend ipAddress = tostring(properties1.ipAddress)
 | extend publicIPAllocationMethod = tostring(properties1.publicIPAllocationMethod)
 | extend publicIpName = tostring(name1)
 | extend vmId = tostring(properties.virtualMachine.id)
 | where notempty(vmId)
  | join  (
	 Resources | where type == "microsoft.compute/virtualmachines"
 ) on $left.vmId == $right.id
| extend name = name2
| extend resourceGroup = resourceGroup2
| project name, resourceGroup,publicIpName, publicIPAllocationMethod, ipAddress

View solution in original post