[英]How to Create Azure Resource Graph Explorer Scheduled Reports and Email Alerts
I have a Kusto query taken from this example that looks like this:我有一个从此示例中提取的 Kusto 查询,如下所示:
Resources
| where type =~ 'microsoft.compute/virtualmachines'
| extend vmPowerState = tostring(properties.extended.instanceView.powerState.code)
| summarize count() by vmPowerState
I would like to create an weekly alert that send the result through an e-mail in a CSV file.我想创建一个每周警报,通过电子邮件将结果发送到 CSV 文件中。
The Logic App is organized in 5 steps: Logic App 分为 5 个步骤:
One:
一:
Two:
二:
With和
{
"query": "Resources | where type =~ 'microsoft.compute/virtualmachines' | extend vmPowerState = tostring(properties.extended.instanceView.powerState.code) | summarize count() by vmPowerState"
}
Three:
三:
Where I parse the Body
and I give an extract of the JSON Schema:在解析
Body
的地方,我给出了 JSON 模式的摘录:
{
"count": 3,
"data": [
{
"count_": 3,
"vmPowerState": "PowerState/stopped"
},
{
"count_": 29,
"vmPowerState": "PowerState/deallocated"
},
{
"count_": 118,
"vmPowerState": "PowerState/running"
}
],
"skip_token": null,
"total_records": 3
}
Here I have a few doubt because I found a guide that says that I should use array
formula instead.在这里我有一些疑问,因为我找到了一个指南,说我应该改用
array
公式。 I'm not very sure about that because I cannot see the details in the example.我对此不是很确定,因为我看不到示例中的详细信息。 Anyway this is what I do:
无论如何,这就是我所做的:
Four:
四:
Five:
五:
Where I create the attachment from the CSV我从 CSV 创建附件的位置
The e-mail in the end arrives but the attachment is not a CSV, it's a JSON file:电子邮件终于到了,但附件不是 CSV,而是 JSON 文件:
What the hack am I doing wrong?我做错了什么?
if you want to use "Create CSV table" with Columns set to "Automatic", do pass the "body" of "parse Json".如果你想使用“创建 CSV 表”并将列设置为“自动”,请传递“解析 Json”的“正文”。
you don't need to use the array variable but whatever you use need to return an array like this:您不需要使用数组变量,但无论您使用什么,都需要返回这样的数组:
The body of the json parser on your example has many other json nodes enveloping that.您的示例中 json 解析器的主体包含许多其他 json 节点。 You should have the option "data" as there is an array there called "data"
您应该有“数据”选项,因为那里有一个名为“数据”的数组
if you want to cut it short, try "data"如果你想缩短它,试试“数据”
you can change to "custom".您可以更改为“自定义”。 that would allow you to remove redundant data or format data (like the "PowerState" in "PowerState/stopped"):
这将允许您删除冗余数据或格式数据(如“PowerState/stopped”中的“PowerState”):
you can also add the.csv to the file name:您还可以将.csv 添加到文件名中:
The above worked for me but it can be enhanced以上对我有用,但可以增强
The suggestoin posted by @BrunoLucasAzure really helped me understand how Logic Apps works. @BrunoLucasAzure 发布的建议确实帮助我理解了逻辑应用程序的工作原理。
However I would like to reply to my own question with the right solution: I had to paste a sample of the JSON output pressing on the button Use sample payload to generate schema .但是,我想用正确的解决方案回答我自己的问题:我必须粘贴 JSON output 的示例,按下按钮Use sample payload to generate schema 。
Then follow the workflow and everything will be fine.然后按照流程走就万事大吉了。
The next problem I need to fix is pagination but apparently there is a solution for that too: https://techcommunity.microsoft.com/t5/integrations-on-azure-blog/logic-app-http-pagination-deeper-look-build-custom-paging/ba-p/2907605我需要解决的下一个问题是分页,但显然也有一个解决方案: https://techcommunity.microsoft.com/t5/integrations-on-azure-blog/logic-app-http-pagination-deeper-look -build-custom-paging/ba-p/2907605
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.