Offloaded data detection from the LLM and hardcoded it
This commit is contained in:
@@ -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`.
|
||||
@@ -94,3 +92,5 @@
|
||||
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`.
|
||||
|
||||
## TODO
|
||||
|
||||
@@ -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'))
|
||||
|
||||
Reference in New Issue
Block a user