> For the complete documentation index, see [llms.txt](https://documentation.immuta.com/SaaS/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.immuta.com/SaaS/govern/detect-introduction/index/how-to-guides/monitor-key-events-in-exported-audit-logs.md).

# Monitor Key Events in Exported Audit Logs

Query exported audit logs and set up alerts for high-impact events

Once your [audit logs are exported](https://documentation.immuta.com/SaaS/govern/detect-introduction/index/how-to-guides/enable-uam.md), you can query them to answer governance and compliance questions. This guide walks through three common monitoring scenarios using Snowflake to query logs exported to S3. You can adapt the queries to your analytics platform. To find events for other questions, see [Events for common audit questions](https://documentation.immuta.com/SaaS/govern/detect-introduction/index.md#events-for-common-audit-questions).

## Requirements

* Audit logs exported to [S3](https://documentation.immuta.com/SaaS/govern/detect-introduction/index/how-to-guides/enable-uam.md) or [ADLS Gen2](https://documentation.immuta.com/SaaS/govern/detect-introduction/index/how-to-guides/export-adls.md)
* A Snowflake external stage that points to your audit export location. The examples below use a stage named `@S3_audit_stage` and a JSON file named `json_format`.
* `APPLICATION_ADMIN` Immuta permission to create webhooks for alerts

## Monitor permission changes

Permission changes affect who can grant or enforce access, so track them even when privileged users make them.

**Relevant events**: `PermissionApplied`, `PermissionRemoved`, `DomainPermissionsUpdated`

<details>

<summary>Example SQL</summary>

The following query returns all global and domain permission changes.

```sql
SELECT
    t0.value:eventTimestamp::datetime as eventtimestamp,
    t0.value:type::string as type,
    t0.value:actionStatus::string as actionstatus,
    t0.value:actor.id::string as user,
    case
        when t0.value:type::string = 'DomainPermissionsUpdated'
        then t0.value:relatedResources[0].name::string
        else t0.value:targets[0].name::string
    end as affecteduser,
    case
        when t0.value:type::string = 'DomainPermissionsUpdated'
        then t0.value:targets[0].name::string
        else null
    end as affecteddomain,
    case
        when t0.value:type::string = 'DomainPermissionsUpdated'
        then t0.value:auditPayload.permissionUpdates[0].permissions::variant
        else t0.value:relatedResources[0].name::string
    end as permissions,
    t0.value as json
FROM @S3_audit_stage (file_format => 'json_format', pattern => '.*json'),
    lateral flatten (input => $1) as t0
WHERE type in ('PermissionApplied', 'PermissionRemoved', 'DomainPermissionsUpdated')
order by eventTimestamp desc;
```

</details>

**Optional alert**: [Create a webhook](https://documentation.immuta.com/SaaS/govern/detect-introduction/notifications/how-to-guides/create-a-webhook.md) with the `permissionsUpdated` notification type to send permission changes to an application such as Slack. To alert only on specific changes, such as changes outside business hours or to the `USER_ADMIN` or `GOVERNANCE` permissions, route the webhook through a service like AWS Lambda that filters events before forwarding them.

<details>

<summary>Example webhook payload</summary>

```json
{
  "webhooks": [
    {
      "url": "https://hooks.slack.com/services/T00000/B00000/XXXXXXXXXXXXXXXXX",
      "name": "Updated permissions",
      "global": true,
      "notificationType": ["permissionsUpdated"],
      "actionType": "triggered"
    }
  ]
}
```

</details>

## Monitor policy and metadata changes

Because policies are metadata-driven, access can change when policies, tags, or user attributes change. To understand the impact of a change, find the event and then compare access and query activity before and after it.

**Relevant events**: `GlobalPolicyCreated`, `GlobalPolicyUpdated`, `GlobalPolicyDeleted`, `TagApplied`, `TagRemoved`, `AttributeApplied`, `AttributeRemoved`

<details>

<summary>Example SQL</summary>

The following query returns policy, tag, and attribute events with the changed value.

```sql
SELECT
    t0.value:eventTimestamp::datetime as eventtimestamp,
    t0.value:type::string as type,
    t0.value:actionStatus::string as actionstatus,
    t0.value:actor.id::string as user,
    t0.value:targets[0].name::string as affectedobject,
    coalesce(concat(
                    t0.value:auditPayload.attributes[0].attribute::string
                    , ': '
                    , replace(replace(t0.value:auditPayload.attributes[0].values::string, '[', ''), ']', '')) -- attributes
            , t0.value:auditPayload.appliedTags[0].tags[0].name::string -- applied tags
            , t0.value:auditPayload.removedTags[0].tags[0].name::string -- removed tags
            , t0.value:auditPayload.policy.actions[0].dataPolicyType::string -- data policies
            , t0.value:auditPayload.policy.actions[0].type::string -- subscription policies
            ) as value,
    t0.value as json
FROM @S3_audit_stage (file_format => 'json_format', pattern => '.*json'),
    lateral flatten (input => $1) as t0
WHERE type in ('TagApplied', 'TagRemoved'
                , 'AttributeApplied', 'AttributeRemoved'
                , 'GlobalPolicyCreated', 'GlobalPolicyUpdated', 'GlobalPolicyDeleted')
order by eventTimestamp desc;
```

</details>

**Optional alert**: [Create a webhook](https://documentation.immuta.com/SaaS/govern/detect-introduction/notifications/how-to-guides/create-a-webhook.md) with the `attributeAdded`, `attributeUpdated`, and `attributeRemoved` notification types to be notified when user attributes are changed manually in Immuta.

<details>

<summary>Example webhook payload</summary>

```json
{
  "webhooks": [
    {
      "url": "https://hooks.slack.com/services/T00000/B00000/XXXXXXXXXXXXXXXXX",
      "name": "attributeAlert",
      "global": true,
      "notificationType": ["attributeAdded", "attributeUpdated", "attributeRemoved"],
      "actionType": "triggered"
    }
  ]
}
```

</details>

## Monitor new sensitive data

When new columns are added to a registered data source, Immuta tags them with the `New` tag, and identification applies tags like `PII` or `PCI` when it detects sensitive data. Monitoring these tags lets you review new sensitive columns and confirm the right policies apply before users query them.

**Relevant event**: `TagApplied`

<details>

<summary>Example SQL</summary>

The following query returns tags containing `PII` or `PCI` applied to data sources or columns.

```sql
SELECT
    t0.value:eventTimestamp::datetime as eventtimestamp,
    t0.value:type::string as type,
    t0.value:actionStatus::string as actionstatus,
    t0.value:actor.id::string as user,
    t0.value:targets[0].name::string as affectedobject,
    t0.value:auditPayload.appliedTags[0].tags[0].name::string as appliedtags,
    t0.value as json
FROM @S3_audit_stage (file_format => 'json_format', pattern => '.*json'),
    lateral flatten (input => $1) as t0
WHERE type in ('TagApplied')
    and (appliedtags ilike '%PII%' or appliedtags ilike '%PCI%')
order by eventTimestamp desc;
```

</details>

{% hint style="info" %}
To mask new columns automatically until they are reviewed, activate the [seeded `New Column Added` global policy](https://documentation.immuta.com/SaaS/govern/authoring-policies-in-secure/data-policies/reference-guides/data-policies.md#new-column-added-data-policy).
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://documentation.immuta.com/SaaS/govern/detect-introduction/index/how-to-guides/monitor-key-events-in-exported-audit-logs.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
