【发布时间】:2020-07-17 21:11:19
【问题描述】:
我正在尝试通过 curl 使用他们的 REST API 检索 SCOM 警报。它不断返回:
"errorMessage": "Index was outside the bounds of the array.",
"errorTrace": " at Microsoft.EnterpriseManagement.OMDataService.Filters.ValidateAntiForgeryTokenAttribute.OnActionExecuting(HttpActionContext actionContext)\r\n at System.Web.Http.Filters.ActionFilterAttribute.OnActionExecutingAsync(HttpActionContext actionContext, CancellationToken cancellationToken)\r\n...
首先,我拿走了我的:
AuthenticationMode:<domain>\<username>:<password>
string 并将其转换为 UTF8,然后使用 openssl 对其进行 base64 编码。我拿了那个“令牌”并在我的 /OperationsManager/authenticate 调用中使用它,如下所示:
curl --location --request POST 'https://myhostname/OperationsManager/authenticate' \
--header 'Content-Type: application/json; charset=utf-8' \
--data-raw '"<my_base64_encoded_token>"'
这会返回一个“SCOMSessionId”和“SCOM-CSRF-TOKEN”。然后我使用“SCOM-CSRF-TOKEN”并对 /OperationsManager/data/alert 进行以下调用:
curl --location --request POST 'https://myhostname/OperationsManager/data/alert' \
--header 'Content-Type: application/json; charset=utf-8' \
--header 'SCOM-CSRF-TOKEN:<csrf_token_value_here>' \
--data-raw '{
"criteria":"(ResolutionState = '\''0'\'')",
"displayColumns": [
"severity","monitoringobjectdisplayname","name","age","repeatcount"
]
}'
我可能做错了什么?我找到的所有文档都以 powershell 为中心。
【问题讨论】: