REST API - Information missing


I am using REST API v2 on prism to retrieve nutanix alerts.
However in the json some informations are missing.

I explain myself:

If i go to my prism central to look the alert, I see in the description of the alert:
"External Client Authentication: IP is authenticating to the REST API with the admin user."

However when I use the REST API call, in the json, the message is:
"External Client Authentication: IP {client_ip_address} is authenticating to the REST API with the admin user"

So I am loosing the information of the IP adress. Why? How can I change this to get the ip when using rest API?

Kind regards.

2 replies

I had the same question and came across a really good post on how to do it via Powershell but the logic applies to anything.

WMWare and Powershell
Author: Grzegorz Kulikowski

In Short:

The data you are looking for to fill the information between the {} is located in the contextTypes and contextValues object of the response. Basically have to map the contextTypes to the contextValues (they are in order) for each Alert.

So basically you get the Alert, then loop through the alert and for each contextType in the message you replace the Alarm message with.

in Powershell:

Foreach ($ContextType in ([regex]::Matches($alarm.message, '{(.*?)}')).Value ) {
$ContextTypeName = $ContextType.Substring(1, $ContextType.Length - 2)
$alarm.message = $alarm.message -replace $ContextType, $context[$ContextTypeName]

Badge +6
Hi @quentinbadoud ! 🙂

To add slightly different detail to the very useful info provided by @rhunt, the data you're looking for can also be easily viewed by looking at the response in JSON Editor Online.

The screenshot below shows a request to https://:9440/api/nutanix/v2.0/alerts on my demo cluster. You'll see client_ip_address under context_types along with in the context_values list.

Can I ask what you are developing your script/app with? Python? PowerShell? Something else? We have some examples of various languages uses over at the Nutanix Developer Portal, if you haven't seen it.