簡體   English   中英

使用 azure 邏輯應用程序編輯 json 內容

[英]Editing json content with azure logic app

我想創建一個邏輯應用程序,它替換邏輯應用程序收到的警報 json 結構中 resourcename 的值。 告警結構如下:

{
  "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>"
    }
  }
}

我一直在嘗試與“設置變量”、“初始化變量”、“撰寫”塊進行各種混合,但仍然沒有成功。 有人有線索嗎?

基於上述要求,我創建了邏輯應用程序,它使用 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": {}
}

這是運行上述邏輯應用程序的參考帖子示例 output

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM