Skip to content

Azure Defender

Microsoft Defender and Sentinel security incidents and alerts

Connector software
Free and open source
Service credentials
Required
Use with an agent

Install the Orchard skill in your project to help your agent find connectors, configure them, and verify SQL results.

npx skills add Query-farm/vgi-skills --skill orchard

Copy this request into your coding agent to get started.

Use https://query.farm/products/orchard/connectors/azure-defender/index.md to help me query Azure Defender with DuckDB or Haybarn 2.0.1 and VGI protocol 3.4. Ask only for missing details about the result I need or whether I want local execution, self-hosting or Query Farm hosting. Check the connector's actual hosting availability, credentials and input requirements. Read one format of each needed reference and the exact object declarations before writing SQL. Use a released connector, and distinguish a saved example result from anything you actually execute. If you cannot run the query, tell me what remains to verify.

Find open security incidents with high severity

Uses your connected account. Set up the connector and credentials to run it with your data.

SELECT id, display_name, severity, status
FROM azure.main.security_incidents()
WHERE _row_kind = 'incident' AND severity = 'high' AND status = 'active'

Quick start

Choose where to run Azure Defender, then follow the steps below.

The connector runs alongside DuckDB or Haybarn. No Query Farm account is needed.

1. Install the vgi extension

Run this in your SQL client. On DuckDB, keep FROM query_farm on LOAD in later sessions.

setup.sql
SET allow_extension_repositories = 'allowed';

CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
    WITH PREFIX 'https://duckdb-extensions.query.farm';

INSTALL vgi FROM query_farm;
LOAD vgi FROM query_farm;

2. Attach the connector

Attach the release directly

Downloads the latest release for your platform and caches it locally.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/vgi-azure-defender'
);

3. Add service credentials

After attaching, create the secret for the service you want to query in the same SQL session. Replace the placeholders with your service settings.

azure_graph credentials

Microsoft Entra app-only (client-credentials) credentials for Microsoft Graph

Get these credentials →
secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Credential fields and requirements →

4. Run a query

query.sql
SELECT id, display_name, severity, status
FROM azure.main.security_incidents()
WHERE _row_kind = 'incident' AND severity = 'high' AND status = 'active'
More example queries →
Technical details
Verified connector release
v0.5.0
Engine
2.0.1
VGI protocol
3.4.0
Verified on
December 1, 2026
Release notes on GitHub
Pin a version for production

When running the connector yourself, keep a specific release until you’re ready to upgrade. Replace the ATTACH statement above with this one and follow the same extension and credential setup.

Attach the release directly

Uses the verified release each time you attach the connector.

ATTACH 'azure' AS azure (
  TYPE vgi,
  LOCATION 'github-auto://Query-farm/[email protected]'
);

Overview

Microsoft 365 Defender / Sentinel incidents & alerts via Microsoft Graph security API — lastUpdateDateTime watermark cursor (safety-lag, ge boundary, dedup-by-id). vgi-azure-defender

Catalog

Everything azure exposes once attached — read straight from the worker's released build.

azure 1 schema
main 1 view · 2 functions

Microsoft 365 Defender / Sentinel security incidents & alerts as incremental Graph security watermark feeds.

Schema examples (6)
Examples (6)

Cold-start sync of open high-severity incidents

SELECT id, display_name, severity, status
FROM azure.main.security_incidents()
WHERE _row_kind = 'incident' AND severity = 'high' AND status = 'active';

Incremental incident sync from a saved watermark

SELECT id, display_name, status
FROM azure.main.security_incidents(since := '<_watermark_next>')
WHERE _row_kind = 'incident';

Read the watermark cursor to persist for the next scan

SELECT _watermark_next
FROM azure.main.security_incidents()
WHERE _row_kind = 'marker';

Authoritative alert feed, high severity only

SELECT id, title, severity, category
FROM azure.main.security_alerts()
WHERE _row_kind = 'alert' AND severity = 'high';
2 more examples

Active incidents ranked by how many distinct MITRE ATT&CK techniques their alerts carry in the authoritative security_alerts feed (incidents with no technique-tagged alert in the window are omitted)

SELECT i.id, i.display_name, i.severity,
  count(DISTINCT t.technique) AS technique_count,
  list_sort(list(DISTINCT t.technique)) AS techniques
FROM azure.main.security_incidents() AS i
JOIN (SELECT incident_id, unnest(mitre_techniques) AS technique FROM azure.main.security_alerts() WHERE _row_kind = 'alert') AS t ON t.incident_id = i.id
WHERE i._row_kind = 'incident' AND i.status = 'active'
GROUP BY i.id, i.display_name, i.severity
ORDER BY technique_count DESC, i.id;

