"""Slack CLI Uptime commands."""
from pi_portal.modules.system import linux, supervisor
from .bases.command import SlackCommandBase
from .process_uptime_commands.cron_videos_uptime import CronVideosUptimeCommand
from .process_uptime_commands.door_monitor_uptime import (
DoorMonitorUptimeCommand,
)
from .process_uptime_commands.slack_bot_uptime import BotUptimeCommand
from .process_uptime_commands.temp_monitor_uptime import (
TempMonitorUptimeCommand,
)
[docs]class UptimeCommand(SlackCommandBase):
"""Slack CLI command to report the uptime of the system components.
:param bot: The configured slack bot in use.
"""
[docs] def invoke(self) -> None:
"""Report the uptime of the system and Pi Portal processes."""
bot_uptime_command = BotUptimeCommand(self.slack_bot)
cron_video_command = CronVideosUptimeCommand(self.slack_bot)
door_monitor_uptime_command = DoorMonitorUptimeCommand(self.slack_bot)
temp_monitor_uptime_command = TempMonitorUptimeCommand(self.slack_bot)
try:
bot_uptime_command.invoke()
cron_video_command.invoke()
door_monitor_uptime_command.invoke()
temp_monitor_uptime_command.invoke()
except supervisor.SupervisorException:
pass
else:
linux_uptime = linux.uptime()
self.slack_bot.slack_client.send_message(
f"System Uptime > {linux_uptime}\n"
f"Bot Uptime > {bot_uptime_command.result}\n"
f"Cron (Video Archival) Uptime > {cron_video_command.result}\n"
f"Door Monitor Uptime > {door_monitor_uptime_command.result}\n"
f"Temperature Monitor Uptime > {temp_monitor_uptime_command.result}"
)