question

GeorgeChristianis-0199 avatar image
0 Votes"
GeorgeChristianis-0199 asked AlexZhu-MSFT edited

SCOM 2019 UR2 Rest API

HI,

I am tyrinng to send alerts + metrics from my SCOM instance into a global console.
I was trying to call my SCOM instance using a REST API Call.

But, I am receiving the following error message:

Invoke-RestMethod : {"errorMessage":"The underlying connection was closed: An unexpected error occurred on a send.","errorTrace":" at System.Net.HttpWebRequest.GetResponse()\r\n at
Microsoft.EnterpriseManagement.OMDataService.Service.Impl.AuthenticationService.InitializeIntegratedMonitoringViewCache(String sessionId, String authmode, String encodedCredentials)\r\n
at Microsoft.EnterpriseManagement.OMDataService.Service.Impl.AuthenticationService.Authenticate(String encodedCredentials)\r\n at
Microsoft.EnterpriseManagement.OMDataService.Controllers.AuthenticationController.Login(String credentials)\r\n at lambda_method(Closure , Object , Object[] )\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.c_DisplayClass10.b9(Object instance, Object[] methodParameters)\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments)\r\n at
System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of
stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d
0.MoveNext()\r\n--- End of
stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d
5.MoveNext()\r\n--- End of stack
trace from previous location where exception was thrown ---\r\n at System.Web.Http.Filters.ActionFilterAttribute.d
5.MoveNext()\r\n--- End of stack trace from previous location where
exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Filters.ActionFilterAttribute.d
0.MoveNext()\r\n--- End of stack
trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ActionFilterResult.d
2.MoveNext()\r\n--- End of stack
trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at
System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Web.Http.Controllers.ExceptionFilterResult.d
_0.MoveNext()"}
At line:12 char:9
+ $auth = Invoke-RestMethod -Method POST -Uri $uriBase -Headers $scomhe ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand



I am using the following powershell:

$scomHeaders = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$scomHeaders.Add('Content-Type','application/json; charset=utf-8')

$bodyraw = "Windows"
$Bytes = [System.Text.Encoding]::UTF8.GetBytes($bodyraw)
$EncodedText =[Convert]::ToBase64String($Bytes)
$jsonbody = $EncodedText | ConvertTo-Json

$uriBase = 'https://{my scom console name}/operationsmanager/authenticate'

$cred = Get-Credential
$auth = Invoke-RestMethod -Method POST -Uri $uriBase -Headers $scomheaders -body $jsonbody -Credential $cred -SessionVariable websession




Is the URL which I am calling correct?

Do I need to initialize the CSRF token anywere?

Thanks

partner-center-api
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

RaytheonXie-MSFT avatar image
0 Votes"
RaytheonXie-MSFT answered GeorgeChristianis-0199 commented

Hi @GeorgeChristianis-0199 ,
It is all because TLS, TLS 1.1 and TLS 1.2 not allowed in the server, Which is why the command failed, To resolve the issue, do the following,
Open the Command prompt and run the below command,

 [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.




· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

HI RaytheonXie-MSFT,

thank you for your response.
I am now receiving:


Invoke-RestMethod : Unable to connect to the remote server
At line:27 char:19
+ ... ntication = Invoke-RestMethod -Method Post -Uri $URIBase -Headers $SC ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand


Thanks

0 Votes 0 ·