使用invoke-restmethod通过powerhsell向AppDynamics发送消息时出错



我正试图通过powershell使用'Invoke-RestMethod'向App Dynamics发送消息,这是下面的错误

Invoke-RestMethod: AppDynamics -错误报告HTTP状态400 -事件summary is not specifiedtype Status reportmessageEvent summary is not客户端发送的请求语法错误不正确的。

我正在使用下面的代码发送消息。

$JSONBody = @{
'@context'= 'http://schema.org/extensions'
'@type'= 'MessageCard'
'title' = 'Incoming Alert Test Message'
'text' = 'xyz'
'eventtype'='CUSTOM'
'customeventtype'='appDcustomevent'
}
$json = ConvertTo-Json $JSONBody -Depth 100
$headers = @{Authorization='Basic '+[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes('username@account:password'))}
$response = Invoke-RestMethod -Uri 'https://rest api url/events' -Proxy 'proxy url:80' -Method Post -Headers $headers -Body $json -ContentType 'application/json'

请帮助我了解如何解决这个问题,因为我没有线索。

提前感谢,Usha .

您的请求缺少"摘要";字段:https://docs.appdynamics.com/appd/20.x/en/extend-appdynamics/appdynamics-apis/alert-and-respond-api/events-and-action-suppression-api#EventsandActionSuppressionAPI-CreateaCustomEvent

(在"输入参数"下标记为"必填"的每个字段;表必须包含在请求中)

更新:

下面是测试工作,似乎JSON版本确实有问题-所以切换到使用查询参数,这是预期的工作

$application_id = "<APPLICATION_NAME>"
$summary = "This_is_a_summary"
$severity = "INFO"
$eventtype = "CUSTOM"
$controller = "<CONTROLLER_URL_NO_PROTOCOL>"
$port = "8090"
$protocol = "http"
$account = "<ACCOUNT>"
$username = "<USERNAME>"
$password = "<PASSWORD>"
$controllerEndpoint = "controller/rest/applications/${application_id}/events"
$restURL = "${protocol}://${controller}:${port}/${controllerEndpoint}?severity=${severity}&summary=${summary}&eventtype=${eventtype}"
"$restURL"
$headers = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes("${username}@${account}:${password}"))}
$response = Invoke-RestMethod -Uri $restURL -Method Post -Headers $headers -Body $JSON -ContentType "application/json"
$response.content

最新更新