Set up auto notifications¶
Overview
Configure BEC to send automatic notifications for scan and alarm events through a messaging service such as SciLog or Signal.
Prerequisites¶
- You have a running BEC IPython client session.
- The messaging service you want to use is enabled for your deployment or session.
- You know which target scope to use for that service, for example a SciLog logbook or a Signal group scope.
Notification interface and event types¶
Auto notifications are configured per messaging service from the BEC client with:
bec.messaging.<service>.set_auto_notifications(event_type, enabled=True, scopes=...)
Supported event types are:
| Event type | Emitted when |
|---|---|
"new_scan" |
A scan enters the open state, meaning BEC has started the scan. |
"scan_completed" |
A scan finishes with the status closed or user_completed. |
"alarm_warning" |
BEC raises an alarm with warning severity. |
"alarm_minor" |
BEC raises an alarm with minor severity. |
"alarm_major" |
BEC raises an alarm with major severity. |
"scan_interlock" |
The scan interlock is triggered because beamline states do not match, and again when that interlock is cleared. |
Custom event names
You can also use custom event names. BEC supports any event string, as long as something in your deployment publishes notifications with the same event name.
To learn how to publish one of these events from custom BEC code, see Send a Custom Notification Event.
For example, if a custom service or plugin publishes a beamline_ready notification, you can route it like this:
bec.messaging.scilog.set_auto_notifications(
"beamline_ready",
enabled=True,
scopes="default",
)
1. Enable an automatic notification¶
Enable a notification by choosing the service, event, and target scope.
For example, route new scan notifications to SciLog:
bec.messaging.scilog.set_auto_notifications(
"new_scan",
enabled=True,
scopes="default",
)
This stores a routing rule for the new_scan event. When a new scan starts, BEC forwards the notification to the configured SciLog scope.
You can do the same for Signal when your deployment exposes a named Signal scope:
bec.messaging.signal.set_auto_notifications(
"alarm_major",
enabled=True,
scopes="beamline-ops",
)
2. Add more event routes¶
You can enable more than one event for the same service:
bec.messaging.scilog.set_auto_notifications(
"scan_completed",
enabled=True,
scopes="default",
)
bec.messaging.scilog.set_auto_notifications(
"scan_interlock",
enabled=True,
scopes="default",
)
You can also route the same event to more than one service. For example, keep SciLog for the permanent record and send major alarms to Signal as well:
bec.messaging.scilog.set_auto_notifications(
"alarm_major",
enabled=True,
scopes="default",
)
bec.messaging.signal.set_auto_notifications(
"alarm_major",
enabled=True,
scopes="beamline-ops",
)
3. Use the default scope¶
If your messaging service already has a suitable default scope, set it once and omit scopes= afterwards:
bec.messaging.scilog.set_default_scope("default")
bec.messaging.scilog.set_auto_notifications(
"new_scan",
enabled=True,
)
This is useful when most notifications should go to the same logbook or group.
4. Disable an automatic notification¶
Disable a route by setting enabled=False for the same event and scope:
bec.messaging.scilog.set_auto_notifications(
"new_scan",
enabled=False,
scopes="default",
)
If that was the only route for this service and event, BEC removes it from the notification configuration.
Congratulations!
You have configured automatic notifications in BEC. You can now route scan and alarm events to your messaging services without sending each message manually.
Common pitfalls¶
set_auto_notifications(...)raises an error if the messaging service is not enabled for the current deployment or session.- Use the supported event strings exactly as shown above.
- For services with configured scopes such as SciLog, the scope must exist before you enable auto notifications.
- Signal auto notifications are typically routed to a configured Signal scope such as a group, not to an arbitrary phone number.