For incidents whose expanded alert set was capped (_alerts_truncated), list every alert from the authoritative security_alerts feed updated in the same lookback window

SELECT a.incident_id, a.id AS alert_id, a.title, a.severity, a.status
FROM azure.main.security_alerts() AS a
WHERE a._row_kind = 'alert' AND a.incident_id IN (SELECT id FROM azure.main.security_incidents() WHERE _row_kind = 'incident' AND _alerts_truncated)
ORDER BY a.incident_id, a.id;
Views
feeds 1 example5 cols

Credential-free manifest of the security watermark feeds (a browsable discovery entry point).

Columns
feed VARCHAR
The table-function name to call (security_incidents or security_alerts).
source_endpoint VARCHAR
The Microsoft Graph security API path the feed reads.
row_kinds VARCHAR
The `_row_kind` values the feed emits in its row stream.
requires_secret BOOLEAN
Whether scanning the feed needs an app-only azure_graph secret (always true).
description VARCHAR
A one-line summary of what the feed returns.
Example

List the available security feeds and their Graph source endpoint

SELECT feed, source_endpoint, requires_secret
FROM azure.main.feeds
ORDER BY feed;
Link
Table functions
security_alerts (filter := VARCHAR, lookback := VARCHAR, since := VARCHAR) 5 examples

Microsoft 365 Defender / Sentinel alerts (alerts_v2) via Microsoft Graph, cursored by a lastUpdateDateTime watermark (safety-lag, ge boundary, dedup-by-id). REQUIRED source of truth for alert-level completeness — an alert can be re-stamped without bumping its parent incident past the incident watermark, so security_incidents' expanded alerts are a convenience join only, not the authoritative alert feed.

Named arguments
filter := VARCHAR
An optional extra Microsoft Graph OData `$filter`, AND-combined with the `lastUpdateDateTime ge <since>` boundary (e.g. `severity eq 'high'`). Empty (the default) applies no extra filter. · default ""
lookback := VARCHAR
Cold-start window used only when `since` is empty: the scan starts at `now − lookback`. Accepts `30d`, `12h`, `45m`, `30s`, or a bare millisecond count; `0` opts into a full historical backfill. Defaults to `30d`. · default "30d"
since := VARCHAR
A previously persisted `_watermark_next` (ISO-8601) from a prior scan's marker row, replayed as the `lastUpdateDateTime ge` boundary to return only alerts changed since. Empty (the default) performs a bounded cold start at `now − lookback`. · default ""
Returns columns
id VARCHAR
The alert id. NULL on the marker row.
incident_id VARCHAR
Parent incident id, if the alert is correlated (may be NULL for a standalone alert).
title VARCHAR
Alert title.
status VARCHAR
Lifecycle status (e.g. `new`, `inProgress`, `resolved`) — a field, never a tombstone.
severity VARCHAR
Severity (`informational`, `low`, `medium`, `high`).
classification VARCHAR
Triage classification (e.g. `truePositive`, `falsePositive`).
determination VARCHAR
Triage determination (e.g. `malware`, `phishing`).
category VARCHAR
Alert category.
service_source VARCHAR
Alert-producing service, e.g. `microsoftDefenderForEndpoint`.
detection_source VARCHAR
Detection source of the alert.
mitre_techniques VARCHAR[]
MITRE ATT&CK technique ids for the alert.
first_activity_datetime VARCHAR
ISO-8601 first observed activity.
last_activity_datetime VARCHAR
ISO-8601 last observed activity.
created_datetime VARCHAR
ISO-8601 creation time.
last_update_datetime VARCHAR
ISO-8601 last update — the field the watermark is folded from.
_row_kind VARCHAR
`alert`, or `marker` for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the ISO-8601 watermark to persist and replay as the next `since`; NULL on data rows.
Examples (5)

Cold-start sync of all alerts (alert rows only)

SELECT id, title, severity, category
FROM azure.main.security_alerts()
WHERE _row_kind = 'alert';

Incremental sync replaying a previously saved watermark cursor

SELECT id, title, status
FROM azure.main.security_alerts(since := '<_watermark_next>')
WHERE _row_kind = 'alert';

High-severity alerts only

SELECT id, title, severity
FROM azure.main.security_alerts()
WHERE _row_kind = 'alert' AND severity = 'high';
2 more examples

Read the watermark cursor to persist for the next sync

SELECT _watermark_next
FROM azure.main.security_alerts()
WHERE _row_kind = 'marker';

Server-side severity pushdown via the OData filter argument (fetches fewer rows than a client-side WHERE)

