alab_management.alarm module#

The module to send alerts to the user via email or slack.

class Alarm(email_receivers=None, email_sender=None, email_password=None, slack_bot_token=None, slack_channel_id=None)[source]#

Bases: object

A class to send alerts to the user via email or slack.

alert(message, category)[source]#

Try to alert user in all platform in format of “Category: Message”.

Parameters:
  • message (str) – The message to print in the platform

  • category (str) – The category of the message.

print_configuration()[source]#

Print the configuration of the alarm.

send_email(message, category)[source]#

Send an email to the receiver email address with the exception and category. Category is the type of exception that occurred. Automatically use “Error” as category if the message contains traceback.

Parameters:
  • message (str) – The message to print in the email

  • category (str) – The category of the message.

send_slack_notification(message, category)[source]#

Send a slack message to the receiver email address with the exception and category. Category is the type of exception that occurred. Automatically use “Error” as category if the message contains traceback.

Parameters:
  • message (str) – The message to print in the email

  • category (str) – The category of the message.

setup_email(email_receivers, email_sender, email_password)[source]#

Try to setup email notification (called in __init__).

Parameters:
  • email_receivers (list) – A list of email addresses to send the alert to.

  • email_sender (str) – The email address to send the alert from.

  • email_password (str) – The password for the email address to send the alert from.

setup_slackbot(slack_bot_token, slack_channel_id)[source]#

Try to setup slackbot notification (called in __init__).

Parameters:
  • slack_bot_token (str) – The token from slackbot app

  • slack_channel_id (str) – The slack channel id where the slackbot app is deployed.

format_message_to_codeblock(message)[source]#

The function takes a message and formats it as a code block. It is used to format tracebacks as code blocks in Slack.

Parameters:

message (str) – The message to format (String). This is usually a traceback.

Return type:

str

Returns ——- formatted_message: The formatted message. This will be formatted into code block in slack if the message contains traceback, otherwise it will be the original message.