【问题标题】:Using curl the SCOM rest api returns "Index was outside the bounds of the array"使用 curl 的 SCOM rest api 返回“索引超出了数组的范围”
【发布时间】: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 为中心。

【问题讨论】:

    标签: curl scom


    【解决方案1】:

    需要解码 SCOM-CSRF-TOKEN。我知道它在文档中的任何地方都没有告诉你。

    使用诸如https://www.urldecoder.org/ 之类的站点将起作用,或者如果您希望以编程方式执行此操作,您可以在ruby 中使用诸如URI.decode() 之类的东西,例如。在 bash 中也有这个答案How to decode URL-encoded string in shell?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-19
      • 1970-01-01
      • 2015-11-06
      • 2010-11-17
      • 1970-01-01
      相关资源
      最近更新 更多