使用 curl SCOM rest api returns "Index was outside the bounds of the array"

Using curl the SCOM rest api returns "Index was outside the bounds of the array"

我正在尝试通过 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>"'

这 returns 我一个“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 为中心。

SCOM-CSRF-TOKEN 需要解码。我知道它不会在文档中的任何地方告诉你这个。

使用 https://www.urldecoder.org/ will work, or if you are looking to do it programmatically you can use something like URI.decode(<your_token_value>) in ruby, for instance. There is this answer for just doing it in bash as well How to decode URL-encoded string in shell?

等网站