Alerts

Alerts notify users when events matching specific criteria are created or updated in EarthRanger. Users configure Alert Rules that define which event types, conditions, and notification methods trigger an alert.

Overview

The alert pipeline follows this flow:

  1. An Event is created or updated.

  2. A post-save signal queues a Celery task to evaluate the event against active alert rules.

  3. Each Alert Rule whose event type and schedule match is evaluated.

  4. If the event satisfies the rule’s conditions (or the rule is unconditional), notifications are dispatched.

  5. Each Notification Method (email, SMS, or WhatsApp) on the rule receives the alert.

Alert Rules

An alert rule defines:

Field

Description

Title

A human-readable name for the rule.

Event Types

One or more event types the rule applies to.

Conditions

Optional filter criteria (e.g., priority = Red, title contains “poaching”). When no conditions are set the rule fires on every matching event.

Triggers

List of field names whose creation or change causes the rule to fire. The sentinel __event_creation__ triggers on initial event creation; any other entry triggers when that field changes on an update. A rule with an empty trigger list never fires.

Schedule

A weekly schedule with timezone controlling when the rule is active. If the event occurs outside the schedule window, the alert is suppressed.

Notification Methods

One or more destinations (email addresses, phone numbers) that receive the alert.

Override Message

Optional custom message body that replaces the default alert template for email and SMS.

Order Number

Controls evaluation precedence when multiple rules match.

Is Active

Toggle to enable or disable the rule without deleting it.

Alert rules are scoped to an owner (the user who created the rule). Only events visible to that owner are evaluated.

Conditions

Conditions use a business-rules engine to filter events by their fields. A condition set is a JSON structure with either:

  • "all" — every condition must be true (AND logic).

  • "anyOf" — at least one condition must be true (OR logic).

Each condition specifies a variable (event field), an operator, and a value.

Available Operators by Field Type

Field Type

Operator

Display Label

Numeric

equal_to

=

Numeric

greater_than

>

Numeric

less_than

<

Numeric

greater_than_or_equal_to

≥

Numeric

less_than_or_equal_to

≤

Select (multiple)

shares_at_least_one_element_with

Is One Of

Select (multiple)

shares_no_elements_with

Is Not One Of

String

contains

Includes

String

non_empty

Is Not Empty

Built-in Variables

Every alert rule can filter on these core event fields:

  • Title (string) — the event title.

  • Priority (select) — Red, Amber, or Green.

  • State (select) — new, active, resolved, or review.

  • Subject Group (select) — groups associated with the event’s related subjects.

Additional variables are dynamically generated from the event type’s schema (e.g., custom fields defined in event type properties).

Unconditional Rules

When an alert rule has no conditions, it fires for every event of the configured event types that occurs within the rule’s schedule.

Triggering on Create vs. Update

The Triggers list acts as a gate that is applied after the rule’s conditions are evaluated. get_matching_alert_rules first filters to the rules whose schedule and conditions match the event; only those rules then have their trigger list checked:

  • On event creation, the rule fires only if it matches (conditions and schedule) and __event_creation__ is in the trigger list.

  • On event update, the rule fires only if both gates pass: (a) the rule’s conditions still match the event, and (b) at least one changed event field (or event-details field) is named in the trigger list.

  • A rule with no triggers never fires, even if its conditions match.

Field triggers name the event field (state, priority, location, …) or the raw event-details schema key (sex, not the condition variable sex_string); the conditions API exposes the raw key as each variable’s related_data_field.name. Removing a details field counts as a change to it. related_subjects cannot be a trigger: the relation is not written into event revisions, so no change to it is ever observed. The API and Django admin reject a trigger that names none of these.

The location trigger observes the event’s point location only. Polygon geometries live on a separate model (EventGeometry) whose edits do not dispatch alert evaluation at all (a pre-existing platform limitation), so a geometry edit is never seen as a location change — the Geographic Feature conditions evaluate polygon geometry, but only when some event field also changes.

Upgrade note (ERA-13133). Rules that existed before triggers were introduced are backfilled to ["__event_creation__"]. Previously an unconditional rule fired on every save and a conditional rule fired when a condition field changed; after the upgrade they fire on creation only until the owner adds field triggers. This needs a customer-facing release note.

This avoids duplicate notifications when an event is edited in ways the rule does not care about.

Notification Methods

A notification method defines how and where an alert is delivered.

Method

Value

Notes

Email

Email address

Sends an HTML alert with event details and a link to the event.

SMS

Phone number (E.164)

Sends a text message with a condensed alert summary.

WhatsApp

Phone number (E.164)

Sends a structured WhatsApp message via template.

Each notification method is owned by a user and can be shared across multiple alert rules.

Alert Content

