DataHub

Rules, Alarms, and Actions

How DataHub detects conditions, raises alarms, and delivers automated responses.

DataHub evaluates rules against incoming telemetry in real time. When a condition is met, the platform creates an alarm and executes configured actions.

Rule evaluation

The rule-worker maintains an in-memory cache of active rules keyed by tag path. For each telemetry event:

  1. Match rules bound to the event's tagPath
  2. Evaluate the detector for that rule type
  3. Track state in RuleState (one row per rule): NORMAL, PENDING, or TRIGGERED
  4. Create an alarm when the condition fires
  5. Enqueue action jobs to BullMQ

Rule changes propagate via datahub.rule.changed — no worker restart required.

Detector types

DataHub ships six rule detectors. Each rule has a ruleType and optional params object.

TypePurposeKey params
THRESHOLDClassic high/low trip on live valueExpression (e.g. value > 80); optional recover expression for hysteresis
ANOMALY_ZSCOREStatistical outlier vs rolling windowwindowSec, zThreshold (default 3), minSamples
RATE_OF_CHANGESpike/drop within a windowwindowSec, maxDelta
FLATLINEStuck / dead sensor signalwindowSec, epsilon
GOLDEN_PROFILECompare to known-good envelope (p05–p95)marginPct; requires a baseline record
RULRemaining useful life trendwindowSec, limit, horizonSec

Windowed detectors (anomaly, rate, flatline, RUL) hold a rolling sample buffer in the rule-worker RAM — use reasonable windowSec values on high-frequency tags.

Golden profile and baselines

GOLDEN_PROFILE rules compare live telemetry to a baseline envelope recorded under Baselines (/baselines). Baselines store percentile bands (p05–p95) per tag over a historical window — not manual maintenance measurements.

Rule state

StateMeaning
NORMALCondition not met
PENDINGCondition met but not yet sustained (duration / arming)
TRIGGEREDAlarm active

The seeded demo rule MOTOR_HIGH_CURRENT uses THRESHOLD: motor.current > 20 for 5 seconds.

Alarms

When a rule fires, DataHub creates an alarm record with:

  • Rule reference and tag path
  • Trigger value and timestamp
  • Status (active, acknowledged, cleared)

Operators view and acknowledge alarms in Alarms (/alarms). Acknowledging requires the alarms.acknowledge permission.

Actions

Each rule can have one or more actions executed when the alarm fires:

ChannelConfiguration
SlackIncoming webhook URL
EmailSMTP settings in environment
TelegramBot token and chat ID
HTTPPOST URL with JSON payload

Unconfigured channels are skipped gracefully — they do not fail the action job.

The action-worker retries failed deliveries up to 3 times with exponential backoff.