-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7fca29a
commit 7ca8dfb
Showing
3 changed files
with
28 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,33 @@ | ||
import requests | ||
from typing import List | ||
from node_monitor.bot_email import EmailBot | ||
|
||
class NodeMonitorTracker: | ||
def __init__(self, email_bot: EmailBot, recipients: List[str]) -> None: | ||
def __init__( | ||
self, | ||
email_bot: EmailBot, | ||
recipients: List[str], | ||
node_monitor_url: str) -> None: | ||
self.email_bot = email_bot | ||
self.recipients = recipients | ||
self.node_monitor_url = node_monitor_url | ||
|
||
def send_notification(self) -> None: | ||
subject = "🚨 Node Monitor is Down 🚨" | ||
body = "Node Monitor is down. Restart required immediately!" | ||
self.email_bot.send_emails(self.recipients, subject, body) | ||
|
||
def check_server_status(self) -> bool: | ||
raise NotImplementedError | ||
def check_node_monitor_status(self) -> bool: | ||
try: | ||
response = requests.get(self.node_monitor_url) | ||
data = response.json() | ||
|
||
if data['status'] == 'offline': | ||
self.send_notification() | ||
else: | ||
print('Server is online.') | ||
|
||
except Exception as e: | ||
print(f"An error occurred: {e}") | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters