Public/Deploy/Core/monitoring/New-CmAzCoreMonitor.json

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "ActionGroups": {
            "type": "Array"
        },
        "Alerts": {
            "type": "Array"
        },
        "AppInsightsName": {
            "type": "String"
        },
        "ServiceContainer": {
            "type": "Object"
        },
        "Solutions": {
            "type": "Array",
            "defaultValue": [
                {
                    "planName": "KeyVaultAnalytics",
                    "type": "KeyVaultAnalytics"
                },
                {
                    "planName": "AzureActivity",
                    "type": "AzureActivity"
                },
                {
                    "planName": "AgentHealthAssessment",
                    "type": "AgentHealthAssessment"
                },
                {
                    "planName": "Updates",
                    "type": "Updates"
                },
                {
                    "planName": "VMInsights",
                    "type": "VMInsights"
                },
                {
                    "planName": "ServiceMap",
                    "type": "ServiceMap"
                }
            ]
        },
        "WorkspaceName": {
            "type": "String"
        }
    },
    "resources": [
        {
            "type": "Microsoft.OperationalInsights/Workspaces",
            "apiVersion": "2015-11-01-preview",
            "name": "[parameters('workspaceName')]",
            "location": "[resourceGroup().location]",
            "tags": {
                "cm-service": "[parameters('ServiceContainer').workspace]"
            },
            "properties": {
                "sku": {
                    "name": "pergb2018"
                },
                "retentionInDays": 90,
                "features": {
                    "searchVersion": 1,
                    "legacy": 0,
                    "enableLogAccessUsingOnlyResourcePermissions": true
                }
            }
        },
        {
            "type": "Microsoft.Insights/Components",
            "apiVersion": "2014-04-01",
            "name": "[parameters('AppInsightsName')]",
            "location": "[resourceGroup().location]",
            "tags": {
                "cm-service": "[parameters('ServiceContainer').appInsights]"
            },
            "properties": {
                "ApplicationId": "[parameters('AppInsightsName')]"
            },
            "dependsOn": [
                "[parameters('workspaceName')]"
            ]
        },
        {
            "name": "[concat(parameters('workspaceName'), '/', subscription().subscriptionId)]",
            "type": "Microsoft.OperationalInsights/Workspaces/DataSources",
            "apiVersion": "2015-11-01-preview",
            "properties": {
                "linkedResourceId": "[concat(subscription().Id, '/providers/Microsoft.Insights/eventTypes/management')]"
            },
            "kind": "AzureActivityLog",
            "dependsOn": [
                "[parameters('workspaceName')]"
            ]
        },
        {
            "apiVersion": "2015-11-01-preview",
            "type": "Microsoft.OperationsManagement/Solutions",
            "location": "[resourceGroup().location]",
            "name": "[concat(parameters('Solutions')[copyIndex('SolutionsCopy')].type, '(', parameters('workspaceName'), ')')]",
            "id": "[resourceId('microsoft.operationsManagement/Solutions', concat(parameters('Solutions')[copyIndex('SolutionsCopy')].type, '(', parameters('workspaceName'), ')'))]",
            "tags": {
                "cm-service": "[parameters('ServiceContainer').solution]"
            },
            "properties": {
                "workspaceResourceId": "[resourceId('Microsoft.OperationalInsights/workspaces', parameters('workspaceName'))]"
            },
            "dependsOn": [
                "[parameters('workspaceName')]"
            ],
            "plan": {
                "name": "[concat(parameters('Solutions')[copyIndex('SolutionsCopy')].type, '(', parameters('workspaceName'), ')')]",
                "product": "[concat('OMSGallery/', parameters('Solutions')[copyIndex('SolutionsCopy')].type)]",
                "promotionCode": "",
                "publisher": "Microsoft"
            },
            "copy": {
                "name": "SolutionsCopy",
                "count": "[length(parameters('Solutions'))]"
            }
        },
        {
            "type": "Microsoft.Insights/ActionGroups",
            "apiVersion": "2019-03-01",
            "name": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].name]",
            "location": "Global",
            "tags": {
                "cm-service": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].service.publish.actionGroup]"
            },
            "properties": {
                "groupShortName": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].shortName]",
                "enabled": true,
                "armRoleReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].armRoles]",
                "automationRunbookReceivers": "[parameters('actionGroups')[copyIndex('ActionGroupCopy')].runbooks]",
                "azureAppPushReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].notifications]",
                "azureFunctionReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].functions]",
                "emailReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].emails]",
                "itsmReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].itsm]",
                "logicAppReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].logicApps]",
                "smsReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].sms]",
                "voiceReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].voice]",
                "webhookReceivers": "[parameters('ActionGroups')[copyIndex('ActionGroupCopy')].webhooks]"
            },
            "copy": {
                "name": "ActionGroupCopy",
                "count": "[length(parameters('ActionGroups'))]"
            }
        },
        {
            "type": "Microsoft.Insights/ActivityLogAlerts",
            "apiVersion": "2020-10-01",
            "name": "[parameters('Alerts')[copyIndex('AlertsCopy')].name]",
            "location": "Global",
            "tags": {
                "cm-service": "[parameters('Alerts')[copyIndex('AlertsCopy')].servicePublish]"
            },
            "properties": {
                "enabled": "[parameters('Alerts')[copyIndex('AlertsCopy')].enabled]",
                "scopes": [
                    "[subscription().Id]"
                ],
                "condition": {
                    "allOf": "[parameters('Alerts')[copyIndex('AlertsCopy')].conditions]"
                },
                "actions": {
                    "actionGroups": [
                        {
                            "actionGroupId": "[resourceId('Microsoft.Insights/ActionGroups', parameters('Alerts')[copyIndex('AlertsCopy')].actionGroupName)]",
                            "webhookProperties": {}
                        }
                    ]
                }
            },
            "copy": {
                "name": "AlertsCopy",
                "count": "[length(parameters('Alerts'))]"
            }
        }
    ]
}