Azure Monitor 警报规则向 Slack 通道发送通知

问题描述 投票:0回答:1

我希望有人可以帮助我解决或至少让我找到解决以下问题的正确路径。

我在 azure 监视器中创建了一个新的警报规则,用于对一些服务的

Response Time
发出警报。阅读微软文档,我发现我无法触发这些警报并直接向 Slack 通道发送通知,但我需要一个逻辑应用程序来处理这个问题。

所以我创建了规则和逻辑应用程序。逻辑应用程序有 2 个步骤,如下所示:

  • 当收到带有以下请求正文的 HTTP 请求时
{
    "properties": {
        "body": {
            "properties": {
                "data": {
                    "properties": {
                        "context": {
                            "properties": {
                                "condition": {
                                    "properties": {
                                        "allOf": {
                                            "items": {
                                                "properties": {
                                                    "dimensions": {
                                                        "type": "array"
                                                    },
                                                    "metricName": {
                                                        "type": "string"
                                                    },
                                                    "metricNamespace": {
                                                        "type": "string"
                                                    },
                                                    "metricValue": {
                                                        "type": "number"
                                                    },
                                                    "operator": {
                                                        "type": "string"
                                                    },
                                                    "threshold": {
                                                        "type": "string"
                                                    },
                                                    "timeAggregation": {
                                                        "type": "string"
                                                    },
                                                    "webTestName": {}
                                                },
                                                "required": [
                                                    "metricName",
                                                    "metricNamespace",
                                                    "operator",
                                                    "threshold",
                                                    "timeAggregation",
                                                    "dimensions",
                                                    "metricValue",
                                                    "webTestName"
                                                ],
                                                "type": "object"
                                            },
                                            "type": "array"
                                        },
                                        "windowSize": {
                                            "type": "string"
                                        }
                                    },
                                    "type": "object"
                                },
                                "conditionType": {
                                    "type": "string"
                                },
                                "description": {
                                    "type": "string"
                                },
                                "id": {
                                    "type": "string"
                                },
                                "name": {
                                    "type": "string"
                                },
                                "portalLink": {
                                    "type": "string"
                                },
                                "resourceGroupName": {
                                    "type": "string"
                                },
                                "resourceId": {
                                    "type": "string"
                                },
                                "resourceName": {
                                    "type": "string"
                                },
                                "resourceType": {
                                    "type": "string"
                                },
                                "severity": {
                                    "type": "string"
                                },
                                "subscriptionId": {
                                    "type": "string"
                                },
                                "timestamp": {
                                    "type": "string"
                                }
                            },
                            "type": "object"
                        },
                        "properties": {},
                        "status": {
                            "type": "string"
                        },
                        "version": {
                            "type": "string"
                        }
                    },
                    "type": "object"
                },
                "schemaId": {
                    "type": "string"
                }
            },
            "type": "object"
        },
        "headers": {
            "properties": {
                "CLIENT-IP": {
                    "type": "string"
                },
                "Content-Length": {
                    "type": "string"
                },
                "Content-Type": {
                    "type": "string"
                },
                "Cookie": {
                    "type": "string"
                },
                "DISGUISED-HOST": {
                    "type": "string"
                },
                "Expect": {
                    "type": "string"
                },
                "Host": {
                    "type": "string"
                },
                "Max-Forwards": {
                    "type": "string"
                },
                "User-Agent": {
                    "type": "string"
                },
                "WAS-DEFAULT-HOSTNAME": {
                    "type": "string"
                },
                "X-ARR-LOG-ID": {
                    "type": "string"
                },
                "X-ARR-SSL": {
                    "type": "string"
                },
                "X-AppService-Proto": {
                    "type": "string"
                },
                "X-CorrelationContext": {
                    "type": "string"
                },
                "X-Forwarded-For": {
                    "type": "string"
                },
                "X-Forwarded-Proto": {
                    "type": "string"
                },
                "X-Forwarded-TlsVersion": {
                    "type": "string"
                },
                "X-Original-URL": {
                    "type": "string"
                },
                "X-SITE-DEPLOYMENT-ID": {
                    "type": "string"
                },
                "X-WAWS-Unencoded-URL": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

第二步是:

  • 发布消息,连接到 Slack 通道。

我面临的问题是,当警报触发并且我在 slack 中收到通知时,通知具有空值。如下

Name:
Description:
Resource Name:

我的预期输出如下:

Name: Something
Description: some descritpion
....

据我了解并且我能够调试(希望)是警报生成的有效负载是一个通用模式,它与传递到逻辑应用程序第一步的请求正文完全不同。在查看逻辑应用第二步中的动态变量时,它们指向

triggerBody()?['data']?['context']?['name']

这些值与逻辑应用中的

HTTP request is received
负载匹配,但与监视器警报中的自定义负载不同。

任何人都可以帮助我了解我是否走在正确的轨道上,如何解决这个问题才能正确填充发送到 Slack 的消息中的字段?

如果我错过了一些东西或者不是100%清楚,我很抱歉,如果您需要更多细节或澄清,请告诉我

azure-logic-apps azure-monitoring azure-monitor
1个回答
0
投票

我已按照使用逻辑应用自定义警报通知创建了警报。

最初,我通过将 Request Body JSON Schema 保留为空,在工作流程中添加了 当收到 HTTP 请求时 触发器。警报触发后,我从逻辑应用程序的运行历史记录中获取输出来生成如下所示的架构-

enter image description here

单击 使用示例有效负载生成架构

enter image description here

粘贴输出并单击完成以生成输入模式。

enter image description here

然后我添加了发布消息 (V2) 操作来连接到 slack。

enter image description here

我能够得到预期的输出。

enter image description here enter image description here

参考文献-

来自 Azure Application Insights 警报通知的逻辑应用 HTTP 请求 JSON - 堆栈内存溢出

© www.soinside.com 2019 - 2024. All rights reserved.