SELECT id, title, severity
FROM azure.main.security_alerts(filter := 'severity eq ''high''')
WHERE _row_kind = 'alert';
Link
security_incidents (filter := VARCHAR, lookback := VARCHAR, max_alerts := VARCHAR, since := VARCHAR) 7 examples

Microsoft 365 Defender / Sentinel incidents (with $expand=alerts) via Microsoft Graph, cursored by a lastUpdateDateTime watermark (safety-lag, ge boundary, dedup-by-id). status is a lifecycle field, NOT a tombstone. Incident watermark does NOT guarantee alert freshness — use security_alerts for alert-level completeness.

Named arguments
filter := VARCHAR
An optional extra Microsoft Graph OData `$filter`, AND-combined with the `lastUpdateDateTime ge <since>` boundary (e.g. `severity eq 'high'`). Empty (the default) applies no extra filter. · default ""
lookback := VARCHAR
Cold-start window used only when `since` is empty: the scan starts at `now − lookback`. Accepts `30d`, `12h`, `45m`, `30s`, or a bare millisecond count; `0` opts into a full historical backfill. Defaults to `30d`. · default "30d"
max_alerts := VARCHAR
Cap on the nested `$expand=alerts($top=N)` set fetched per incident. When an incident's real alert count exceeds this cap, its incident row's `_alerts_truncated` is true — fall back to `security_alerts` for the complete alert set. Defaults to `50`. · default "50"
since := VARCHAR
A previously persisted `_watermark_next` (ISO-8601) from a prior scan's marker row, replayed as the `lastUpdateDateTime ge` boundary to return only incidents changed since. Empty (the default) performs a bounded cold start at `now − lookback`. · default ""
Returns columns
id VARCHAR
The incident id (`incident` rows) or alert id (`alert` rows). NULL on the marker row.
incident_id VARCHAR
On an `incident` row, its own id; on an `alert` row, the parent incident id.
display_name VARCHAR
Incident display name (`incident` rows only; NULL otherwise).
title VARCHAR
Alert title (`alert` rows only; NULL otherwise).
status VARCHAR
Lifecycle status (e.g. `active`, `resolved`) — a field, never a tombstone.
severity VARCHAR
Severity (`informational`, `low`, `medium`, `high`).
classification VARCHAR
Triage classification (e.g. `truePositive`, `falsePositive`).
determination VARCHAR
Triage determination (e.g. `malware`, `phishing`).
assigned_to VARCHAR
Analyst the incident is assigned to (`incident` rows only; analyst PII).
tenant_id VARCHAR
Owning tenant id (`incident` rows only).
incident_web_url VARCHAR
Portal deep-link to the incident (`incident` rows only).
alert_count INTEGER
Reported number of alerts on the incident (`incident` rows only).
_alerts_truncated BOOLEAN
True when the incident's real alert count exceeds the fetched cap — fall back to security_alerts (`incident` rows only).
category VARCHAR
Alert category (`alert` rows only).
service_source VARCHAR
Alert-producing service, e.g. `microsoftDefenderForEndpoint` (`alert` rows only).
detection_source VARCHAR
Detection source of the alert (`alert` rows only).
mitre_techniques VARCHAR[]
MITRE ATT&CK technique ids for the alert (`alert` rows only).
first_activity_datetime VARCHAR
ISO-8601 first observed activity (`alert` rows only).
last_activity_datetime VARCHAR
ISO-8601 last observed activity (`alert` rows only).
created_datetime VARCHAR
ISO-8601 creation time.
last_update_datetime VARCHAR
ISO-8601 last update — the field the watermark is folded from.
_row_kind VARCHAR
`incident`, `alert`, or `marker` for the single trailing cursor row.
_watermark_next VARCHAR
On the marker row, the ISO-8601 watermark to persist and replay as the next `since`; NULL on data rows.
Examples (7)

Cold-start sync of all incidents (incident rows only)

SELECT id, display_name, severity, status
FROM azure.main.security_incidents()
WHERE _row_kind = 'incident';

Incremental sync replaying a previously saved watermark cursor

SELECT id, display_name, status
FROM azure.main.security_incidents(since := '<_watermark_next>')
WHERE _row_kind = 'incident';

Active incidents ranked by how many distinct MITRE ATT&CK techniques their alerts carry in the authoritative security_alerts feed (incidents with no technique-tagged alert in the window are omitted)

SELECT i.id, i.display_name, i.severity,
  count(DISTINCT t.technique) AS technique_count,
  list_sort(list(DISTINCT t.technique)) AS techniques
