Skip to main content

Notifier

Notifier is an application that publishes notifications to a communication system such as Matrix or, in the future, to electronic lab notebooks.

The Notifier does not produce notifications itself, but reads messages that have been published by other components of a data processing pipeline such as connectors and workers to a queue. At the moment, the actions stream of a given Asapo data source is used to store the queue of these messages. We recommend the name misc for this Asapo data source.

graph LR
  dps@{ shape: procs, label: "Data Processing Units"}
  actions_queue(["Queue of actions<br/>(Asapo stream)"])
  notifier[Notifier]
  comm_system["Communication system<br/>(e.g. Matrix)"]
  users@{ shape: procs, label: "Users"}

  actions_queue ~~~ notifier
  dps -- publish actions ---> actions_queue
  notifier -- read ---> actions_queue
  notifier -- publish notifications ---> comm_system
  comm_system -- notifies ---> users

The Notifier expects messages that describe notifications to be stored as Asapo messages metadata of the following format:

{
    "version": "0.1.0",
    "from": "<component_description>",
    "action": {"type": "alert", "message": "<message>"},
}

Getting started

To run the Notifier, you will need a device_id and access_token that correspond to a Matrix account. To create a device_id and access_token for a given account, execute the following commands:

MATRIX_USER_ID=""   # Set the corresponding user ID
MATRIX_PASSWORD=""  # Set the corresponding password

AUTH_RESPONSE="$(curl -X POST "https://matrix.org/_matrix/client/v3/login" \
     -H "Content-Type: application/json" \
     -d '{
       "type": "m.login.password",
       "identifier": {
         "type": "m.id.user",
         "user": "'$MATRIX_USER_ID'"
       },
       "password": "'$MATRIX_PASSWORD'",
       "initial_device_display_name": "bot session"
     }')"
# Result:
# {"access_token":"<token>","device_id":"<device_id>","user_id":"<MATRIX_USER_ID>"}
matrix_device_id="$(jq -r .device_id <<<"$AUTH_RESPONSE")"
matrix_access_token="$(jq -r .access_token <<<"$AUTH_RESPONSE")"
# echo "matrix_device_id='$matrix_device_id' && matrix_access_token='$matrix_access_token'"

To run the Notifier, you also need to install its dependencies:

# Create a virtual environment
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip

# Install dependencies
python3 -m pip install -e .[asapo]

You can now start the Notifier with the following commands:

# The values provided below assume using the Asapo standalone Docker container.
# Edit these values to make the notifier use a different Asapo, beamline, or beamtime.
asapo_endpoint="localhost:8400"
asapo_beamline="test"
asapo_beamtime="asapo_test"
asapo_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e\
yJleHAiOjk1NzE3MTAyMTYsImp0aSI6Ind0ZmlzdGhpcyIsInN\
1YiI6ImJ0X2FzYXBvX3Rlc3QiLCJFeHRyYUNsYWltcyI6eyJBY\
2Nlc3NUeXBlcyI6WyJ3cml0ZSIsIndyaXRlcmF3IiwicmVhZCJ\
dfX0.cz6R_kVf4yh7IJD6bJjDdgTaxPN3txudZx9DE6WaTtk"

# Start the Notifier app:
python3 -m notifier.app \
  --asapo.endpoint "$asapo_endpoint" \
  --beamline "$asapo_beamline" \
  --beamtime "$asapo_beamtime" \
  --asapo.token "$asapo_token" \
  --matrix.device_id "$matrix_device_id" \
  --matrix.access_token "$matrix_access_token" \
  --log_level "debug"

To test that the notifier works correctly, you can publish some notification messages to Asapo:

# The values provided below assume using the Asapo standalone Docker container.
# Edit these values to make the notifier use a different Asapo, beamline, or beamtime.
asapo_endpoint="localhost:8400"
asapo_beamline="test"
asapo_beamtime="asapo_test"
asapo_token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e\
yJleHAiOjk1NzE3MTAyMTYsImp0aSI6Ind0ZmlzdGhpcyIsInN\
1YiI6ImJ0X2FzYXBvX3Rlc3QiLCJFeHRyYUNsYWltcyI6eyJBY\
2Nlc3NUeXBlcyI6WyJ3cml0ZSIsIndyaXRlcmF3IiwicmVhZCJ\
dfX0.cz6R_kVf4yh7IJD6bJjDdgTaxPN3txudZx9DE6WaTtk"

# Publish messages to Asapo:
python3 -m tests.notifier.publish_to_asapo \
  --asapo.endpoint "$asapo_endpoint" \
  --beamline "$asapo_beamline" \
  --beamtime "$asapo_beamtime" \
  --asapo.token "$asapo_token" \
  --messages "tests/notifier/messages.json" \
  --log_level "debug"

As a reminder, if you want to use an Asapo standalone Docker container, execute the following command:

docker run --rm --name asapo --network host \
  gitlab.desy.de:5555/asapo/asapo/asapo-standalone:26.02.0.dev01

Contributing

If you want to contribute, please read CONTRIBUTING.md first.

In addition, you can find more information on the organization of the code in the document doc/architecture.md.

Metadata

Release files for asapo-notifier 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for asapo-notifier 0.1.0
File Size Uploaded Provenance
asapo_notifier-0.1.0.tar.gz 19.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for asapo-notifier 0.1.0
File Interpreter ABI Platform
asapo_notifier-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 30.5 kB

Release files / asapo_notifier-0.1.0.tar.gz

Download URL asapo_notifier-0.1.0.tar.gz
Size 19.2 kB
Tags Source
SHA-256 checksum
How to use checksums
763bdf1276f4b87d34d42b257c191661a2fa7e3c28d04d8c72003881ea349c7c
BLAKE2b-256 checksum
How to use checksums
dc3d0d1ed180b5d94cfcecac29ecf4efc92538f1426b32659587865ec11d2515
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / asapo_notifier-0.1.0-py3-none-any.whl

Download URL asapo_notifier-0.1.0-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c185b67d5d726932eb7bd4f649fc63929b0531e1617a912db7413a48a5011843
BLAKE2b-256 checksum
How to use checksums
118950c15c28c9cacf3c91b4f243774ab59089ea9c6777476c3290451dba3972
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for asapo-notifier 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page