Shweta Agarwal
Shweta Agarwal

Reputation: 1

Nutanix Cluster Report using API

How can i fetch the cluster report from the Nutanix prism portal using powershell (API or module)?

I need to fetch the cluster details like total capacity, free capacity, usage capacity etc.

Upvotes: 0

Views: 1103

Answers (2)

There seems to be a lot of confusion (at least for me) regarding what version of the API you have. Below is my configuration with the API version listed at the bottom. If you have what I have, you have the API that I have.

Prism Central:

  • AOS: 6.5.5.7
  • Files Manager: 4.4.0.3
  • Licensing: LM.2022.2.1
  • NCC: 4.6.5.2
  • PC: pc.2022.6.0.11
  • API: 3.0

Prism Element:

  • AOS 6.5.5.7
  • ESX_NX hypervisor: 7.0.3-21930508
  • FSM: 4.4.0.3
  • File Analytics: 3.4.0.1
  • File Server: 4.4.0.3
  • Foundation: 5.6.1
  • Foundation Platforms: 2.15.1
  • Licensing: LM.2022.2.1
  • NCC: 4.6.6.2
  • Security AOS: 1.0.0
  • API: 2.0

Common Code:

#This looks stupid, but you need the plaintext password later
$Pwd="<password>"
$SecurePwd=ConvertTo-SecureString -String $Pwd -AsPlainText -Force
$Cred=[System.Management.Automation.PSCredential]::new("<user name>",$SecurePwd)

#region you only need this section if you don't trust the certificate
$TypeDef=@"
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; }
}
"@
Add-Type -TypeDefinition $TypeDef -Language CSharp
[System.Net.ServicePointManager]::CertificatePolicy=New-Object TrustAllCertsPolicy
#endregion

$SecureBase64AuthInfo=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Cred.UserName,$Cred.Password)))
$Base64AuthInfo=[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $Cred.UserName,$Pwd)))

Prism Central:

$Header=@{Accept="application/json";Authorization="Basic $SecureBase64AuthInfo"}
$URI="https://<name or IP of central>:9440/PrismGateway/services/rest/v2.0/"
$Command="cluster"
$Central=Invoke-WebRequest -Method Get -Uri ($URI+$Command) -Credential $Cred -ContentType "application/json" -Headers $Header | Select-Object -ExpandProperty Content | ConvertFrom-Json

Prism Element:

$Header=@{Accept="application/json";Authorization="Basic $Base64AuthInfo"}
$URI="https://<name or IP of element>:9440/api/nutanix/v3/clusters/list"
$Body='{"kind":"cluster"}'
$Element=Invoke-WebRequest -Method Post -Uri $URI -Credential $Cred -ContentType "application/json" -Headers $Header -Body $Body -UseBasicParsing Select-Object -ExpandProperty Content | ConvertFrom-Json

Question Specific Answer:

If you use my code, I think you're looking for $Central.usage_stats.

Upvotes: 0

Kees
Kees

Reputation: 21

There's a few options, one of them would be using:

Alternatively there's nutanix.dev with a whole bunch of examples you can use to get this kickstarted

disclaimer: I'm a Nutanix employee and author of the script in the first link.

Upvotes: 2

Related Questions