Alerts
This page is for the practitioner who wants alert-specific workflows on top of the bound document
layer. All snippets below assume svi is an authenticated SVIClient.
Before this example
Alert values vary across VI deployments. Before you adapt a snippet, use Discover your environment to find:
- a real alert id or discoverable alert list
- a real domain id for
"<your-domain-id>" - a real scenario id for
"<your-scenario-id>" - the real resolution and reason codes for your environment
Fetch and update an alert
Alerts are specialized documents with alert-specific operations:
listed_alerts = svi.alerts.list(limit=1)
if listed_alerts:
alert = svi.alerts.get(alert_id=listed_alerts[0].alert_id)
if alert is not None:
alert.update_fields(**{"<your-alert-field>": "<your-updated-value>"})
alert.perform_action(action_type="CHECKOUT")
action_type is one of the four codes the Alerts API publishes: ASSIGNMENT,
CHECKIN, CHECKOUT and REACTIVATE. Any other code raises AlertOperationError
before a request is sent.
All of the bound document managers from the Documents guide are also available
on Alert, because Alert extends Document.
Disposition an alert
A disposition closes the triage of an alert with a resolution. List what applies to the alert, then apply one by id (or by resolution code):
if alert is not None:
options = alert.disposition_options()
print([(option.id, option.name) for option in options])
result = alert.disposition(disposition_id=options[0].id, note="Reviewed")
print(result.success, alert.alert_status_id)
Some dispositions prompt for more than an id: a note, a reason code, the fields
of a document the disposition creates, or a result per scenario-fired event.
When one is missing the SDK raises DispositionPromptRequiredError with the missing
names in exc.missing and sends nothing; the
disposition-with-prompts recipe shows the
collect-and-retry loop. A disposition the service refuses for the alert's state,
or because the alert changed since it was read, raises AlertConflictError
(see Troubleshooting).
Alerts inherit the document layer
In practice, this means an alert is not a separate object model with a completely different surface. You still get the same bound document helpers for the common follow-on workflows:
alert.commentsfor analyst notesalert.attachmentsandalert.imagesfor file accessalert.insightsandalert.workspacesfor investigation viewsalert.relationshipsandalert.historyfor relationship and audit flowsalert.childrenwhen the alert type owns child collections
Use the alert-specific methods when you need alert actions, dispositions, or scenario-fired events. Use the inherited document methods when you need the shared object-management layer.
if alert is not None:
alert.comments.create(text="Investigated by analyst")
workspace = alert.workspaces.create(name="Alert Review Workspace")
print(workspace.id)
Scenario-fired events
Use this bound manager when your alert workflow continues into scenario review.
List and fetch one event
listed_alerts = svi.alerts.list(limit=1)
if listed_alerts:
alert = svi.alerts.get(alert_id=listed_alerts[0].alert_id)
if alert is not None:
events = alert.scenario_fired_events.list(limit=5)
event = (
alert.scenario_fired_events.get(scenario_fired_event_id=events[0].id)
if events
else None
)
print(event)
Get contributing objects
This helper hydrates related records back into bound Document objects:
if alert is not None:
events = alert.scenario_fired_events.list(limit=1)
if events:
contributors = events[0].get_contributing_objects(limit=10)
print([item.document_id for item in contributors])
Rate productivity
if alert is not None:
events = alert.scenario_fired_events.list(limit=1)
if events:
events[0].rate_productivity(
resolution_code="<your-resolution-code>",
reason_code="<your-reason-code>",
comment="Confirmed by analyst review",
)
Audit history
An alert has two trails. alert.history is the Data Hub document trail of the alerts record
(field versions, the same manager every document has). alert.audit is the trail the Alerts
service keeps: check-outs, assignments, dispositions, scenario ratings. Use alert.audit when the
question is "what did analysts do with this alert".
if alert is not None:
for action in alert.audit.actions(limit=10):
print(action.created_at, action.created_by, action.action_type, action.action)
for block in action.details:
print(" ", block.title, block.headings)
for row in block.rows:
print(" ", row)
# Restrict to one action type; the codes come from action_types().
codes = [item.name for item in alert.audit.action_types()]
checkouts = alert.audit.actions(action_type="CHECKOUT") if "CHECKOUT" in codes else []
# Page through everything, or fetch one action by its surrogate key.
everything = alert.audit.actions_all(batch_size=50)
if everything and everything[0].action_sk is not None:
detailed = alert.audit.action(action_sk=everything[0].action_sk)
actions() returns AlertHistoryAction records; each carries AlertHistoryActionDetail blocks
with the headings and rows the Alerts service renders in its history panel. action() returns
None when no action has that key. Every method has an _async twin.
Versions
alert.audit.versions() lists the alert versions the Alerts service keeps, one
AlertVersionSummary per version with the status, disposition, resolution code and score at that
point. This is the alert-level counterpart of alert.history.versions(), which reports the Data
Hub document versions.
if alert is not None:
for version in alert.audit.versions():
print(version.version, version.status_id, version.resolution_code, version.score)
Scorecard and scores
A scorecard explains a score: its range and description, and for each entity the scenario-fired
events that contributed. Alert.scorecard() explains the alert's current score;
AlertingEvent.scorecard() explains one alerting event. The scenario-fired events in the card are
bound ScenarioFiredEvent objects, so the usual follow-ups (details(),
get_contributing_objects(), rate_productivity()) work on them directly.
if alert is not None:
card = alert.scorecard()
print(card.score, card.range_low, card.range_high, card.description)
for block in card.entity_scenarios:
print(block.entity_type, block.entity_label)
for event in block.scenarios:
print(" ", event.scenario_name, event.score)
current = alert.current_alerting_event()
if current is not None:
for score in current.scores():
print(score.score, score.calculated, score.scenario_fired_event_ids)
scores() returns AlertingScore records naming the scenario-fired events that counted and the
ones the service suppressed.
Scenario-fired event details and replicated objects
The alert-scoped ScenarioFiredEvent snapshot carries what the alert needs. details() fetches the
full record from the by-id endpoint as a separate, read-only ScenarioFiredEventDetail: scenario
description and origin, score statistics, the message template and its values, the context
window, replication settings and contributing_object_refs. get_replicated_objects() binds the
objects the scenario replicated into the alert to Documents, the way
get_contributing_objects() does for contributors.
if alert is not None:
events = alert.scenario_fired_events.list(limit=1)
if events:
detail = events[0].details()
print(detail.scenario_description, detail.message_template_text, detail.message_values)
print([ref.to_dict() for ref in detail.contributing_object_refs])
replicated = events[0].get_replicated_objects(limit=10)
print([item.document_id for item in replicated])
The raw replicated-objects operation defaults to 10000 items; the SDK defaults limit to 50.
List alerting events
svi.alerts.events reads alerting events across alerts. Typed filters combine with a raw
filter_ expression; list_all() pages until the service is exhausted; get() fetches one event
by id and returns None when it does not exist.
events = svi.alerts.events.list(domain_id="<your-domain-id>", min_score=50, limit=10)
for event in events:
print(event.id, event.alert_id, event.score, [sfe.id for sfe in event.scenario_fired_events])
if alert is not None and alert.current_alerting_event_id is not None:
current = svi.alerts.events.get(event_id=alert.current_alerting_event_id)
for_alert = svi.alerts.events.list_all(alert_id=alert.document_id, batch_size=50)
Create an alert from an existing entity
Use AlertsService.create() when you need a new alert tied to a document:
from sasvi.alerts import ScenarioFiredEventInput
entity = svi.documents.get(
entity_type_name="<your-entity-type>",
document_id="<your-document-id>",
)
if entity is not None:
created_event = svi.alerts.create(
domain_id="<your-domain-id>",
actionable_entity=entity,
scenario_fired_events=[
ScenarioFiredEventInput(
scenario_id="<your-scenario-id>",
score=75,
message="Triggered by screening rule",
contributing_objects=[entity],
)
],
)
alert = created_event.alert()
print(created_event.id, alert.document_id if alert is not None else None)
create() returns the created alerting event immediately. Use created_event.alert(wait=False) for
a single non-blocking lookup, or created_event.alert() to wait for the final alert to
materialize.
One active alert per entity and domain
An entity has at most one active alert in each domain. If you call create() for an entity
that already has an active alert in domain_id, the service does not open a second alert. It
updates the existing one: the new alerting event becomes current, the scorecard shows the new
event's scenarios and score, and the alert id stays the same. created_event.alert() then
returns that existing alert.
This has two consequences:
- To rescore an open alert, send a new event for the same entity and domain.
- To get several separate alerts, for test data or a demo backlog, give each one its own actionable entity.
Give the domain a disposition first
An alert is closed by dispositioning it, and a domain with no dispositions offers nothing to apply. Alerts created in such a domain stay active, and you cannot clean them up through Disposition an alert. Add at least one closing disposition to the domain before you create alerts in it.
Use the async variant when alert creation is part of a larger async ingestion flow:
from sasvi.alerts import ScenarioFiredEventInput
async def create_alert_for_entity(svi, entity):
created_event = await svi.alerts.create_async(
domain_id="<your-domain-id>",
actionable_entity=entity,
scenario_fired_events=[
ScenarioFiredEventInput(
scenario_id="<your-scenario-id>",
score=75,
message="Triggered by screening rule",
contributing_objects=[entity],
)
],
)
return created_event, await created_event.alert_async(wait=False)
Go further
- Need the shared bound object layer: Documents guide
- Need real domains, scenarios, and codes first: Discover your environment
- Richer end-to-end examples: Notebook examples
- Exact methods: Alerts API reference
- Design model: Client model