【问题标题】:Logic App with azure monitor and conditions具有天蓝色监视器和条件的逻辑应用程序
【发布时间】:2021-11-01 02:18:26
【问题描述】:

我用 logicAPP 创建了一个工作流。目标是在 VM 缺少补丁时通知团队。我在逻辑应用程序中使用 azure monitor 来设置查询。我决定在 Azure Monitor 之后放置一个条件,以了解查询表是否为空或有数据。如果表为空,则 logix 为 true ,因此不发送通知,如果为 false ,则发送通知。

当我运行时,我遇到了逻辑错误。通常,表没有数据,但在条件之后,函数 empty([my_table]) 返回 false 并向我发送结果通知(“查询未产生数据”)

有什么问题??

谢谢

【问题讨论】:

    标签: notifications conditional-statements azure-logic-apps azure-monitor


    【解决方案1】:

    基于上述共享要求,我们创建了逻辑应用并在我们的本地环境中对其进行了测试,它运行良好。

    下面是完整的逻辑代码:

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "Condition_2": {
                    "actions": {
                        "Terminate_2": {
                            "inputs": {
                                "runStatus": "Cancelled"
                            },
                            "runAfter": {},
                            "type": "Terminate"
                        }
                    },
                    "else": {
                        "actions": {
                            "Send_an_email_(V2)_2": {
                                "inputs": {
                                    "body": {
                                        "Body": "<p>@{base64ToString(body('Run_query_and_visualize_results')?['body'])}</p>",
                                        "Subject": "list of vm from update management ",
                                        "To": "<UserEmailId>"
                                    },
                                    "host": {
                                        "connection": {
                                            "name": "@parameters('$connections')['office365']['connectionId']"
                                        }
                                    },
                                    "method": "post",
                                    "path": "/v2/Mail"
                                },
                                "runAfter": {},
                                "type": "ApiConnection"
                            }
                        }
                    },
                    "expression": {
                        "and": [
                            {
                                "equals": [
                                    "@length(body('Run_query_and_visualize_results')?['body'])",
                                    0
                                ]
                            }
                        ]
                    },
                    "runAfter": {
                        "Run_query_and_visualize_results": [
                            "Succeeded"
                        ]
                    },
                    "type": "If"
                },
                "Run_query_and_visualize_results": {
                    "inputs": {
                        "body": "Update\n| where Classification == 'Security Updates' or Classification  == 'Critical Updates'\n| where UpdateState == 'Needed'\n| summarize by Computer,ResourceGroup,Classification,UpdateState\n|sort by Computer",
                        "host": {
                            "connection": {
                                "name": "@parameters('$connections')['azuremonitorlogs']['connectionId']"
                            }
                        },
                        "method": "post",
                        "path": "/visualizeQuery",
                        "queries": {
                            "resourcegroups": "<Resource_group_Name",
                            "resourcename": "<log analytics workspacename",
                            "resourcetype": "Log Analytics Workspace",
                            "subscriptions": "<subcription_id>",
                            "timerange": "Last 12 hours",
                            "visType": "Html Table"
                        }
                    },
                    "runAfter": {},
                    "type": "ApiConnection"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {
                "$connections": {
                    "defaultValue": {},
                    "type": "Object"
                }
            },
            "triggers": {
                "Recurrence": {
                    "evaluatedRecurrence": {
                        "frequency": "Hour",
                        "interval": 3
                    },
                    "recurrence": {
                        "frequency": "Hour",
                        "interval": 3
                    },
                    "type": "Recurrence"
                }
            }
        },
        "parameters": {
            "$connections": {
                "value": {
                    "azuremonitorlogs": {
                        "connectionId": "/subscriptions/<subcription-id>/resourceGroups/<resource-group>/providers/Microsoft.Web/connections/azuremonitorlogs",
                        "connectionName": "azuremonitorlogs",
                        "id": "/subscriptions/<subcription-id>/providers/Microsoft.Web/locations/northcentralus/managedApis/azuremonitorlogs"
                    },
                    "office365": {
                        "connectionId": "/subscriptions/<subcription-id>/resourceGroups/<resource-group>/providers/Microsoft.Web/connections/office365",
                        "connectionName": "office365",
                        "id": "/subscriptions/<subcription-id>/providers/Microsoft.Web/locations/northcentralus/managedApis/office365"
                    }
                }
            }
        }
    }
    

    请找到上述逻辑示例运行的参考输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-07
      • 1970-01-01
      • 2016-03-25
      • 1970-01-01
      • 2021-10-17
      相关资源
      最近更新 更多