As our monitoring is done from Windows platform, we would like to use powershell to retrieve info from ambari-rest-api.
In a browser the api can be explored. First login, then the used url can be pasted: https://someazurenode.westeurope.cloudapp.azure.com/ambari/api/v1/clusters It just shows the json response in the browser.
In curl:
curl --user myusr:mypwd --insecure -i -H 'X-Requested-By:ambari' -X GET https://someazurenode.westeurope.cloudapp.azure.com/ambari/api/v1/clusters
Works fine
In powershell (after disabling ssl-verification**):
$cred = New-Object System.Management.Automation.PSCredential ("myusr", (ConvertTo-SecureString "mypwd" -AsPlainText -Force))
Invoke-WebRequest -Method Get `
-UseBasicParsing `
-Uri "https://someazurenode.westeurope.cloudapp.azure.com/api/v1/clusters" -Headers @{"X-Requested-By"="Ambari"} `
-Credential $cred
--> 404
It seems something with authorisation, therefore I tried the option below (**):
Invoke-WebRequest -Method GET `
-Uri "https://someazurenode.westeurope.cloudapp.azure.com/api/v1/clusters" `
-Headers @{Authorization =[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('myusr:mypwd'))}
--> 404 Not found
** Inspiration for ignoring ssl-verification: Ignoring Self-Signed Certificates from Powershell Invoke-RestMethod doesn't work (it's changed again...)
** Inspiration for handling basic authentication Use Invoke-WebRequest with a username and password for basic authentication on the GitHub API