0
votes

I want to create a logic app which replaces the value of resourcename inside an alert json structure received by a logic app. The alarm structure is as follows:

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

I've been trying all sorts of mix with 'set variable', 'initialize variable', 'compose' blocks, but still no luck. Anyone has a clue?

1

1 Answers

0
votes

Based on the above requirement i have created the logic app which replaces the resource name using HTTP request & replace actions.

Below is the code view of my logic app :

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

Here is the sample output for reference post running the above logic app

enter image description here