Home » Nutanix » Nutanix Infra details – Prism Central and PowerShell

Continuing with the last post, this post will focus on collecting multi cluster inventory details through Prism Central (PC).

As part of collecting the inventory, query one or more prism central in the environment to prepare following reports

  • Details for each Nutanix cluster
  • Node list and their details
  • Storage container details
  • VMs list and their details
#define the prism central FQDN and the credentials for them
$NXPClist = @{
"prismcentral01" = "username:password"
"prismcentral02" = "username:password"
} 

$reportFolder =  "path of root folder to place the report files"
$NtnxPNodeReportName = "NX_Node-" + (Get-Date -Format dd-MMM-yyyy) + ".csv"
$NtnxPclusReportName = "NX_Cluster-" + (Get-Date -Format dd-MMM-yyyy) + ".csv"
$NtnxPcontrReportName = "NX_Container-" + (Get-Date -Format dd-MMM-yyyy) + ".csv"
$NtnxVMReportName = "NX_VMs-" + (Get-Date -Format dd-MMM-yyyy) + ".csv"

$NtnxPNodeReportFile = Join-Path $reportFolder $NtnxPNodeReportName
$NtnxPclusReportFile = Join-Path $reportFolder $NtnxPclusReportName
$NtnxPcontrReportFile = Join-Path $reportFolder $NtnxPcontrReportName
$NtnxVMReportFile = Join-Path $reportFolder $NtnxVMReportName



add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"
 
