From e64b880c9717f8a8385f967a49fbaccb179252e7 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 15 Sep 2025 13:27:40 -0500 Subject: [PATCH] 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. --- config.py | 2 +- monitor_agent.py | 28 ++++++++++++++++++---------- tmp/monitoring_agent.log | 1 + ufw_log_position.txt | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/config.py b/config.py index 073a894..ccf24cc 100755 --- a/config.py +++ b/config.py @@ -9,7 +9,7 @@ HOME_ASSISTANT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjOGRmZjI GOOGLE_HOME_SPEAKER_ID = "media_player.spencer_room_speaker" # Daily Recap Time (in 24-hour format, e.g., "20:00") -DAILY_RECAP_TIME = "18:28" +DAILY_RECAP_TIME = "22:00" # Nmap Configuration NMAP_TARGETS = "192.168.2.0/24" diff --git a/monitor_agent.py b/monitor_agent.py index 7130cb6..9acd6dd 100755 --- a/monitor_agent.py +++ b/monitor_agent.py @@ -455,18 +455,26 @@ def send_daily_recap(): """Sends a daily recap of events to Discord.""" global daily_events if daily_events: - recap_message = "\n".join(daily_events) - webhook = DiscordWebhook(url=config.DISCORD_WEBHOOK_URL, content=f"**Daily Recap:**\n{recap_message}") - try: - response = webhook.execute() - if response.status_code == 200: - logger.info("Daily recap sent successfully.") - else: - logger.error(f"Error sending daily recap: {response.status_code} - {response.content}") - except Exception as e: - logger.error(f"Error sending daily recap: {e}") + recap_message = "**Daily Recap:**\n" + "\n".join(daily_events) + + # Split the message into chunks of 2000 characters + message_chunks = [recap_message[i:i+2000] for i in range(0, len(recap_message), 2000)] + + for chunk in message_chunks: + webhook = DiscordWebhook(url=config.DISCORD_WEBHOOK_URL, content=chunk) + try: + response = webhook.execute() + 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 + def run_monitoring_cycle(nmap_scan_counter): """Runs a single monitoring cycle.""" diff --git a/tmp/monitoring_agent.log b/tmp/monitoring_agent.log index e3b45cd..0b60071 100755 --- a/tmp/monitoring_agent.log +++ b/tmp/monitoring_agent.log @@ -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,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:25:08,619 - INFO - Running monitoring cycle... diff --git a/ufw_log_position.txt b/ufw_log_position.txt index 7660983..27cd5fd 100644 --- a/ufw_log_position.txt +++ b/ufw_log_position.txt @@ -1 +1 @@ -819154 \ No newline at end of file +822805 \ No newline at end of file