【问题标题】:Editing json content with azure logic app使用 azure logic app 编辑 json 内容
【发布时间】:2021-08-22 16:14:44
【问题描述】:

我想创建一个逻辑应用,它替换逻辑应用接收到的警报 json 结构内的资源名称的值。告警结构如下:

{
  "schemaId": "AzureMonitorMetricAlert",
  "data": {
    "version": "2.0",
    "properties": null,
    "status": "Deactivated",
    "context": {
      "timestamp": "2021-08-21T01:43:09.2000007Z",
      "id": "/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/microsoft.insights/metricAlerts/teste%20-%20vpnp2s%20count",
      "name": "teste - vpnp2s count",
      "description": "",
      "conditionType": "SingleResourceMultipleMetricCriteria",
      "severity": "3",
      "condition": {
        "windowSize": "PT1M",
        "allOf": [
          {
            "metricName": "P2SConnectionCount",
            "metricNamespace": "Microsoft.Network/p2sVpnGateways",
            "operator": "GreaterThanOrEqual",
            "threshold": "1",
            "timeAggregation": "Total",
            "dimensions": [],
            "metricValue": 0,
            "webTestName": null
          }
        ]
      },
      "subscriptionId": "<subscription_id>",
      "resourceGroupName": "<my_resource_group>",
      "resourceName": "some_resource_name",
      "resourceType": "Microsoft.Network/p2sVpnGateways",
      "resourceId": "/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/Microsoft.Network/p2sVpnGateways/<p2svpngatewayid>",
      "portalLink": "https://portal.azure.com/#resource/subscriptions/<subscription_id>/resourceGroups/<my_resource_group>/providers/Microsoft.Network/p2sVpnGateways/<theresourceid>"
    }
  }
}

我一直在尝试使用“set variable”、“initialize variable”、“compose”块进行各种混合,但仍然没有运气。有人知道吗?

【问题讨论】:

    标签: json azure-logic-apps


    【解决方案1】:

    基于上述要求,我创建了使用 HTTP 请求和替换操作替换资源名称的逻辑应用。

    下面是我的逻辑应用的代码视图:

    {
        "definition": {
            "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
            "actions": {
                "ConversionToString": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "StringConversion",
                                "type": "string",
                                "value": "@{json(string(triggerBody()))}"
                            }
                        ]
                    },
                    "runAfter": {},
                    "type": "InitializeVariable"
                },
                "FInalJsonOutput": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "JsonOutput",
                                "type": "object",
                                "value": "@json(variables('replaceResouceName'))"
                            }
                        ]
                    },
                    "runAfter": {
                        "ReplaceResourceName": [
                            "Succeeded"
                        ]
                    },
                    "type": "InitializeVariable"
                },
                "ReplaceResourceName": {
                    "inputs": {
                        "variables": [
                            {
                                "name": "replaceResouceName",
                                "type": "string",
                                "value": "@{replace(variables('StringConversion'),'some_resource_name','newresource')}"
                            }
                        ]
                    },
                    "runAfter": {
                        "ConversionToString": [
                            "Succeeded"
                        ]
                    },
                    "type": "InitializeVariable"
                }
            },
            "contentVersion": "1.0.0.0",
            "outputs": {},
            "parameters": {},
            "triggers": {
                "manual": {
                    "inputs": {
                        "schema": {
                            "properties": {
                                "data": {
                                    "properties": {
                                        "context": {
                                            "properties": {
                                                "condition": {
                                                    "properties": {
                                                        "allOf": {
                                                            "items": {
                                                                "properties": {
                                                                    "dimensions": {
                                                                        "type": "array"
                                                                    },
                                                                    "metricName": {
                                                                        "type": "string"
                                                                    },
                                                                    "metricNamespace": {
                                                                        "type": "string"
                                                                    },
                                                                    "metricValue": {
                                                                        "type": "integer"
                                                                    },
                                                                    "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"
                        }
                    },
                    "kind": "Http",
                    "type": "Request"
                }
            }
        },
        "parameters": {}
    }
    

    这是运行上述逻辑应用程序的参考帖子的示例输出

    【讨论】:

    • 这很有见地...但是,resourceName 字段的值不是固定的。 “some_resource_name”只是一个值的例子......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2021-07-18
    • 1970-01-01
    • 2019-10-29
    • 1970-01-01
    • 2019-03-29
    相关资源
    最近更新 更多