# Clusters(prism elements) under the prism central
foreach ( $NXPC in $NXPClist.Keys) {

$clusterlookup = @()

$Header = @{"Authorization" = "Basic "+[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes($NXPClist.$NXPC))}

$NXClusters=Invoke-RestMethod -Method Get -Uri "https://$($NXPC):9440/PrismGateway/services/rest/v2.0/clusters" -Headers $Header

foreach ( $NtnxclusData in $NXClusters.entities) {
$Report1 = "" | select Name,uuid,IP,StType,Nodes,NOSv,NCCv,RFPlaned,RFNow,ExtSeg,IntSeg,ShadowClone,DNS,NTP,MGMTSrvIP,MGMTSrv,MgmtSrvType, `
StorageCapGB,StorageUseGB,StorageUseLogical,StorageFree,StorageUsedP,ProvisionedP
 select Name,uuid

$Report1.Name =  $NtnxclusData.name
$Report1.uuid = $NtnxclusData.cluster_uuid
$Report1.IP = $NtnxclusData.cluster_external_ipaddress
$Report1.StType = $NtnxclusData.storage_type
$Report1.Nodes = $NtnxclusData.num_nodes
$Report1.NOSv = $NtnxclusData.version
$Report1.NCCv = $NtnxclusData.ncc_version.split("-")[1]
$Report1.RFPlaned = $NtnxclusData.cluster_redundancy_state.desired_redundancy_factor
$Report1.RFNow = $NtnxclusData.cluster_redundancy_state.current_redundancy_factor
$Report1.ExtSeg = $NtnxclusData.external_subnet
$Report1.IntSeg = $NtnxclusData.internal_subnet 
$Report1.ShadowClone = $NtnxclusData.enable_shadow_clones
$Report1.DNS = $NtnxclusData.name_servers -join ","
$Report1.NTP = $NtnxclusData.ntp_servers -join ","

$Report1.MGMTSrvIP = $NtnxclusData.management_servers.ip_address
if ($NtnxclusData.management_servers.ip_address) {$Report2.MGMTSrv = (Resolve-DnsName $NtnxclusData.management_servers.ip_address).Server}
$Report1.MgmtSrvType = $NtnxclusData.management_servers.management_server_type
$Report1.StorageCapGB = ($NtnxclusData.usage_stats.'storage.capacity_bytes' / 1GB).ToString("#")
$Report1.StorageUseGB = ($NtnxclusData.usage_stats.'storage.usage_bytes' / 1GB).ToString("#")
$Report1.StorageUseLogical = ($NtnxclusData.usage_stats.'storage.logical_usage_bytes' / 1GB).ToString("#")
$Report1.StorageFree = ($NtnxclusData.usage_stats.'storage.free_bytes' / 1GB).ToString("#")
$Report1.StorageUsedP = ($NtnxclusData.usage_stats.'storage.usage_bytes' / $NtnxclusData.usage_stats.'storage.capacity_bytes').ToString("P")
$Report1.ProvisionedP = ($NtnxclusData.usage_stats.'storage.logical_usage_bytes' / $NtnxclusData.usage_stats.'storage.capacity_bytes').ToString("P")

$Report1 | Export-Csv -Append $NtnxPclusReportFile


$clusterlookup += $Report1 | select uuid,name
}

# Nodes and their details 

$NXhosts = Invoke-RestMethod -Method Get -Uri "https://$($NXPC).we.interbrew.net:9440/PrismGateway/services/rest/v2.0/hosts" -Headers $Header

foreach ($NtnxHostData in $NXhosts.entities) {
    $Report2 = ""|select NxCluster,NXHost,NXIP,OOBIP,HPVIP,NSN,BSN,Bmodel,CPU,Cores,Sockets,RAMGB,HPV,HPVVer, `
    VMs,StorageCapGB,StorageUseGB,StorageUseLogical,StorageFree,StorageSSDCap,StorageHDDCap

    $Report2.NxCluster = ($clusterlookup | ? uuid -eq $NtnxHostData.cluster_uuid).Name
    $Report2.NXHost = $NtnxHostData.name.Split(".")[0]
    $Report2.NXIP = $NtnxHostData.service_vmexternal_ip
    $Report2.OOBIP = $NtnxHostData.ipmi_address
    $Report2.HPVIP = $NtnxHostData.hypervisor_address
    $Report2.NSN = $NtnxHostData.serial
    $Report2.BSN = $NtnxHostData.block_serial
    $Report2.Bmodel = $NtnxHostData.block_model_name
    $Report2.CPU = $NtnxHostData.cpu_model.Split(" ")[3,4,6] -join " "
    $Report2.Cores = $NtnxHostData.num_cpu_cores
    $Report2.Sockets = $NtnxHostData.num_cpu_sockets
    $Report2.RAMGB = ($NtnxHostData.memory_capacity_in_bytes / 1GB).ToString("#")
    $Report2.HPV = $NtnxHostData.hypervisor_type
    $Report2.HPVVer = $NtnxHostData.hypervisor_full_name
    $Report2.VMs = $NtnxHostData.num_vms


    $Report2.StorageCapGB = ($NtnxHostData.usage_stats.'storage.capacity_bytes' / 1GB).ToString("#")
    $Report2.StorageUseGB = ($NtnxHostData.usage_stats.'storage.usage_bytes' / 1GB).ToString("#")
    $Report2.StorageUseLogical = ($NtnxHostData.usage_stats.'storage.logical_usage_bytes' / 1GB).ToString("#")
    $Report2.StorageFree = ($NtnxHostData.usage_stats.'storage.free_bytes' / 1GB).ToString("#")
    $Report2.StorageFree = ($NtnxHostData.usage_stats.'storage.free_bytes' / 1GB).ToString("#")
    $Report2.StorageSSDCap = ($NtnxHostData.usage_stats.'storage_tier.ssd.capacity_bytes' / 1GB).ToString("#")
    $Report2.StorageHDDCap = ($NtnxHostData.usage_stats.'storage_tier.das-sata.capacity_bytes' / 1GB).ToString("#")

    
    $Report2 | Export-Csv -Append $NtnxPNodeReportFile
    
   }

# List of Nutanix containers 
$NXContainers = Invoke-RestMethod -Method Get -Uri "https://$($NXPC).we.interbrew.net:9440/PrismGateway/services/rest/v2.0/storage_containers" -Headers $Header
foreach ($NtnxContrData in $NXContainers.entities) {
    $Report3 = ""|select NxCluster,CntrName,MaxCap,AdvCap,ExReserved,ImReserved,RF,OplogRF,ErasureCode,WFPrint,Dedup,Compression,SoftEncrypt, `
    vstores,Rcontainers,ForRemoval,io_preference
    $Report3.NxCluster = ($clusterlookup | ? uuid -eq $NtnxContrData.cluster_uuid).Name
    $Report3.CntrName = $NtnxContrData.name
    $Report3.MaxCap = ($NtnxContrData.max_capacity / 1GB).ToString("#")
    $Report3.AdvCap = ($NtnxContrData.advertised_capacity / 1GB).ToString("#")
    $Report3.ExReserved = ($NtnxContrData.total_explicit_reserved_capacity / 1GB).ToString("#")
    $Report3.ImReserved = ($NtnxContrData.total_implicit_reserved_capacity / 1GB).ToString("#")
    $Report3.RF = $NtnxContrData.replication_factor
    $Report3.OplogRF = $NtnxContrData.oplog_replication_factor
    $Report3.ErasureCode = $NtnxContrData.erasure_code
    $Report3.WFPrint = $NtnxContrData.finger_print_on_write
    $Report3.Dedup = $NtnxContrData.on_disk_dedup
    $Report3.Compression = $NtnxContrData.compression_enabled
    $Report3.SoftEncrypt = $NtnxContrData.enable_software_encryption
    $Report3.vstores = $NtnxContrData.vstore_name_list -join ","
    $Report3.Rcontainers = $NtnxContrData.mapped_remote_containers -join ","
    $Report3.io_preference = $NtnxContrData.random_io_preference -join ","
    $Report3.ForRemoval = $NtnxContrData.marked_for_removal
    $Report3 | Export-Csv -Append $NtnxPcontrReportFile
    
   }
# List of VMs and details from prims central 
$NXVMS = Invoke-RestMethod -Method Get -Uri "https://$($NXPC).we.interbrew.net:9440/PrismGateway/services/rest/v1/vms" -Headers $Header
foreach ($NXVM in $NXVMs.entities) {
    $Report4 = ""|select VMName,Description,Hpv,Power,NXhost,NxCluster,vCPUs,CPUResv,RAM,RAMResv,VMNICS,VMIPs,Disks,DiskCap,IsCtrVM, `
    ProtectDomain,ProtectTpe,DedupDisk,diskpath
    $Report4.VMName = $NXVM.vmname
    $Report4.Description = $NXVM.description
    $Report4.Hpv = $NXVM.hypervisorType
    $Report4.Power = $NXVM.powerState
    $Report4.NXhost = $NXVM.hostName.Split(".")[0]
    $Report4.NxCluster = ($clusterlookup | ? uuid -eq $NXVM.clusterUuid).Name
    $Report4.vCPUs = $NXVM.numVCpus
    if ($NXVM.cpuReservedInHz) {$Report4.CPUResv = $NXVM.cpuReservedInHz / 1000000 }
    $Report4.RAM = $NXVM.memoryCapacityInBytes / 1GB
    if ($NXVM.memoryReservedCapacityInBytes) {$Report4.RAMResv = $NXVM.memoryReservedCapacityInBytes / 1GB}
    $Report4.VMNICS = $NXVM.numNetworkAdapters
    $Report4.VMIPs = $NXVM.ipAddresses -join ","
    $Report4.Disks = $NXVM.nutanixVirtualDisks.Count
    $Report4.diskpath = $NXVM.nutanixVirtualDisks -join ","
    $Report4.DiskCap = $NXVM.diskCapacityInBytes / 1GB
    $Report4.IsCtrVM = $NXVM.controllerVm
    $Report4.ProtectDomain = $NXVM.protectionDomainName
    $Report4.ProtectTpe = $NXVM.protectionType
    $Report4.DedupDisk = $NXVM.onDiskDedup
    $Report4 | Export-Csv -Append $NtnxVMReportFile
    }

}

 

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*