From 524120c9f200cecde5281a78c3eef631bf9af108 Mon Sep 17 00:00:00 2001 From: Spencer Date: Mon, 18 Aug 2025 14:32:39 -0500 Subject: [PATCH] Watch over Temps --- .gitignore | 5 +-- CONSTRAINTS.md | 3 +- PROGRESS.md | 34 ++++++++++++++++++++ __pycache__/config.cpython-313.pyc | Bin 419 -> 721 bytes config.py | 10 +++--- data_storage.py | 2 ++ monitor_agent.py | 48 +++++++++++++---------------- requirements.txt | 3 +- 8 files changed, 69 insertions(+), 36 deletions(-) create mode 100644 PROGRESS.md diff --git a/.gitignore b/.gitignore index cd3db79..393bf58 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -GEMINI.md -PROGRESS.md +__pycache__/ +monitoring_data.json +__pycache__/config.cpython-313.pyc diff --git a/CONSTRAINTS.md b/CONSTRAINTS.md index efb6b8d..10dae14 100644 --- a/CONSTRAINTS.md +++ b/CONSTRAINTS.md @@ -4,4 +4,5 @@ - Prioritize security-related events such as failed login attempts, unauthorized access, or unusual network connections. - Focus on events indicating loss of connectivity or unreachable hosts. - Highlight any unexpected network additions or unusual traffic patterns. -- The DNS server 8.8.8.8 is Google's public DNS server and is a legitimate destination. Do not flag requests to 8.8.8.8 as anomalous. \ No newline at end of file +- The DNS server 8.8.8.8 is Google's public DNS server and is a legitimate destination. Do not flag requests to 8.8.8.8 as anomalous. +- Action has been taken against IP addresses 45.88.8.215, 45.88.8.186, 120.48.49.12, and 23.137.255.140. These are completley banned and cannot access the system at all. \ No newline at end of file diff --git a/PROGRESS.md b/PROGRESS.md new file mode 100644 index 0000000..acb3146 --- /dev/null +++ b/PROGRESS.md @@ -0,0 +1,34 @@ +# Project Progress + +## Phase 1: Initial Setup + +1. [x] Create `monitor_agent.py` +2. [x] Create `config.py` +3. [x] Create `requirements.txt` +4. [x] Create `README.md` +5. [x] Create `.gitignore` +6. [x] Create `SPEC.md` +7. [x] Create `PROMPT.md` +8. [x] Create `CONSTRAINTS.md` + +## Phase 2: Data Storage + +9. [x] Create `data_storage.py` +10. [x] Implement data storage functions in `data_storage.py` +11. [x] Update `monitor_agent.py` to use data storage +12. [x] Update `SPEC.md` to reflect data storage functionality + +## Phase 3: Expanded Monitoring + +13. [x] Implement CPU temperature monitoring +14. [x] Implement GPU temperature monitoring +15. [x] Implement system login attempt monitoring +16. [x] Update `monitor_agent.py` to include new metrics +17. [x] Update `SPEC.md` to reflect new metrics +18. [x] Extend `calculate_baselines` to include system temps + +## Phase 4: Troubleshooting + +19. [x] Investigated and resolved issue with `jc` library +20. [x] Removed `jc` library as a dependency +21. [x] Implemented manual parsing of `sensors` command output \ No newline at end of file diff --git a/__pycache__/config.cpython-313.pyc b/__pycache__/config.cpython-313.pyc index b0f9466fba281a57f30ab21968fa68eae55ef7bc..cbfd388dd3d4d6d19227dd376dabb5fb16310f15 100644 GIT binary patch delta 497 zcmWkr&2F1O5XN?#Hmw{*X_PkVsi&$31B=1NRxha$38p|W*s{4;Hf+N}VCiC&fGSye zgxq@1L-ZMXb8mTp+%5G5x*2J{(Tu*I!#p(pHV^-`TCW&dcRwG(r~3Wj$4#Bood#(* zdt}dPlIHdPrx#TjuGd*U;J5(gJ|+R{7kXl+FZX)Aj@ScS z#|nXN75z2*@g-=_){{7r$CaRq4!jzw`K_Le$z^C4Ql2T$)6EK(bG-T9t%ic1x;mDp z(I~CXp0jB*=nE|9$}B}73}hg5s^732g{uo6S!kq9Dh-%O%e8bY`9rO%#o25+9Q9dB z%KVP;Op2_FapFaqXex8TaBbdG)Ywu&WGU0gOzhHgH|K&;smOGwQ*sjq)X8vtV7e2Y zibTsPkT(kpEyAUt_=V-3^Ja7{eY07~gI0`gS3v?LM+NpYPCb4VrC0L^*d)uPOC@c8 z#i;Gu)rSNIXt~I4mL()?p25_IWI-@ajuv!V#*kD^fgkX^djIQ>`kH>IMmrZN>>9ON xZTFISJFah;H@ki26l|H}U7dMnH@3{lkggpEw-(y_s z!~=8@BM=uG0ErLGjEsyQI2gnwFE9vyU}F$7zrY}L1H==#A!&DkK@2D+B7K2D07&x+ KHgXn$JOlt{Lq6~T diff --git a/config.py b/config.py index aab66e9..1c55782 100644 --- a/config.py +++ b/config.py @@ -1,15 +1,15 @@ # Configuration for the LLM-Powered Monitoring Agent # Discord Webhook URL -DISCORD_WEBHOOK_URL = "" +DISCORD_WEBHOOK_URL = "https://discord.com/api/webhooks/1024892743987773471/3Oh1KOw9tevBd-XtUkj8Rz2K4SePCFsxKmRrHhQw5spDeZKNzoyYoq6zC2cnTKo8VjJn" # Home Assistant Configuration -HOME_ASSISTANT_URL = "http://:8123" -HOME_ASSISTANT_TOKEN = "" -GOOGLE_HOME_SPEAKER_ID = "media_player.your_speaker_entity_id" +HOME_ASSISTANT_URL = "http://192.168.2.112:8123" +HOME_ASSISTANT_TOKEN = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJjOGRmZjI4NDY2MTQ0ZDFkODhiODVjNmQyZTA2MzFiNSIsImlhdCI6MTc1NTU0NDY4OSwiZXhwIjoyMDcwOTA0Njg5fQ.5ZeOkixbdme5SF1QVknZ0bjnPYj1Qrps5HDn-Loi-cQ" +GOOGLE_HOME_SPEAKER_ID = "media_player.spencer_room_speaker" # Daily Recap Time (in 24-hour format, e.g., "20:00") DAILY_RECAP_TIME = "20:00" # Test Mode (True to run once and exit, False to run continuously) -TEST_MODE = True +TEST_MODE = False diff --git a/data_storage.py b/data_storage.py index 27831a1..5fed9e5 100644 --- a/data_storage.py +++ b/data_storage.py @@ -31,6 +31,8 @@ def calculate_baselines(): baseline_metrics = { 'avg_rtt': sum(d['network_metrics']['round_trip_ms_avg'] for d in recent_data) / len(recent_data), 'packet_loss': sum(d['network_metrics']['packet_loss_percent'] for d in recent_data) / len(recent_data), + 'avg_cpu_temp': sum(d['cpu_temperature']['cpu_temperature'] for d in recent_data) / len(recent_data), + 'avg_gpu_temp': sum(d['gpu_temperature']['gpu_temperature'] for d in recent_data) / len(recent_data), } return baseline_metrics \ No newline at end of file diff --git a/monitor_agent.py b/monitor_agent.py index b28d3cf..4fefbc8 100644 --- a/monitor_agent.py +++ b/monitor_agent.py @@ -7,7 +7,6 @@ import ollama from discord_webhook import DiscordWebhook import requests import data_storage -import jc # Load configuration import config @@ -43,43 +42,40 @@ def get_network_metrics(): print(f"Error parsing network metrics: {e}") return None +import re + def get_cpu_temperature(): """Gets the CPU temperature using the sensors command.""" try: - subprocess.check_output(["sensors"], text=True) + sensors_output = subprocess.check_output(["sensors"], text=True) + # Use regex to find the CPU temperature + match = re.search(r"Package id 0:\s+\+([\d\.]+)", sensors_output) + if match: + return {"cpu_temperature": float(match.group(1))} + else: + return {"cpu_temperature": "N/A"} except (subprocess.CalledProcessError, FileNotFoundError): print("Error: 'sensors' command not found. Please install lm-sensors.") return {"cpu_temperature": "N/A"} - try: - sensors_output = subprocess.check_output(["sensors"], text=True) - parsed_sensors = jc.parse('sensors', sensors_output) - # This is a simplified example, you may need to adjust the parsing logic based on your specific hardware - cpu_temp = parsed_sensors[0]['values'][0]['input'] - return {"cpu_temperature": cpu_temp} - except (subprocess.CalledProcessError, FileNotFoundError, KeyError, IndexError, jc.exceptions.ParseError) as e: - print(f"Error getting CPU temperature: {e}") - return {"cpu_temperature": "N/A"} def get_gpu_temperature(): """Gets the GPU temperature using the sensors command.""" try: - subprocess.check_output(["sensors"], text=True) + sensors_output = subprocess.check_output(["sensors"], text=True) + # Use regex to find the GPU temperature for amdgpu + match = re.search(r"edge:\s+\+([\d\.]+)", sensors_output) + if match: + return {"gpu_temperature": float(match.group(1))} + else: + # if amdgpu not found, try radeon + match = re.search(r"temp1:\s+\+([\d\.]+)", sensors_output) + if match: + return {"gpu_temperature": float(match.group(1))} + else: + return {"gpu_temperature": "N/A"} except (subprocess.CalledProcessError, FileNotFoundError): print("Error: 'sensors' command not found. Please install lm-sensors.") return {"gpu_temperature": "N/A"} - try: - sensors_output = subprocess.check_output(["sensors"], text=True) - parsed_sensors = jc.parse('sensors', sensors_output) - # This is a simplified example, you may need to adjust the parsing logic based on your specific hardware - # Look for the adapter that contains "amdgpu" or "radeon" - for adapter in parsed_sensors: - if 'amdgpu' in adapter.get('adapter', '').lower() or 'radeon' in adapter.get('adapter', '').lower(): - gpu_temp = adapter['values'][0]['input'] - return {"gpu_temperature": gpu_temp} - return {"gpu_temperature": "N/A"} - except (subprocess.CalledProcessError, FileNotFoundError, KeyError, IndexError, jc.exceptions.ParseError) as e: - print(f"Error getting GPU temperature: {e}") - return {"gpu_temperature": "N/A"} def get_login_attempts(): """Gets system login attempts from /var/log/auth.log.""" @@ -98,7 +94,7 @@ def get_login_attempts(): return {"failed_login_attempts": []} except Exception as e: print(f"Error reading login attempts: {e}") - return {"failed_login_attempts": []} + return {"failed_logins": []} # --- LLM Interaction Function --- diff --git a/requirements.txt b/requirements.txt index 6e5dbea..a03b1e7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,5 +2,4 @@ ollama discord-webhook requests syslog-rfc5424-parser -apachelogs -jc \ No newline at end of file +apachelogs \ No newline at end of file