Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions appwrite/encoders/value_class_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
from ..enums.firebase_migration_resource import FirebaseMigrationResource
from ..enums.n_host_migration_resource import NHostMigrationResource
from ..enums.supabase_migration_resource import SupabaseMigrationResource
from ..enums.monitor_record import MonitorRecord
from ..enums.monitor_severity import MonitorSeverity
from ..enums.monitor_method import MonitorMethod
from ..enums.monitor_tls_mode import MonitorTlsMode
from ..enums.region import Region
from ..enums.project_auth_method_id import ProjectAuthMethodId
from ..enums.environment_resource import EnvironmentResource
Expand Down Expand Up @@ -74,6 +78,13 @@
from ..enums.execution_resource_type import ExecutionResourceType
from ..enums.execution_trigger import ExecutionTrigger
from ..enums.execution_status import ExecutionStatus
from ..enums.monitor_type import MonitorType
from ..enums.monitor_resource_type import MonitorResourceType
from ..enums.monitor_status import MonitorStatus
from ..enums.monitor_result import MonitorResult
from ..enums.alert_status import AlertStatus
from ..enums.alert_metric import AlertMetric
from ..enums.alert_comparator import AlertComparator
from ..enums.o_auth2_github_prompt import OAuth2GithubPrompt
from ..enums.o_auth2_discord_prompt import OAuth2DiscordPrompt
from ..enums.o_auth2_google_prompt import OAuth2GooglePrompt
Expand Down Expand Up @@ -195,6 +206,18 @@ def default(self, o):
if isinstance(o, SupabaseMigrationResource):
return o.value

if isinstance(o, MonitorRecord):
return o.value

if isinstance(o, MonitorSeverity):
return o.value

if isinstance(o, MonitorMethod):
return o.value

if isinstance(o, MonitorTlsMode):
return o.value

if isinstance(o, Region):
return o.value

Expand Down Expand Up @@ -321,6 +344,27 @@ def default(self, o):
if isinstance(o, ExecutionStatus):
return o.value

if isinstance(o, MonitorType):
return o.value

if isinstance(o, MonitorResourceType):
return o.value

if isinstance(o, MonitorStatus):
return o.value

if isinstance(o, MonitorResult):
return o.value

if isinstance(o, AlertStatus):
return o.value

if isinstance(o, AlertMetric):
return o.value

if isinstance(o, AlertComparator):
return o.value

if isinstance(o, OAuth2GithubPrompt):
return o.value

Expand Down
8 changes: 8 additions & 0 deletions appwrite/enums/alert_comparator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import Enum


class AlertComparator(Enum):
GREATERTHAN = "greaterThan"
GREATERTHANEQUAL = "greaterThanEqual"
LESSTHAN = "lessThan"
LESSTHANEQUAL = "lessThanEqual"
34 changes: 34 additions & 0 deletions appwrite/enums/alert_metric.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
from enum import Enum


class AlertMetric(Enum):
NETWORK_REQUESTS = "network.requests"
NETWORK_INBOUND = "network.inbound"
NETWORK_OUTBOUND = "network.outbound"
EXECUTIONS = "executions"
EXECUTIONS_MBSECONDS = "executions.mbSeconds"
REALTIME_CONNECTIONS = "realtime.connections"
WEBHOOKS_EVENTS_SENT = "webhooks.events.sent"
WEBHOOKS_EVENTS_FAILED = "webhooks.events.failed"
USERS_MAU = "users.mau"
AUTH_METHOD_PHONE = "auth.method.phone"
USERS = "users"
DATABASES_OPERATIONS_READS = "databases.operations.reads"
DATABASES_OPERATIONS_WRITES = "databases.operations.writes"
DATABASES_STORAGE = "databases.storage"
STORAGE = "storage"
FILES_STORAGE = "files.storage"
MESSAGES_SENT = "messages.sent"
MESSAGES_SMS_SENT = "messages.sms.sent"
MESSAGES_FAILED = "messages.failed"
AVATARS_SCREENSHOTSGENERATED = "avatars.screenshotsGenerated"
DEDICATEDDATABASES_CPU = "dedicatedDatabases.cpu"
DEDICATEDDATABASES_MEMORY = "dedicatedDatabases.memory"
DEDICATEDDATABASES_STORAGE = "dedicatedDatabases.storage"
DEDICATEDDATABASES_CONNECTIONS = "dedicatedDatabases.connections"
DEDICATEDDATABASES_QPS = "dedicatedDatabases.qps"
DEDICATEDDATABASES_IOPSREAD = "dedicatedDatabases.iopsRead"
DEDICATEDDATABASES_IOPSWRITE = "dedicatedDatabases.iopsWrite"
ANALYTICS_EVENTS = "analytics.events"
ANALYTICS_PAGEVIEWS = "analytics.pageviews"
BILLING_BUDGETUSED = "billing.budgetUsed"
6 changes: 6 additions & 0 deletions appwrite/enums/alert_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class AlertStatus(Enum):
FIRING = "firing"
RESOLVED = "resolved"
11 changes: 11 additions & 0 deletions appwrite/enums/monitor_method.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class MonitorMethod(Enum):
GET = "GET"
HEAD = "HEAD"
POST = "POST"
PUT = "PUT"
PATCH = "PATCH"
DELETE = "DELETE"
OPTIONS = "OPTIONS"
10 changes: 10 additions & 0 deletions appwrite/enums/monitor_record.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class MonitorRecord(Enum):
A = "A"
AAAA = "AAAA"
CNAME = "CNAME"
MX = "MX"
TXT = "TXT"
NS = "NS"
11 changes: 11 additions & 0 deletions appwrite/enums/monitor_resource_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from enum import Enum


