Skip to content

Commit

Permalink
Alarm configuration is printed during setup rather than every initial…
Browse files Browse the repository at this point in the history
…ization
  • Loading branch information
bernardusrendy committed Aug 7, 2024
1 parent c5b5688 commit 9f50700
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
49 changes: 24 additions & 25 deletions alab_management/alarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,25 @@ def __init__(
slack_channel_id: The slack channel id to send the alert to.
"""
self.sim_mode_flag = AlabOSConfig().is_sim_mode()
self.email_alert = False
self.slack_alert = False
self.email_receivers = email_receivers
self.email_sender = email_sender
self.email_password = email_password
self.slack_bot_token = slack_bot_token
self.slack_channel_id = slack_channel_id

if (
email_receivers is not None
and self.sim_mode_flag is False
and email_sender is not None
and email_password is not None
self.email_receivers is not None
and self.email_sender is not None
and self.email_password is not None
):
self.setup_email(email_sender, email_receivers, email_password)
else:
self.email_alert = False
print(
"Email alert is not set up due to either missing "
"email_receivers, email_sender or email_password. "
"It is also possible that the system is in simulation mode. "
"Please recheck the config file if this is not expected."
)
self.setup_email(self.email_receivers, self.email_sender, self.email_password)
if (
slack_bot_token is not None
and self.sim_mode_flag is False
and slack_channel_id is not None
self.slack_bot_token is not None
and self.slack_channel_id is not None
):
self.setup_slackbot(slack_bot_token, slack_channel_id)
else:
self.slack_alert = False
print(
"Slack alert is not set up due to either missing"
"slack_bot_token or slack_channel_id. "
"It is also possible that the system is in simulation mode. "
"Please recheck the config file if this is not expected."
)
self.setup_slackbot(self.slack_bot_token, self.slack_channel_id)
self.platforms = {"email": self.email_alert, "slack": self.slack_alert}

def setup_email(
Expand Down Expand Up @@ -212,3 +202,12 @@ def send_slack_notification(self, message: str, category: str):
client.chat_postMessage(
channel=self.slack_channel_id, text=category + ": " + message
)

def print_configuration(self):
"""Print the configuration of the alarm."""
print("Alarm Configuration:")
print("Platforms: ", self.platforms)
print("Email Receivers: ", self.email_receivers)
print("Email Sender: ", self.email_sender)
print("Slack Channel ID: ", self.slack_channel_id)
print("Sim Mode Flag: ", str(self.sim_mode_flag) + ". Will not send alerts in sim mode." if self.sim_mode_flag else "")
7 changes: 7 additions & 0 deletions alab_management/scripts/setup_lab.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
"""


from alab_management.alarm import Alarm
from alab_management.config import AlabOSConfig


def setup_lab():
"""Cleanup the db and then import all the definitions and set up the db."""
from alab_management.device_view import DeviceView, get_all_devices
Expand Down Expand Up @@ -32,4 +36,7 @@ def setup_lab():
sample_positions=device.sample_positions, parent_device_name=device.name
)

# print the alarm configuration
alarm_config = AlabOSConfig().get("alarm", {})
Alarm(**alarm_config).print_configuration()
return True

0 comments on commit 9f50700

Please sign in to comment.