FROM azure.main.security_incidents() AS i
JOIN (SELECT incident_id, unnest(mitre_techniques) AS technique FROM azure.main.security_alerts() WHERE _row_kind = 'alert') AS t ON t.incident_id = i.id
WHERE i._row_kind = 'incident' AND i.status = 'active'
GROUP BY i.id, i.display_name, i.severity
ORDER BY technique_count DESC, i.id;
4 more examples

For incidents whose expanded alert set was capped (_alerts_truncated), list every alert from the authoritative security_alerts feed updated in the same lookback window

SELECT a.incident_id, a.id AS alert_id, a.title, a.severity, a.status
FROM azure.main.security_alerts() AS a
WHERE a._row_kind = 'alert' AND a.incident_id IN (SELECT id FROM azure.main.security_incidents() WHERE _row_kind = 'incident' AND _alerts_truncated)
ORDER BY a.incident_id, a.id;

Read the watermark cursor to persist for the next sync

SELECT _watermark_next
FROM azure.main.security_incidents()
WHERE _row_kind = 'marker';

The alerts correlated to each incident (convenience join; use security_alerts for completeness)

SELECT incident_id, title, severity
FROM azure.main.security_incidents()
WHERE _row_kind = 'alert';

Server-side severity pushdown via the OData filter argument (fetches fewer rows than a client-side WHERE)

SELECT id, display_name, severity
FROM azure.main.security_incidents(filter := 'severity eq ''high''')
WHERE _row_kind = 'incident';
Link

Credentials

The secret type azure declares, as reported by the worker itself.

azure_graph

How to get these credentials

Microsoft Entra app-only (client-credentials) credentials for Microsoft Graph

secret.sql
CREATE SECRET azure_graph (
    TYPE azure_graph,
    tenant_id     '<tenant_id>',
    client_id     '<client_id>',
    client_secret '<AZURE_GRAPH_CLIENT_SECRET>'  -- secret
);
Key Type Required Description
tenant_id VARCHAR — Directory (tenant) ID from the app registration's Overview page in Microsoft Entra ID
client_id VARCHAR — Application (client) ID from the app registration's Overview page
client_secret secret VARCHAR — Client secret value created under the app registration's Certificates & secrets page

The worker doesn't mark which keys are required.

Needed by security_incidentssecurity_alerts

Create the secret in the same session, after attaching azure — the worker registers its secret types at ATTACH. Keys marked secret are masked in duckdb_secrets(); angle-bracket values are placeholders. Read credentials from your environment or secret store in your application and pass them through your SQL client’s parameter bindings. Keep real values out of saved SQL and history. Native DuckDB and Haybarn do not provide a SQL getenv() function.

Try these queries

incidents_bind_probe — Bind security_incidents and expose its result columns (credential-free; drop LIMIT 0 and attach an azure_graph secret to sync real incidents)

SELECT id, incident_id, display_name, status, severity, _row_kind,
  _watermark_next
FROM azure.main.security_incidents()
LIMIT 0;

Uses security_incidents

alerts_bind_probe — Bind security_alerts and expose its result columns (credential-free; attach an azure_graph secret to sync real alerts)

SELECT id, incident_id, title, status, severity, category, _row_kind,
  _watermark_next
FROM azure.main.security_alerts()
LIMIT 0;

Uses security_alerts

list_feeds — List the catalog's security feeds from the credential-free manifest view (runs with no secret)

SELECT feed, source_endpoint, requires_secret
FROM azure.main.feeds
ORDER BY feed;

Uses feeds

Incremental incident sync from a saved watermark

SELECT id, display_name, status
FROM azure.main.security_incidents(since := '<_watermark_next>')
WHERE _row_kind = 'incident'

Uses security_incidents

Read the watermark cursor to persist for the next scan

SELECT _watermark_next
FROM azure.main.security_incidents()
WHERE _row_kind = 'marker'

Uses security_incidents

Authoritative alert feed, high severity only

SELECT id, title, severity, category
FROM azure.main.security_alerts()
WHERE _row_kind = 'alert' AND severity = 'high'

Uses security_alerts

10 more examples in the Catalog, each listed under the table or function it uses.

Questions it can answer

Plain-English questions from the worker's agent test tasks. An AI agent with this catalog attached should answer each one with SQL.

  • List the open high-severity security incidents with their display name and severity.
  • After syncing incidents, how do I get the cursor to use for the next incremental sync?
  • What is the right way to get a complete, up-to-date list of security alerts?
  • What security data feeds does this catalog provide, and which endpoint backs each?
  • For each active high-severity incident, which alert-producing services (service_source) contributed alerts to it according to the complete alert feed?

Azure Defender is an independent open-source connector from Query.Farm. It is not affiliated with, endorsed by or sponsored by the services, projects or organisations it works with. Product names, logos and trademarks belong to their respective owners.