feat: Improve daily recap functionality

- Changed the daily recap time to 22:00.
- Modified the `send_daily_recap` function to split the recap message into multiple messages if it exceeds 2000 characters to avoid hitting the Discord message length limit.
- Added a 1-second delay between each message chunk to avoid rate limiting.
This commit is contained in:
2025-09-15 13:27:40 -05:00
parent e559e16e35
commit e64b880c97
4 changed files with 21 additions and 12 deletions

View File

@@ -9,7 +9,7 @@ HOME_ASSISTANT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjOGRmZjI
GOOGLE_HOME_SPEAKER_ID = "media_player.spencer_room_speaker" GOOGLE_HOME_SPEAKER_ID = "media_player.spencer_room_speaker"
# Daily Recap Time (in 24-hour format, e.g., "20:00") # Daily Recap Time (in 24-hour format, e.g., "20:00")
DAILY_RECAP_TIME = "18:28" DAILY_RECAP_TIME = "22:00"
# Nmap Configuration # Nmap Configuration
NMAP_TARGETS = "192.168.2.0/24" NMAP_TARGETS = "192.168.2.0/24"

View File

@@ -455,18 +455,26 @@ def send_daily_recap():
"""Sends a daily recap of events to Discord.""" """Sends a daily recap of events to Discord."""
global daily_events global daily_events
if daily_events: if daily_events:
recap_message = "\n".join(daily_events) recap_message = "**Daily Recap:**\n" + "\n".join(daily_events)
webhook = DiscordWebhook(url=config.DISCORD_WEBHOOK_URL, content=f"**Daily Recap:**\n{recap_message}")
try: # Split the message into chunks of 2000 characters
response = webhook.execute() message_chunks = [recap_message[i:i+2000] for i in range(0, len(recap_message), 2000)]
if response.status_code == 200:
logger.info("Daily recap sent successfully.") for chunk in message_chunks:
else: webhook = DiscordWebhook(url=config.DISCORD_WEBHOOK_URL, content=chunk)
logger.error(f"Error sending daily recap: {response.status_code} - {response.content}") try:
except Exception as e: response = webhook.execute()
logger.error(f"Error sending daily recap: {e}") if response.status_code == 200:
logger.info("Daily recap chunk sent successfully.")
else:
logger.error(f"Error sending daily recap chunk: {response.status_code} - {response.content}")
except Exception as e:
logger.error(f"Error sending daily recap chunk: {e}")
time.sleep(1) # Wait 1 second between chunks to avoid rate limiting
daily_events = [] # Reset for the next day daily_events = [] # Reset for the next day
def run_monitoring_cycle(nmap_scan_counter): def run_monitoring_cycle(nmap_scan_counter):
"""Runs a single monitoring cycle.""" """Runs a single monitoring cycle."""

View File

@@ -476,3 +476,4 @@
2025-09-15 13:22:04,084 - INFO - LLM Response: {'severity': 'high', 'reason': 'High number of blocked connections detected from multiple IP addresses: 23.28.198.165 (1477), 84.252.134.217 (33), 51.250.10.6 (140), 158.160.20.113 (48), 182.93.50.90 (13), 172.22.0.2 (82), 192.168.2.117 (591), 172.23.0.2 (12), and 192.168.2.104 (11). This indicates a potential coordinated attack or misconfigured system.'} 2025-09-15 13:22:04,084 - INFO - LLM Response: {'severity': 'high', 'reason': 'High number of blocked connections detected from multiple IP addresses: 23.28.198.165 (1477), 84.252.134.217 (33), 51.250.10.6 (140), 158.160.20.113 (48), 182.93.50.90 (13), 172.22.0.2 (82), 192.168.2.117 (591), 172.23.0.2 (12), and 192.168.2.104 (11). This indicates a potential coordinated attack or misconfigured system.'}
2025-09-15 13:22:04,982 - ERROR - Error sending Discord alert: 400 - b'{"content": ["Must be 2000 or fewer in length."]}' 2025-09-15 13:22:04,982 - ERROR - Error sending Discord alert: 400 - b'{"content": ["Must be 2000 or fewer in length."]}'
2025-09-15 13:22:11,390 - INFO - Google Home alert sent successfully. 2025-09-15 13:22:11,390 - INFO - Google Home alert sent successfully.
2025-09-15 13:25:08,619 - INFO - Running monitoring cycle...

View File

@@ -1 +1 @@
819154 822805