Setup Healthchecks integration for sunset detection reset #22

This commit is contained in:
Ashish D'Souza 2025-04-18 21:22:00 -05:00
parent e5c1560177
commit cafb1e0adf
4 changed files with 31 additions and 4 deletions

View File

@ -115,11 +115,17 @@ services:
environment:
IPGEOLOCATION_API_KEY: ${IPGEOLOCATION_API_KEY}
FRIGATE_CONFIG_FILE: /frigate_config/config.yaml
REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
SUNSET_DETECTION_RESET_HEALTHCHECKS_URL: 'https://healthchecks.homelab.net/ping/bee0e8ca-be23-41ba-aa30-478fc5f502f2'
volumes:
- type: volume
source: config
target: /frigate_config
read_only: true
- type: bind
source: /data/certs/homelab_ca.crt
target: /usr/local/share/ca-certificates/homelab_ca.crt
read_only: true
- type: bind
source: /etc/localtime
target: /etc/localtime

View File

@ -62,3 +62,9 @@
container: frigate-notifier
command: update-ca-certificates
user: root
- name: Update CA certificates for frigate-webcontrol
community.docker.docker_container_exec:
container: frigate-webcontrol
command: update-ca-certificates
user: root

View File

@ -4,3 +4,4 @@ fastapi==0.110.0
uvicorn[standard]==0.29.0
aiohttp==3.8.6
paho-mqtt==1.6.1
requests==2.30.0

View File

@ -4,6 +4,7 @@ import logging
import os
import paho.mqtt.publish as mqtt_publish
import requests
from webcontrol.frigate_config import FrigateConfigFile
from webcontrol.nighttime import get_nighttimes
@ -27,7 +28,20 @@ async def reset_all_cameras_detection_after_sunset() -> None:
logger.info(f"Waiting until {nighttime} to reset detection for all cameras")
await asyncio.sleep((nighttime - dt.datetime.now()).total_seconds())
healthchecks_url = os.getenv("SUNSET_DETECTION_RESET_HEALTHCHECKS_URL")
try:
if healthchecks_url:
requests.post(os.path.join(healthchecks_url, "start"))
await frigate_config_file.reload()
active_and_detection_enabled_cameras = set(frigate_config_file.active_cameras).intersection(frigate_config_file.detection_enabled_cameras)
for camera in active_and_detection_enabled_cameras:
await set_camera_detection(camera, True)
if healthchecks_url:
requests.post(healthchecks_url, data=", ".join(active_and_detection_enabled_cameras))
except Exception as e:
if healthchecks_url:
requests.post(os.path.join(healthchecks_url, "fail"), data=str(e))
raise e