{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "actionGroups_ag_manual_recovery_alerts_odms_dev_name": {
      "type": "String"
    },
    "scheduledqueryrules_ManualRecoveryAlerts_name": {
      "type": "String"
    },
    "sites_app_odms_dictation_dev_externalid": {
      "type": "String"
    }
  },
  "resources": [
    {
      "apiVersion": "2023-01-01",
      "location": "Global",
      "name": "[parameters('actionGroups_ag_manual_recovery_alerts_odms_dev_name')]",
      "properties": {
        "armRoleReceivers": [],
        "automationRunbookReceivers": [],
        "azureAppPushReceivers": [],
        "azureFunctionReceivers": [],
        "emailReceivers": [
          {
            "emailAddress": "saito.k@nds-tyo.co.jp",
            "name": "テスト通知_-EmailAction-",
            "useCommonAlertSchema": false
          }
        ],
        "enabled": true,
        "eventHubReceivers": [],
        "groupShortName": "手動復旧が必要なエラー",
        "itsmReceivers": [],
        "logicAppReceivers": [],
        "smsReceivers": [],
        "voiceReceivers": [],
        "webhookReceivers": []
      },
      "tags": {
        "Environment": "develop",
        "Project": "ODMS",
        "ms-resource-usage": "ManualRecoveryAlerts"
      },
      "type": "microsoft.insights/actionGroups"
    },
    {
      "apiVersion": "2023-03-15-preview",
      "dependsOn": [
        "[resourceId('microsoft.insights/actionGroups', parameters('actionGroups_ag_manual_recovery_alerts_odms_dev_name'))]"
      ],
      "location": "japaneast",
      "name": "[parameters('scheduledqueryrules_ManualRecoveryAlerts_name')]",
      "properties": {
        "actions": {
          "actionGroups": [
            "[resourceId('microsoft.insights/actionGroups', parameters('actionGroups_ag_manual_recovery_alerts_odms_dev_name'))]"
          ],
          "actionProperties": {},
          "customProperties": {}
        },
        "autoMitigate": false,
        "criteria": {
          "allOf": [
            {
              "dimensions": [],
              "failingPeriods": {
                "minFailingPeriodsToAlert": 1,
                "numberOfEvaluationPeriods": 1
              },
              "operator": "GreaterThanOrEqual",
              "query": "AppServiceConsoleLogs | where  Level == \"Error\" and ResultDescription contains \"[MANUAL_RECOVERY_REQUIRED]\"\n",
              "threshold": 1.0,
              "timeAggregation": "Count"
            }
          ]
        },
        "description": "手動復旧が必要なエラーを検知し、設定されたメールアドレスに通知を行う",
        "displayName": "[parameters('scheduledqueryrules_ManualRecoveryAlerts_name')]",
        "enabled": true,
        "evaluationFrequency": "PT1M",
        "scopes": [
          "[parameters('sites_app_odms_dictation_dev_externalid')]"
        ],
        "severity": 0,
        "targetResourceTypes": [
          "Microsoft.Web/sites"
        ],
        "windowSize": "PT1M"
      },
      "type": "microsoft.insights/scheduledqueryrules"
    }
  ],
  "variables": {}
}
