由于我们的监控是从Windows平台完成的,我们希望使用powershell从ambari-rest-api中检索信息。
在浏览器中可以探索api。首次登录,然后使用的网址可以是……
找到问题,最后......在我们的案例中,我们需要通过3个步骤来修复连接:
从那里很容易检索信息。
function Disable-SslVerification { if (-not ([System.Management.Automation.PSTypeName]"TrustEverything").Type) { Add-Type -TypeDefinition @" using System.Net.Security; using System.Security.Cryptography.X509Certificates; public static class TrustEverything { private static bool ValidationCallback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; } public static void SetCallback() { System.Net.ServicePointManager.ServerCertificateValidationCallback = ValidationCallback; } public static void UnsetCallback() { System.Net.ServicePointManager.ServerCertificateValidationCallback = null; } } "@ } [TrustEverything]::SetCallback() } function Enable-SslVerification { if (([System.Management.Automation.PSTypeName]"TrustEverything").Type) { [TrustEverything]::UnsetCallback() } } $domain = "my-cluster.westeurope.cloudapp.azure.com/ambari" $usernm = "myusr" $userpwd = "mypwd" Disable-SslVerification [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 $uri = "https://{0}/api/v1/clusters" -f $domain Write-Output $uri $credstring = "{0}:{1}" -f $usernm, $userpwd $credbytes = [System.Text.Encoding]::ASCII.GetBytes($credstring) $credbase64 = [System.Convert]::ToBase64String($credbytes) $credAuthValue = "Basic {0}" -f $credbase64 $headers = @{ Authorization = $credAuthValue} $result = "-" $result = Invoke-RestMethod -Method Get -UseBasicParsing -Uri $uri -Headers $headers $result