dmf.alerts.send_alert#

dmf.alerts.send_alert(text: str | None = None, attachment: str | Path | None = None, params: dict | None = None, level: Literal['success', 'info', 'warning', 'error'] = 'info') None[source]#

Sends a message formatted as an alert with the specified text and alert level.

The function sends a notification with a message that is styled according to the provided level (e.g., “success”, “info”, “warning”, “error”). The message can include additional parameters that are appended to the text to provide more context. The alert message is sent using the appropriate backend.

Parameters:
  • text – Optional; The message text to send. If not provided, the level will be used as the default message text.

  • attachment – Optional; Path to the file to attach. If provided, the file located at this path will be sent as an attachment with the message. The path can be specified as a string or a Path object.

  • params – Optional; Dictionary of key-value pairs to include in the alert message. These parameters will be appended to the message text to provide additional details. For example, {“Duration”: “5 minutes”, “Status”: “Completed”} would result in the text “Duration: 5 minutes, Status: Completed” being added to the alert message.

  • level – Optional; The level of the alert message, which determines the format and emphasis of the message. Supported levels are “success”, “info”, “warning”, and “error”. The default is “info”.

Examples:

Sending a simple info alert:

send_alert(text="The process has completed successfully.")

Sending a warning alert with parameters added to the text:

send_alert(text="Process took longer than expected.", params={"Duration": "10 minutes"}, level="warning")

Sending an error alert with an attachment:

send_alert(text="An error occurred. See the attached log file.", attachmenlogging.warning("No alert backend is available. Message not sent.")t="/path/to/log.txt", level="error")