eelib.utils.notification

Sends notifications for the status of simulations.

Author: elenia@TUBS
Copyright 2024 elenia
This file is part of eELib, which is free software under the terms of the GNU GPL Version 3.

Module Contents

Classes

Notifier

Abstract parent class for notifier objects.

EmailNotifier

Class for sending notifications through email. Extends Notifier.

WebexNotifier

Class for sending notifications through Webex App. Extends Notifier.

StatusMonitor

Abstract parent class for a group of context manager classes.

StatusMonitorEmail

context manager class used to notify user of a simulation's status through email.

StatusMonitorWebex

context manager class used to notify user of a simulation's status through Webex.

Attributes

_logger

_logger
class Notifier

Bases: abc.ABC

Abstract parent class for notifier objects.

abstractmethod send_message(sim_identifier: str, success: bool, message: str = None, recipient_email: str = None)

Abstract method for sending a message.

Parameters:
  • sim_identifier (str) – an identifier for the simulation.

  • success (bool) – whether or not the simulation was successful.

  • message (str) – An additional message. Defaults to None.

  • recipient_email (str) – the recipient email. Defaults to None.

construct_message(sim_identifier: str, success: bool, message: str = None) tuple[str, str]

Method to construct a message depending on success or failure of a simulation.

Parameters:
  • sim_identifier (str) – an identifier for the simulation.

  • success (bool) – whether or not the simulation was successful.

  • message (str) – An additional message. Defaults to None.

Returns:

the subject and content of the constructed message.

Return type:

tuple[str, str]

class EmailNotifier(smtp_server: str = None, smtp_port: int = None, sender_email: str = None, sender_password: str = None)

Bases: Notifier

Class for sending notifications through email. Extends Notifier.

smtp_server
smtp_port
sender_email
sender_password
send_message(sim_identifier: str, success: bool, message: str = None, recipient_email: str = None)

Sends email as a status update for a simulation.

Parameters:
  • sim_identifier (str) – an identifier for the simulation.

  • success (bool) – whether or not the simulation was successful.

  • message (str) – An additional message. Defaults to None.

  • recipient_email (str) – the recipient email. Defaults to None.

class WebexNotifier(api_url: str = None, access_token: str = None)

Bases: Notifier

Class for sending notifications through Webex App. Extends Notifier.

access_token
url
send_message(sim_identifier: str, success: bool, message: str = None, recipient_email: str = None) list

Sends webex message as a status update for a simulation.

Parameters:
  • sim_identifier (str) – an identifier for the simulation.

  • success (bool) – whether or not the simulation was successful.

  • message (str) – An additional message. Defaults to None.

  • recipient_email (str) – the recipient’s email. Defaults to None.

Returns:

json-encoded content of response or None.

Return type:

list

class StatusMonitor(notifier: Notifier, sim_identifier: str, recipient_email: str = None)

Bases: abc.ABC

Abstract parent class for a group of context manager classes.

Monitors the status of simulation and informs the user about success or failure. Use in the following format:

with StatusMonitor(…):

execute_simulation()

notifier
sim_identifier
recipient_email = 'None'
__enter__()

Called at the beginning of a with statement. Performs setup actions.

__exit__(exc_type: any, exc_val: any, exc_tb: any) bool

Called at the end of a with statement. Performs teardown actions and handles exceptions.

Parameters:
  • exc_type (any) – The type of the exception if any.

  • exc_val (any) – The value of the exception (e.g., the exception instance) if any.

  • exc_tb (any) – A traceback object encapsulating the call stack at the point where the exception occurred.

Returns:

returns False to propogate the exception.

Return type:

bool

class StatusMonitorEmail(sim_identifier: str, recipient_email: str = None, **kwargs)

Bases: StatusMonitor

context manager class used to notify user of a simulation’s status through email.

Extends StatusMonitor. Use in the following format:

with StatusMonitor(…):

execute_simulation()

smtp_server
smtp_port
sender_email
sender_password
email_sender
class StatusMonitorWebex(sim_identifier: str, recipient_email: str = None, **kwargs)

Bases: StatusMonitor

context manager class used to notify user of a simulation’s status through Webex.

Extends StatusMonitor. Use in the following format:

with StatusMonitor(…):

execute_simulation()

api_url
access_token
webex_sender