简体   繁体   English

如何创建 Azure Resource Graph Explorer 计划报告和 Email 警报

[英]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.

相关问题 通过资源管理器模板创建Azure警报(不是经典警报) - Create Azure alerts (not classic) by resource manager templates 如何在成本管理中为 Azure 创建报告并将它们发送到 email - how to create reports in Cost Management for Azure and send them in email 在 Azure 资源图中创建联接 - Create a Join in Azure Resource Graph Azure 资源图资源管理器中缺少资源 createdTime 属性 - Resource createdTime property missing in Azure Resource Graph Explorer 如何使用 Terraform 创建 Azure 警报 - How to create Azure Alerts using Terraform 如何使用 Terraform 为 Azure 资源创建警报 - How to create alerts for Azure resources using Terraform Azure Resource Graph Explorer::在时间图表中绘制趋势线 - Azure Resource Graph Explorer :: Draw a trendline in the time chart 为 Azure 警报配置电子邮件模板 - Configure Email Template for Azure Alerts 来自 Azure 搜索图 Search-AzGraph 与 Azure 资源图资源管理器的意外搜索结果 - Unexpected search result from Azure Search Graph Search-AzGraph vs Azure Resource Graph Explorer Microsoft图形浏览器-创建用户并更新登录用户名/ email - Microsoft graph explorer - create user & update sign in username /email
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM