Skip to content

Commit 034e2a6

Browse files
committed
feat: add alerts
1 parent c844933 commit 034e2a6

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

videodb/_constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class ApiPath:
7373
rtstream = "rtstream"
7474
status = "status"
7575
event = "event"
76+
alert = "alert"
7677

7778

7879
class Status:

videodb/rtstream.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ def stop(self):
4949
)
5050
self.status = "stopped"
5151

52+
def create_alert(self, event_id, callback_url) -> str:
53+
alert_data = self._connection.post(
54+
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}",
55+
data={
56+
"event_id": event_id,
57+
"callback_url": callback_url,
58+
},
59+
)
60+
return alert_data.get("alert_id", None)
61+
62+
def list_alerts(self):
63+
alert_data = self._connection.get(
64+
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}"
65+
)
66+
return alert_data.get("alerts", [])
67+
68+
def enable_alert(self, alert_id):
69+
self._connection.patch(
70+
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}/{alert_id}/{ApiPath.status}",
71+
data={"status": "enabled"},
72+
)
73+
74+
def disable_alert(self, alert_id):
75+
self._connection.patch(
76+
f"{ApiPath.rtstream}/{self.rtstream_id}/{ApiPath.index}/{self.rtstream_index_id}/{ApiPath.alert}/{alert_id}/{ApiPath.status}",
77+
data={"status": "disabled"},
78+
)
79+
5280

5381
class RTStream:
5482
def __init__(self, _connection, id: str, **kwargs) -> None:

0 commit comments

Comments
 (0)