Setup Healthchecks integration for sunset detection reset #22
This commit is contained in:
parent
749f6fcf4f
commit
f3ea6d0379
|
@ -115,11 +115,17 @@ services:
|
||||||
environment:
|
environment:
|
||||||
IPGEOLOCATION_API_KEY: ${IPGEOLOCATION_API_KEY}
|
IPGEOLOCATION_API_KEY: ${IPGEOLOCATION_API_KEY}
|
||||||
FRIGATE_CONFIG_FILE: /frigate_config/config.yaml
|
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:
|
volumes:
|
||||||
- type: volume
|
- type: volume
|
||||||
source: config
|
source: config
|
||||||
target: /frigate_config
|
target: /frigate_config
|
||||||
read_only: true
|
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
|
- type: bind
|
||||||
source: /etc/localtime
|
source: /etc/localtime
|
||||||
target: /etc/localtime
|
target: /etc/localtime
|
||||||
|
|
|
@ -4,6 +4,7 @@ import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import paho.mqtt.publish as mqtt_publish
|
import paho.mqtt.publish as mqtt_publish
|
||||||
|
import requests
|
||||||
|
|
||||||
from webcontrol.frigate_config import FrigateConfigFile
|
from webcontrol.frigate_config import FrigateConfigFile
|
||||||
from webcontrol.nighttime import get_nighttimes
|
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")
|
logger.info(f"Waiting until {nighttime} to reset detection for all cameras")
|
||||||
await asyncio.sleep((nighttime - dt.datetime.now()).total_seconds())
|
await asyncio.sleep((nighttime - dt.datetime.now()).total_seconds())
|
||||||
|
|
||||||
await frigate_config_file.reload()
|
healthchecks_url = os.getenv("SUNSET_DETECTION_RESET_HEALTHCHECKS_URL")
|
||||||
active_and_detection_enabled_cameras = set(frigate_config_file.active_cameras).intersection(frigate_config_file.detection_enabled_cameras)
|
try:
|
||||||
for camera in active_and_detection_enabled_cameras:
|
if healthchecks_url:
|
||||||
await set_camera_detection(camera, True)
|
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
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue