{
  "$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/2dafed9a-a8ea-4696-82ac-63ec6e5a3dab')]",
      "kind": "Scheduled",
      "name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/2dafed9a-a8ea-4696-82ac-63ec6e5a3dab')]",
      "properties": {
        "alertDetailsOverride": {
          "alertDescriptionFormat": "Trust level changed from {{PreviousLevel}} to AlwaysDeny. Failed factors: {{FailedFactorList}}.",
          "alertDisplayNameFormat": "SonicWall CSE: device {{HostName}} trust level AlwaysDeny"
        },
        "alertRuleTemplateName": "2dafed9a-a8ea-4696-82ac-63ec6e5a3dab",
        "customDetails": {
          "FailedFactors": "FailedFactorList",
          "PreviousLevel": "PreviousLevel",
          "TrustProfile": "TrustProfileName"
        },
        "description": "'A device's SonicWall Cloud Secure Edge (CSE) trust level changed to AlwaysDeny, so the device\nis denied access to protected resources. Causes include failed trust factors (for example\ndisk encryption or firewall turned off), no trust profile matching the device (\"Default\"),\nor an administrator ban. Alerts once per change: the trust state repeats on every Service\nTunnel event, so only TrustScoring events are evaluated, and an evaluation that stays at\nAlwaysDeny does not alert again.\nEvaluates events by when they reached Sentinel, so events that arrive late (connector\ndelay or a backfill) are evaluated once, when they arrive. The query period is 2 days to\ninclude backfilled events, which keep their own time for up to 48 hours.'\n",
        "displayName": "SonicWall CSE - Device trust level dropped to AlwaysDeny",
        "enabled": true,
        "entityMappings": [
          {
            "entityType": "Host",
            "fieldMappings": [
              {
                "columnName": "HostName",
                "identifier": "HostName"
              }
            ]
          },
          {
            "entityType": "Account",
            "fieldMappings": [
              {
                "columnName": "UserEmail",
                "identifier": "FullName"
              },
              {
                "columnName": "AccountName",
                "identifier": "Name"
              },
              {
                "columnName": "UPNSuffix",
                "identifier": "UPNSuffix"
              }
            ]
          }
        ],
        "OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/SonicWall%20Cloud%20Secure%20Edge/Analytic%20Rules/SonicWallCSEDeviceTrustAlwaysDeny.yaml",
        "query": "let RunWindow = 1h;\nCSEEvents\n| where EventType == \"TrustScoring\" and isnotempty(DeviceSerialNumber)\n| order by DeviceSerialNumber asc, EventTime asc\n| extend PreviousLevel = iff(prev(DeviceSerialNumber) == DeviceSerialNumber, prev(TrustLevel), \"\")\n| where TrustLevel == \"AlwaysDeny\" and PreviousLevel != \"AlwaysDeny\"\n| where IngestedAt > ago(RunWindow)\n| project TimeGenerated, EventTime, Action, DeviceSerialNumber, DeviceName, DevicePlatform, UserEmail,\n    PreviousLevel, TrustLevel, TrustScore, TrustProfileName, FailedFactors, EventId\n| extend\n    AccountName = tostring(split(UserEmail, \"@\")[0]),\n    UPNSuffix = tostring(split(UserEmail, \"@\")[1]),\n    HostName = coalesce(DeviceName, DeviceSerialNumber),\n    FailedFactorList = strcat_array(FailedFactors, \", \")\n",
        "queryFrequency": "PT1H",
        "queryPeriod": "P2D",
        "severity": "Medium",
        "subTechniques": [],
        "suppressionDuration": "PT1H",
        "suppressionEnabled": false,
        "tactics": [
          "DefenseEvasion"
        ],
        "techniques": [
          "T1562"
        ],
        "templateVersion": "1.1.0",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 0
      },
      "type": "Microsoft.OperationalInsights/workspaces/providers/alertRules"
    }
  ]
}
