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.

abstract 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)

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:

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.

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.

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

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:

Any

class StatusMonitor(notifier, sim_identifier, recipient_email=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()

__enter__()

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

__exit__(exc_type, exc_val, exc_tb)

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, recipient_email=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()

class StatusMonitorWebex(sim_identifier, recipient_email=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()