class MonitorResourceType(Enum):
PROJECT = "project"
DATABASE = "database"
BUCKET = "bucket"
FUNCTION = "function"
SITE = "site"
DEDICATEDDATABASE = "dedicatedDatabase"
ORGANIZATION = "organization"
17 changes: 17 additions & 0 deletions appwrite/enums/monitor_result.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from enum import Enum


class MonitorResult(Enum):
OK = "ok"
DNS_FAILED = "dns_failed"
CONNECT_REFUSED = "connect_refused"
CONNECT_TIMEOUT = "connect_timeout"
CONNECT_FAILED = "connect_failed"
TLS_FAILED = "tls_failed"
TLS_EXPIRING = "tls_expiring"
STATUS_MISMATCH = "status_mismatch"
ANSWER_MISMATCH = "answer_mismatch"
SMTP_REJECTED = "smtp_rejected"
TARGET_DENIED = "target_denied"
TIMEOUT = "timeout"
RULE_MATCHED = "rule_matched"
8 changes: 8 additions & 0 deletions appwrite/enums/monitor_severity.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import Enum


class MonitorSeverity(Enum):
INFO = "info"
WARNING = "warning"
ERROR = "error"
CRITICAL = "critical"
6 changes: 6 additions & 0 deletions appwrite/enums/monitor_status.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from enum import Enum


class MonitorStatus(Enum):
OK = "ok"
FIRING = "firing"
8 changes: 8 additions & 0 deletions appwrite/enums/monitor_tls_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from enum import Enum


class MonitorTlsMode(Enum):
NONE = "none"
STARTTLS = "starttls"
IMPLICIT = "implicit"
AUTO = "auto"
10 changes: 10 additions & 0 deletions appwrite/enums/monitor_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from enum import Enum


class MonitorType(Enum):
USAGE = "usage"
HTTP = "http"
DNS = "dns"
TCP = "tcp"
SMTP = "smtp"
BUDGET = "budget"
8 changes: 8 additions & 0 deletions appwrite/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from .execution_list import ExecutionList
from .project_list import ProjectList
from .webhook_list import WebhookList
from .monitor_list import MonitorList
from .alert_list import AlertList
from .key_list import KeyList
from .country_list import CountryList
from .continent_list import ContinentList
Expand Down Expand Up @@ -131,6 +133,8 @@
from .project_service import ProjectService
from .project_protocol import ProjectProtocol
from .webhook import Webhook
from .monitor import Monitor
from .alert import Alert
from .key import Key
from .ephemeral_key import EphemeralKey
from .mock_number import MockNumber
Expand Down Expand Up @@ -369,6 +373,8 @@
'ExecutionList',
'ProjectList',
'WebhookList',
'MonitorList',
'AlertList',
'KeyList',
'CountryList',
'ContinentList',
Expand Down Expand Up @@ -477,6 +483,8 @@
'ProjectService',
'ProjectProtocol',
'Webhook',
'Monitor',
'Alert',
'Key',
'EphemeralKey',
'MockNumber',
Expand Down
151 changes: 151 additions & 0 deletions appwrite/models/alert.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
from typing import Any, Dict, List, Optional, Union, cast
from pydantic import Field, PrivateAttr, model_validator

from .base_model import AppwriteModel
from ..enums.alert_status import AlertStatus
from ..enums.monitor_severity import MonitorSeverity
from ..enums.alert_metric import AlertMetric
from ..enums.alert_comparator import AlertComparator
from ..enums.monitor_type import MonitorType
from ..enums.monitor_resource_type import MonitorResourceType
from ..enums.monitor_result import MonitorResult


