From d102dc30f4ae884c89abb18ab62d6d68e85f87ec Mon Sep 17 00:00:00 2001 From: Spencer Date: Sun, 24 Aug 2025 13:30:21 -0500 Subject: [PATCH] Offloaded data detection from the LLM and hardcoded it --- PROGRESS.md | 6 +++--- monitor_agent.py | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/PROGRESS.md b/PROGRESS.md index 5e42e5f..412afa3 100644 --- a/PROGRESS.md +++ b/PROGRESS.md @@ -76,8 +76,6 @@ - [x] When calculating averages, please round up to the nearest integer. We only want to deliver whole integers to the LLM to process, and nothing with decimal points. It gets confused with decimal points. - [x] In the discord message, please include the exact specific details and the log of the problem that prompted the alert -## TODO - ## Phase 7: Offloading Analysis from LLM 39. [x] Create a new function `analyze_data_locally` in `monitor_agent.py`. @@ -93,4 +91,6 @@ 41.1. [x] Call `analyze_data_locally` to get the list of anomalies. 41.2. [x] If anomalies are found, call `generate_llm_report` to create the report. 41.3. [x] Use the output of `generate_llm_report` for alerting. -42. [x] Remove the detailed analytical instructions from `build_llm_prompt` as they will be handled by `analyze_data_locally`. \ No newline at end of file +42. [x] Remove the detailed analytical instructions from `build_llm_prompt` as they will be handled by `analyze_data_locally`. + +## TODO diff --git a/monitor_agent.py b/monitor_agent.py index 197b4e2..238dec6 100644 --- a/monitor_agent.py +++ b/monitor_agent.py @@ -284,6 +284,7 @@ def build_llm_prompt(anomalies): def generate_llm_report(anomalies): """Generates a report from a list of anomalies using the local LLM.""" + logger.info("Generating LLM report...") if not anomalies: return {"severity": "none", "reason": ""} @@ -322,7 +323,13 @@ def generate_llm_report(anomalies): def send_discord_alert(llm_response, combined_data): """Sends an alert to Discord.""" reason = llm_response.get('reason', 'No reason provided.') - message = f"**High Severity Alert:**\n> {reason}\n\n**Relevant Data:**\n```json\n{json.dumps(combined_data, indent=2)}\n```" + message = f"""**High Severity Alert:** +> {reason} + +**Relevant Data:** +```json +{json.dumps(combined_data, indent=2)} +```""" webhook = DiscordWebhook(url=config.DISCORD_WEBHOOK_URL, content=message) try: response = webhook.execute() @@ -430,6 +437,7 @@ def run_monitoring_cycle(nmap_scan_counter): anomalies = analyze_data_locally(combined_data, baselines, known_issues, port_applications) if anomalies: + logger.info(f"Detected {len(anomalies)} anomalies: {anomalies}") llm_response = generate_llm_report(anomalies) if llm_response and llm_response.get('severity') != "none": daily_events.append(llm_response.get('reason')) @@ -452,4 +460,4 @@ def main(): time.sleep(300) # Run every 5 minutes if __name__ == "__main__": - main() + main() \ No newline at end of file