feat: Restrict alerts to a defined time window

- Add a function to check if the current time is within the alerting window (9am - 12am).
- Modify the alerting logic to only send alerts during this window.
- Update PROGRESS.md to reflect the completion of the task.
This commit is contained in:
2025-08-21 12:28:08 -05:00
parent d03018de9b
commit 7e24379fa1
2 changed files with 11 additions and 5 deletions

View File

@@ -71,7 +71,8 @@
- [x] Change baseline calculations to only use integers instead of floats. - [x] Change baseline calculations to only use integers instead of floats.
- [x] Add a log file that only keeps records for the past 24 hours. - [x] Add a log file that only keeps records for the past 24 hours.
- [x] Log all LLM responses to the console. - [x] Log all LLM responses to the console.
- [ ] Reduce alerts to only happen between 9am and 12am. - [x] Reduce alerts to only happen between 9am and 12am.
- [ ] Get hostnames of devices in Nmap scan. - [ ] Get hostnames of devices in Nmap scan.
- [ ] Filter out RTT fluctuations below 10 seconds. - [ ] Filter out RTT fluctuations below 10 seconds.
- [ ] Filter out temperature fluctuations with differences less than 5 degrees. - [ ] Filter out temperature fluctuations with differences less than 5 degrees.
- [ ] Create a list of known port numbers and their applications for the LLM to check against to see if an open port is a threat

View File

@@ -301,7 +301,7 @@ def send_google_home_alert(message):
simplified_message = response['response'].strip() simplified_message = response['response'].strip()
except Exception as e: except Exception as e:
logger.error(f"Error summarizing message: {e}") logger.error(f"Error summarizing message: {e}")
simplified_message = message.split('.')[0] # Take the first sentence as a fallback simplified_.message = message.split('.')[0] # Take the first sentence as a fallback
url = f"{config.HOME_ASSISTANT_URL}/api/services/tts/speak" url = f"{config.HOME_ASSISTANT_URL}/api/services/tts/speak"
headers = { headers = {
@@ -324,6 +324,11 @@ def send_google_home_alert(message):
# --- Main Script Logic --- # --- Main Script Logic ---
def is_alerting_time():
"""Checks if the current time is within the alerting window (9am - 12am)."""
current_hour = datetime.now().hour
return 9 <= current_hour < 24
daily_events = [] daily_events = []
def run_monitoring_cycle(nmap_scan_counter): def run_monitoring_cycle(nmap_scan_counter):
@@ -361,7 +366,7 @@ def run_monitoring_cycle(nmap_scan_counter):
if llm_response and llm_response.get('severity') != "none": if llm_response and llm_response.get('severity') != "none":
daily_events.append(llm_response.get('reason')) daily_events.append(llm_response.get('reason'))
if llm_response.get('severity') == "high": if llm_response.get('severity') == "high" and is_alerting_time():
send_discord_alert(llm_response.get('reason')) send_discord_alert(llm_response.get('reason'))
send_google_home_alert(llm_response.get('reason')) send_google_home_alert(llm_response.get('reason'))
return nmap_scan_counter return nmap_scan_counter
@@ -386,4 +391,4 @@ def main():
time.sleep(300) # Run every 5 minutes time.sleep(300) # Run every 5 minutes
if __name__ == "__main__": if __name__ == "__main__":
main() main()