Alerts include the following information:

  • Event title and serial number (Report ID).

  • Priority with color indicator (Red, Amber, Green).

  • State (New, Active, Resolved, or Review) with inferred state logic.

  • Event time and alert time.

  • Location — longitude and latitude with a deep link to the map view (if the event has a location).

  • Reported by — the user or entity that created the event.

  • Event details — custom schema fields with display-friendly titles and values.

  • Changed fields — when an event is updated, the alert highlights which fields changed and their previous values.

  • Notes — any notes attached to the event, with an indicator for recently updated notes.

  • Alert rule name and site name/URL.

When an alert rule has an override message, that message replaces the default template body for email and SMS alerts.

Rate Limiting

To prevent alert fatigue and protect notification channels, EarthRanger enforces rate limits on alerts.

  • The alert rate limit is a site-wide tenant setting — it cannot be configured per user. Every user on the site shares the same limit threshold.

  • However, each user’s usage is tracked individually. Each user has their own counter within a rolling time window (configured via ALERTS_RATE_LIMIT_DURATION_SECONDS).

  • When an individual user’s counter reaches the site-wide limit, further alerts to that user are suppressed until their window resets. Other users on the same site are unaffected.

  • When a user is approaching their limit (within ALERTS_REMAINING_COUNTER_FOR_WARNING alerts), a warning is prepended to the alert title showing how many alerts remain.

  • Alert usage metrics are published for monitoring: gauges track users at 90% and 100% of their quota.

Schedules

Alert rules support a weekly schedule that controls when alerts are active. The schedule is defined as a JSON object conforming to the OneWeekSchedule schema and includes a timezone. Events that occur outside the scheduled windows do not trigger alerts for that rule.

Permissions and Location Visibility

Two Users, Two Roles

Alert permissions involve two distinct users whose roles are easy to confuse:

User

Role in the Pipeline

Alert rule owner

Determines which event types and conditions trigger the alert. The rule is only evaluated if the owner’s account is active.

Notification method owner

Determines whether the event can actually be rendered and sent. The event is permission-checked against this user’s access, not the alert rule owner’s.

These are often the same person, but they do not have to be. A notification method can be shared across multiple alert rules owned by different users.

How Permissions Are Applied

The pipeline applies permissions at two stages:

1. Rule evaluation (superuser context): When an event is created or updated, the system evaluates it against all matching alert rules using a synthetic superuser. This deliberately ignores per-user restrictions so that rules are evaluated uniformly. The code comment notes: “I will leave it up to the logic that sends alerts to determine whether an individual user has read access.”

2. Alert rendering (notification method owner context): When the alert is actually sent, the event is re-rendered using the notification method owner as the permission context. The following checks apply:

  • Event category permission — the notification method owner must have read access to the event’s category (e.g., security_read, monitoring_read).

  • Subject group membership — if the event has related subjects, those subjects must belong to subject groups the notification method owner has permission to view.

If either check fails, the alert is silently skipped for that notification method — no error is raised and no notification is sent.

Practical Implications

Because permissions are checked against the notification method owner:

  • An alert rule owner can configure a rule that matches events they themselves can see, but if the notification method belongs to a user without the right event category or subject group permissions, that notification will never fire.

  • Conversely, if a notification method owner has broader permissions than the alert rule owner, alerts will be sent based on the notification method owner’s access.

  • When troubleshooting “why didn’t my alert fire?”, check the permissions of both the alert rule owner (is their account active?) and the notification method owner (can they see this event category and its related subjects?).

Location in Alerts

Important: When an alert is sent, the event’s location is included directly from the event record. The alert pipeline does not apply subject-level location permissions (such as view_last_position or view_real_time) when rendering event data for alerts.

This means that if the notification method owner:

  • Passes the event category permission check, and

  • Has access to the related subject groups,

they will receive the event’s location in the alert, even if they would not normally have permission to view that subject’s real-time location through the observations API.

The location included in the alert is the event location (where the event was reported), not the subject’s current tracking position. However, for events generated from real-time tracking data (e.g., geofence breaks, immobility alerts), the event location typically reflects the subject’s position at the time the event was created.

Pipeline Architecture

The alert system uses Celery for asynchronous processing:

Event saved
  → post_save signal (activity/signals.py)
    → evaluate_alert_rules task (activity/tasks.py)
      → get_matching_alert_rules (activity/alerting/service.py)
        → schedule filter + business rules evaluation (activity/alerting/businessrules.py)
      → evaluate_conditions_for_sending_alerts (activity/tasks.py)   # checks triggers
        → send_notifications (activity/tasks.py)                     # rate-limit check per recipient
          → send_alert_to_notificationmethod task (activity/tasks.py)
            → send_event_alert (activity/alerting/message.py)

get_matching_alert_rules returns the rules whose schedule and conditions match the event (rendered as a superuser). The orchestrating task then applies each matched rule’s trigger list before queuing notifications. Each send_alert_to_notificationmethod task is dispatched as a separate Celery task, allowing independent rate limiting and retry behavior per notification method.