{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspace": {
      "type": "String"
    }
  },
  "resources": [
    {
      "apiVersion": "2024-01-01-preview",
      "id": "[concat(resourceId('Microsoft.OperationalInsights/workspaces/providers', parameters('workspace'), 'Microsoft.SecurityInsights'),'/alertRules/deb9b2cb-3ada-4276-bf1f-b2e3de3adb01')]",
      "kind": "Scheduled",
      "name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/deb9b2cb-3ada-4276-bf1f-b2e3de3adb01')]",
      "properties": {
        "alertDetailsOverride": {
          "alertDescriptionFormat": "{{StatusMessage}}",
          "alertDisplayNameFormat": "SonicWall CSE connector fetch failure: {{StatusCode}}"
        },
        "alertRuleTemplateName": "deb9b2cb-3ada-4276-bf1f-b2e3de3adb01",
        "customDetails": {
          "FailureType": "FailureType",
          "StatusCode": "StatusCode"
        },
        "description": "'The SonicWall Cloud Secure Edge (CSE) event connector reported a failed data fetch, for\nexample HTTP 401 after the API key was deleted or expired. While it fails, no CSE events are\ningested, and events from the failure period are not fetched later: after fixing the cause,\ndisconnect and connect the connector, then backfill the gap.\nThe rule matches both health records the poller writes: a \"Data fetch status change\" with\nStatus Failure (written once, when the status changes) and the hourly \"Data fetch failure\nsummary\" (written while failures continue). A poller that stops polling without failing\nwrites neither; the rule \"SonicWall CSE - No events ingested\" covers that case.'\n",
        "displayName": "SonicWall CSE - Event connector failing to fetch data",
        "enabled": true,
        "entityMappings": [
          {
            "entityType": "AzureResource",
            "fieldMappings": [
              {
                "columnName": "SentinelResourceId",
                "identifier": "ResourceId"
              }
            ]
          }
        ],
        "OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/SonicWall%20Cloud%20Secure%20Edge/Analytic%20Rules/SonicWallCSEConnectorHealthFailure.yaml",
        "query": "// Only records ingested since the previous run, so each record alerts once although the\n// query period overlaps runs to allow for health ingestion delay.\nSentinelHealth\n| where ingestion_time() > ago(15m)\n| where SentinelResourceType == \"Data connector\" and SentinelResourceKind == \"ApiPolling\"\n| where SentinelResourceName endswith \"CSEEventsPoller\"\n| where Status == \"Failure\" or OperationName == \"Data fetch failure summary\"\n| extend Failures = ExtendedProperties.FailureSummary\n| mv-expand Failure = iff(array_length(Failures) > 0, Failures, dynamic([{}]))\n| extend\n    StatusCode = coalesce(tostring(Failure.StatusCode), Reason),\n    FailureType = tostring(Failure.HealthResultType),\n    StatusMessage = coalesce(tostring(Failure.StatusMessage), Description),\n    FailureStart = todatetime(ExtendedProperties.StartTime),\n    FailureEnd = todatetime(ExtendedProperties.EndTime)\n| project TimeGenerated, SentinelResourceName, OperationName, Status, StatusCode, FailureType,\n    StatusMessage, FailureStart, FailureEnd, SentinelResourceId\n",
        "queryFrequency": "PT15M",
        "queryPeriod": "PT1H",
        "severity": "High",
        "subTechniques": [],
        "suppressionDuration": "PT1H",
        "suppressionEnabled": false,
        "tactics": [
          "DefenseEvasion"
        ],
        "techniques": [
          "T1562"
        ],
        "templateVersion": "1.0.0",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 0
      },
      "type": "Microsoft.OperationalInsights/workspaces/providers/alertRules"
    }
  ]
}
