Azure Automation Runbook无法将Webhookdata解析为JSON对象
我对这个问题感到非常震惊。我要求您回答或提示。我的选项用完了。
我正在通过Webhook在高CPU利用率上调用Azure Runbook。我的问题是在运行簿数据中没有正确解码。例如,下行没有打印任何东西。
Write-Output $WebHookData.RequestHeader
如果我尝试将数据转换为JSON,那么在哪里
*$WebhookData = ConvertFrom-Json $WebhookData*
,这是一个投掷错误。
convertfrom-json:无效的JSON原始:。在线:6 char:31 + $ webhookdata = $ webhookdata | convertfrom-json
,我正在尝试使用Azure Gallery上可用的Runbook {垂直扩展具有Azure Automation的Azure Resource Manager VM}
我的Webhook是从VM上创建的Alert中调用的。
一个非常奇怪的观察:
工作网络期示例(在示例中找到){“ webhookname”:“ test1”,“ requestBody”:“ [ \ r \ r \ n {\ r \ r \ n \ n \ sagess \ \ \ \'' :\ \“ test Messages \” \ r \ n} \ r \ n ****] ****”
不起作用(从VM调用运行书发送的数据):
{“ webhookname”:“ test2”,“请求body” “:” { \“ Schemaid \”:\“ AzuremonItormeticerert \” } }
谢谢
I am badly struck by this problem. I request you to answer or give a hint. I am running out of options.
I am calling an azure runbook upon high CPU utilization via a WebHook. My problem is inside runbook data is not getting decoded properly. For example, the below line is not printing anything.
Write-Output $WebHookData.RequestHeader
Wheras IF i try to explictly convert the data to JSON, like this
*$WebhookData = ConvertFrom-Json $WebhookData*
then it is a throwing error.
ConvertFrom-Json : Invalid JSON primitive: . At line:6 char:31 +
$WebhookData = $WebhookData | ConvertFrom-Json
By the way, I am trying to use the runbook available on Azure gallery {Vertically scale up an Azure Resource Manager VM with Azure Automation}
My Webhook is called from alert created on VM.
A very strange observation:
Working WebHood Example (found in an example) {"WebhookName":"test1","RequestBody":" [\r\n {\r\n \"Message\": \"Test Message\"\r\n }\r\n****]****"
Not Working(the data sent upon calling runbook from VM):
{"WebhookName":"test2","RequestBody":" {\"schemaId\":\"AzureMonitorMetricAlert\"}}
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我遇到了同样的错误。从我的测试中,看来在执行运行书的“测试”时,将接收到纯文本,但是当被调用时,它通过已格式化为JSON。这是我的解决方案,以涵盖这两种情况,到目前为止,效果很好。
I was getting the same error. From my testing, it appears that when performing a "Test" of the runbook, the Webhook data is received as plain text, but when invoked remotely it comes through already formatted as JSON. Here was my solution to cover both scenarios and so far has been working well...
我尝试使用webhook,脚本
注销输出$ webhookdata.requestheader
应该正常工作。而且,如果我使用
convertfrom-json $ webhookdata
,我可以重现您的问题,不确定为什么会发生。 /azure/automation/automation-webhooks#参数“ rel =“ nofollow noreferrer”> doc ,$ webhookdata
也以json格式,如果接受,则可以使用<代码> convertfrom -json -inputObject $ webhookdata.requestbody ,它可以正常工作。我的Runbook :
我用来发送webhook 的PowerShell脚本:
输出:
I tried with a webhook, the script
Write-Output $WebHookData.RequestHeader
should work fine.And if I use
ConvertFrom-Json $WebhookData
, I can reproduce your issue, not sure why it occurred, according to the doc, the$WebhookData
is also in a JSON format, if it is accepted, you could useConvertFrom-Json -InputObject $WebhookData.RequestBody
, it will work fine.My runbook:
The powershell script I used to send a webhook:
Output:
如果使用带有警报JSON的测试窗格,我也有相同的问题使用以获取Webhookdata
I had the same problem use following to get webhookdata if using test pane with Alert json as input