class Alert(AppwriteModel):
"""
Alert

Attributes
----------
id : str
Alert ID.
createdat : str
Date the alert started firing, in ISO 8601 format.
updatedat : str
Alert update date in ISO 8601 format.
monitorid : str
ID of the monitor that raised the alert.
name : str
Name of the monitor when the alert fired.
status : AlertStatus
Whether the alert is still firing or has resolved.
resolvedat : Optional[str]
Date the alert resolved, in ISO 8601 format. Empty while it fires.
acknowledgedat : Optional[str]
Date a member acknowledged the alert, in ISO 8601 format. Empty while nobody has.
acknowledgedby : str
ID of the user who acknowledged the alert. Empty while nobody has, or when it was acknowledged with an API key.
acknowledgedbyname : str
Name of the user who acknowledged the alert, when they did.
escalationid : str
ID of the escalation notifying the team of this alert. Empty when the monitor notified its `notify` roles instead.
escalationstep : float
Index of the escalation's next step to notify, counting from 0. Equal to the number of steps once the last round has gone out.
escalationround : float
How many times the escalation's steps have been repeated for this alert.
escalatesat : Optional[str]
When the next step is notified, in ISO 8601 format. Null when nothing is due: the alert was acknowledged or resolved, or every step has gone out.
rules : List[Any]
The monitor's rules when the alert fired, as query strings.
severity : MonitorSeverity
The monitor's severity when the alert fired: `info`, `warning`, `error` or `critical`.
metric : Optional[AlertMetric]
Metric the alert fired on. Null for a probe monitor's alert.
comparator : Optional[AlertComparator]
How the metric was compared with the threshold. Null for a probe monitor's alert.
threshold : float
Threshold the metric crossed, in the metric's unit.
value : float
Latest reading while the alert fired: the metric's value for a usage monitor, and for a probe monitor its `latency`.
peak : float
Reading furthest past the threshold while the alert fired.
type : MonitorType
Type of the monitor that raised the alert.
resourcetype : MonitorResourceType
Type of the resource the alert fired on: the project, or one database, bucket, function or site.
resourceid : str
ID of the resource the alert fired on. The project ID for a project-wide monitor.
notifications : float
How many times the alert was announced as firing: once when it fired, and again after each cooldown while it kept firing.
latency : Optional[float]
Probe monitors: response time in milliseconds of the latest check recorded on the alert.
result : Optional[MonitorResult]
What the failing check of a probe monitor found when the alert opened, such as `connect_refused`. Null for a usage monitor's alert.
"""

id: str = Field(..., alias='$id')
createdat: str = Field(..., alias='$createdAt')
updatedat: str = Field(..., alias='$updatedAt')
monitorid: str = Field(..., alias='monitorId')
name: str = Field(..., alias='name')
status: AlertStatus = Field(..., alias='status')
resolvedat: Optional[str] = Field(default=None, alias='resolvedAt')
acknowledgedat: Optional[str] = Field(default=None, alias='acknowledgedAt')
acknowledgedby: str = Field(..., alias='acknowledgedBy')
acknowledgedbyname: str = Field(..., alias='acknowledgedByName')
escalationid: str = Field(..., alias='escalationId')
escalationstep: float = Field(..., alias='escalationStep')
escalationround: float = Field(..., alias='escalationRound')
escalatesat: Optional[str] = Field(default=None, alias='escalatesAt')
rules: List[Any] = Field(..., alias='rules')
severity: MonitorSeverity = Field(..., alias='severity')
metric: Optional[AlertMetric] = Field(default=None, alias='metric')
comparator: Optional[AlertComparator] = Field(default=None, alias='comparator')
threshold: float = Field(..., alias='threshold')
value: float = Field(..., alias='value')
peak: float = Field(..., alias='peak')
type: MonitorType = Field(..., alias='type')
resourcetype: MonitorResourceType = Field(..., alias='resourceType')
resourceid: str = Field(..., alias='resourceId')
notifications: float = Field(..., alias='notifications')
latency: Optional[float] = Field(default=None, alias='latency')
result: Optional[MonitorResult] = Field(default=None, alias='result')

@model_validator(mode='before')
@classmethod
def _apply_defaults(cls, data: Any) -> Any:
if not isinstance(data, dict):
return data

data = dict(data)
if '$id' not in data and 'id' not in data:
data['$id'] = ''
if '$createdAt' not in data and 'createdat' not in data:
data['$createdAt'] = ''
if '$updatedAt' not in data and 'updatedat' not in data:
data['$updatedAt'] = ''
if 'monitorId' not in data and 'monitorid' not in data:
data['monitorId'] = ''
if 'name' not in data:
data['name'] = ''
if 'status' not in data:
data['status'] = 'firing'
if 'acknowledgedBy' not in data and 'acknowledgedby' not in data:
data['acknowledgedBy'] = ''
if 'acknowledgedByName' not in data and 'acknowledgedbyname' not in data:
data['acknowledgedByName'] = ''
if 'escalationId' not in data and 'escalationid' not in data:
data['escalationId'] = ''
if 'escalationStep' not in data and 'escalationstep' not in data:
data['escalationStep'] = 0
if 'escalationRound' not in data and 'escalationround' not in data:
data['escalationRound'] = 0
if 'rules' not in data:
data['rules'] = []
if 'severity' not in data:
data['severity'] = 'warning'
if 'threshold' not in data:
data['threshold'] = 0
if 'value' not in data:
data['value'] = 0
if 'peak' not in data:
data['peak'] = 0
if 'type' not in data:
data['type'] = 'usage'
if 'resourceType' not in data and 'resourcetype' not in data:
data['resourceType'] = 'project'
if 'resourceId' not in data and 'resourceid' not in data:
data['resourceId'] = ''
if 'notifications' not in data:
data['notifications'] = 0
return data
Loading
Loading