mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-10-02 21:06:52 +03:00
Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ea24b60339 | ||
|
|
9bfe0f662e | ||
|
|
38b87feece |
@@ -571,6 +571,8 @@ notifications:
|
||||
enabled: False
|
||||
# Optional: Email for push service to reach out to
|
||||
# NOTE: This is required to use notifications
|
||||
# NOTE: Email can be specified with an environment variable or docker secrets that must begin with 'FRIGATE_'.
|
||||
# e.g. email: '{FRIGATE_NOTIFICATION_EMAIL}'
|
||||
email: "admin@example.com"
|
||||
# Optional: Cooldown time for notifications in seconds (default: shown below)
|
||||
cooldown: 0
|
||||
|
||||
+14
-3
@@ -311,9 +311,12 @@ def config(request: Request):
|
||||
mode="json", warnings="none", exclude_none=True
|
||||
)
|
||||
|
||||
# remove environment_vars for non-admin users
|
||||
if request.headers.get("remote-role") != "admin":
|
||||
is_admin = request.headers.get("remote-role") == "admin"
|
||||
|
||||
# hide environment_vars and the notification email from non-admin users
|
||||
if not is_admin:
|
||||
config.pop("environment_vars", None)
|
||||
redact_credential(config["notifications"], "email")
|
||||
|
||||
# redact mqtt credentials
|
||||
redact_credential(config["mqtt"], "password")
|
||||
@@ -370,7 +373,15 @@ def config(request: Request):
|
||||
camera_name
|
||||
)
|
||||
if base_sections:
|
||||
camera_dict["base_config"] = base_sections
|
||||
# copy so redaction below can't alter the profile manager's cache
|
||||
camera_dict["base_config"] = copy.deepcopy(base_sections)
|
||||
|
||||
# cameras inherit the global notification email
|
||||
if not is_admin:
|
||||
redact_credential(camera_dict["notifications"], "email")
|
||||
redact_credential(
|
||||
camera_dict.get("base_config", {}).get("notifications", {}), "email"
|
||||
)
|
||||
|
||||
# remove go2rtc stream passwords
|
||||
go2rtc: dict[str, Any] = config_obj.go2rtc.model_dump(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from pydantic import Field
|
||||
|
||||
from ..base import FrigateBaseModel
|
||||
from ..env import EnvString
|
||||
|
||||
__all__ = ["NotificationConfig"]
|
||||
|
||||
@@ -11,7 +12,7 @@ class NotificationConfig(FrigateBaseModel):
|
||||
title="Enable notifications",
|
||||
description="Enable or disable notifications for all cameras; can be overridden per-camera.",
|
||||
)
|
||||
email: str | None = Field(
|
||||
email: EnvString | None = Field(
|
||||
default=None,
|
||||
title="Notification email",
|
||||
description="Email address used for push notifications or required by certain notification providers.",
|
||||
|
||||
+17
-1
@@ -236,6 +236,15 @@ def skipped_percent(skipped_fps: float, camera_fps: float, enabled: bool) -> flo
|
||||
return round(skipped_fps / camera_fps * 100, 1)
|
||||
|
||||
|
||||
def get_go2rtc_pid(cpu_usages: dict[str, dict[str, Any]]) -> int | None:
|
||||
"""Find the pid of the running go2rtc process in the cpu usages."""
|
||||
for pid, usage in cpu_usages.items():
|
||||
if usage.get("cmdline", "").split(" ")[0].endswith("/go2rtc"):
|
||||
return int(pid)
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def stats_snapshot(
|
||||
config: FrigateConfig,
|
||||
stats_tracking: StatsTrackingTypes,
|
||||
@@ -356,6 +365,14 @@ def stats_snapshot(
|
||||
|
||||
stats["service"]["storage"]["/dev/shm"] = calculate_shm_requirements(config)
|
||||
|
||||
cpu_usages = stats.get("cpu_usages", {})
|
||||
|
||||
# go2rtc is supervised by s6, so its pid changes when s6 restarts it
|
||||
go2rtc_pid = get_go2rtc_pid(cpu_usages)
|
||||
|
||||
if go2rtc_pid is not None:
|
||||
stats_tracking["processes"]["go2rtc"] = go2rtc_pid
|
||||
|
||||
stats["processes"] = {}
|
||||
for name, pid in stats_tracking["processes"].items():
|
||||
stats["processes"][name] = {
|
||||
@@ -364,7 +381,6 @@ def stats_snapshot(
|
||||
|
||||
# Embed cpu/mem stats into detectors, cameras, and processes
|
||||
# so history consumers don't need the full cpu_usages dict
|
||||
cpu_usages = stats.get("cpu_usages", {})
|
||||
|
||||
for det_stats in stats["detectors"].values():
|
||||
pid_str = str(det_stats.get("pid", ""))
|
||||
|
||||
@@ -4,6 +4,7 @@ from unittest.mock import Mock, patch
|
||||
|
||||
import frigate.genai
|
||||
from frigate.config import GenAIProviderEnum
|
||||
from frigate.config.env import FRIGATE_ENV_VARS
|
||||
from frigate.const import MODEL_CACHE_DIR, REDACTED_CREDENTIAL_SENTINEL
|
||||
from frigate.genai import GenAIClient
|
||||
from frigate.models import Event, Recordings, ReviewSegment
|
||||
@@ -111,6 +112,30 @@ class TestHttpApp(BaseTestHttp):
|
||||
mqtt = response.json()["mqtt"]
|
||||
assert mqtt["password"] == REDACTED_CREDENTIAL_SENTINEL
|
||||
|
||||
def test_config_response_hides_notification_email_from_viewers(self):
|
||||
self.minimal_config["notifications"] = {"email": "{FRIGATE_TEST_EMAIL}"}
|
||||
|
||||
with patch.dict(FRIGATE_ENV_VARS, {"FRIGATE_TEST_EMAIL": "me@example.com"}):
|
||||
app = super().create_app()
|
||||
|
||||
assert app.frigate_config.notifications.email == "me@example.com"
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
response = client.get(
|
||||
"/config",
|
||||
headers={"remote-user": "viewer", "remote-role": "viewer"},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
config = response.json()
|
||||
assert config["notifications"]["email"] == REDACTED_CREDENTIAL_SENTINEL
|
||||
assert (
|
||||
config["cameras"]["front_door"]["notifications"]["email"]
|
||||
== REDACTED_CREDENTIAL_SENTINEL
|
||||
)
|
||||
|
||||
response = client.get("/config")
|
||||
assert response.json()["notifications"]["email"] == "me@example.com"
|
||||
|
||||
def test_config_response_keeps_plus_model_reference(self):
|
||||
model_id = "test_plus_reference"
|
||||
model_path = os.path.join(MODEL_CACHE_DIR, model_id)
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
"""Tests for resolving the go2rtc pid from cpu usages."""
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from frigate.stats.util import get_go2rtc_pid, stats_snapshot
|
||||
|
||||
|
||||
class TestGo2rtcPid(unittest.TestCase):
|
||||
def test_finds_go2rtc_by_binary_path(self):
|
||||
cpu_usages = {
|
||||
"frigate.full_system": {"cpu": "1.0", "mem": "2.0"},
|
||||
"100": {"cmdline": "ffmpeg -i rtsp://127.0.0.1:8554/go2rtc_cam"},
|
||||
"200": {
|
||||
"cmdline": "/usr/local/go2rtc/bin/go2rtc -config=/dev/shm/go2rtc.yaml"
|
||||
},
|
||||
"300": {"cmdline": "frigate.recording"},
|
||||
}
|
||||
|
||||
self.assertEqual(get_go2rtc_pid(cpu_usages), 200)
|
||||
|
||||
def test_finds_custom_go2rtc_binary(self):
|
||||
self.assertEqual(get_go2rtc_pid({"42": {"cmdline": "/config/go2rtc"}}), 42)
|
||||
|
||||
def test_returns_none_when_go2rtc_is_not_running(self):
|
||||
self.assertIsNone(get_go2rtc_pid({"100": {"cmdline": "ffmpeg -i x"}}))
|
||||
self.assertIsNone(get_go2rtc_pid({}))
|
||||
|
||||
|
||||
class TestGo2rtcPidInSnapshot(unittest.TestCase):
|
||||
def snapshot(self, tracking: dict, go2rtc_pid: int) -> dict:
|
||||
def update_stats(stats: dict) -> None:
|
||||
stats["cpu_usages"] = {
|
||||
str(go2rtc_pid): {
|
||||
"cmdline": "/usr/local/go2rtc/bin/go2rtc -config=x",
|
||||
"cpu": str(go2rtc_pid / 100),
|
||||
"mem": str(go2rtc_pid / 10),
|
||||
}
|
||||
}
|
||||
|
||||
config = SimpleNamespace(
|
||||
cameras={},
|
||||
telemetry=SimpleNamespace(stats=SimpleNamespace(network_bandwidth=False)),
|
||||
)
|
||||
hardware_stats = Mock()
|
||||
hardware_stats.update_stats.side_effect = update_stats
|
||||
|
||||
with (
|
||||
patch("frigate.stats.util.get_detector_stats", return_value={}),
|
||||
patch("frigate.stats.util.embeddings_stats", return_value={}),
|
||||
patch("frigate.stats.util.calculate_shm_requirements", return_value={}),
|
||||
):
|
||||
return stats_snapshot(config, tracking, hardware_stats)
|
||||
|
||||
def test_snapshot_follows_go2rtc_restart(self):
|
||||
tracking = {
|
||||
"camera_metrics": {},
|
||||
"detectors": {},
|
||||
"started": 0,
|
||||
"latest_frigate_version": "",
|
||||
"processes": {"go2rtc": 200, "recording": 50},
|
||||
"storage_maintainer": None,
|
||||
}
|
||||
|
||||
first = self.snapshot(tracking, 200)["processes"]["go2rtc"]
|
||||
self.assertEqual(first, {"pid": 200, "cpu": "2.0", "mem": "20.0"})
|
||||
|
||||
restarted = self.snapshot(tracking, 300)["processes"]["go2rtc"]
|
||||
self.assertEqual(restarted, {"pid": 300, "cpu": "3.0", "mem": "30.0"})
|
||||
Reference in New Issue
Block a user