:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(uptime-monitoring): add the uptime monitor model (#122247)
Jon McCallumb1ece8d815d2
diff --git a/.semgrep/rules/security/idor-team-scoped-models.yaml b/.semgrep/rules/security/idor-team-scoped-models.yamlindex 37e0c677d76f..2ab29ded3105 100644--- a/.semgrep/rules/security/idor-team-scoped-models.yaml+++ b/.semgrep/rules/security/idor-team-scoped-models.yaml@@ -462,6 +462,7 @@ rules:|TracesRetentionRule|TracingView|UploadedMedia+ |UptimeMonitor|UserInterview|UserActivitySummaryQueueState|UserActivitySummaryVersion@@ -932,6 +933,7 @@ rules:|TracesRetentionRule|TracingView|UploadedMedia+ |UptimeMonitor|UserInterview|UserActivitySummaryQueueState|UserActivitySummaryVersiondiff --git a/products/uptime_monitoring/backend/facade/enums.py b/products/uptime_monitoring/backend/facade/enums.pynew file mode 100644index 000000000000..55b0d375ee7c--- /dev/null+++ b/products/uptime_monitoring/backend/facade/enums.py@@ -0,0 +1,12 @@+"""Choice vocabularies the models store and the API renders.++They live here rather than on the models because a product's facade must not import Django, and+both halves need the same list.+"""++from posthog.enums import LabeledStrEnum+++class UptimeMonitorMethod(LabeledStrEnum):+ GET = "GET", "GET"+ HEAD = "HEAD", "HEAD"diff --git a/products/uptime_monitoring/backend/migrations/0001_initial.py b/products/uptime_monitoring/backend/migrations/0001_initial.pynew file mode 100644index 000000000000..2ff857bd1c03--- /dev/null+++ b/products/uptime_monitoring/backend/migrations/0001_initial.py@@ -0,0 +1,93 @@+# Generated by Django 5.2.18 on 2026-10-22 13:00++import django.core.validators+import django.db.models.deletion+from django.conf import settings+from django.db import migrations, models++import posthog.uuidt+++class Migration(migrations.Migration):+ initial = True++ dependencies = [+ ("posthog", "1409_activitylog_team_user_created_at_index"),+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),+ ]++ operations = [+ migrations.CreateModel(+ name="UptimeMonitor",+ fields=[+ (+ "id",+ models.UUIDField(+ default=posthog.uuidt.uuid7,+ editable=False,+ primary_key=True,+ serialize=False,+ ),+ ),+ ("created_at", models.DateTimeField(auto_now_add=True)),+ ("updated_at", models.DateTimeField(auto_now=True)),+ ("name", models.CharField(max_length=255)),+ ("url", models.URLField(max_length=2048)),+ (+ "method",+ models.CharField(+ choices=[("GET", "GET"), ("HEAD", "HEAD")],+ db_default="GET",+ default="GET",+ max_length=8,+ ),+ ),+ (+ "interval_seconds",+ models.PositiveIntegerField(+ db_default=300,+ default=300,+ validators=[+ django.core.validators.MinValueValidator(60),+ django.core.validators.MaxValueValidator(86400),+ ],+ ),+ ),+ (+ "timeout_seconds",+ models.PositiveIntegerField(+ db_default=10,+ default=10,+ validators=[+ django.core.validators.MinValueValidator(1),+ django.core.validators.MaxValueValidator(10),+ ],+ ),+ ),+ ("enabled", models.BooleanField(db_default=True, default=True)),+ (+ "created_by",+ models.ForeignKey(+ blank=True,+ db_constraint=False,+ null=True,+ on_delete=django.db.models.deletion.SET_NULL,+ related_name="+",+ to=settings.AUTH_USER_MODEL,+ ),+ ),+ (+ "team",+ models.ForeignKey(+ db_constraint=False,+ on_delete=django.db.models.deletion.CASCADE,+ related_name="+",+ to="posthog.team",+ ),+ ),+ ],+ options={+ "abstract": False,+ },+ ),+ ]diff --git a/products/uptime_monitoring/backend/migrations/__init__.py b/products/uptime_monitoring/backend/migrations/__init__.pynew file mode 100644index 000000000000..e69de29bb2d1diff --git a/products/uptime_monitoring/backend/migrations/max_migration.txt b/products/uptime_monitoring/backend/migrations/max_migration.txtnew file mode 100644index 000000000000..cbab66dde92a--- /dev/null+++ b/products/uptime_monitoring/backend/migrations/max_migration.txt@@ -0,0 +1 @@+0001_initialdiff --git a/products/uptime_monitoring/backend/models/__init__.py b/products/uptime_monitoring/backend/models/__init__.pynew file mode 100644index 000000000000..a251be1a39d7--- /dev/null+++ b/products/uptime_monitoring/backend/models/__init__.py@@ -0,0 +1,3 @@+from .uptime_monitor import UptimeMonitor++__all__ = ["UptimeMonitor"]diff --git a/products/uptime_monitoring/backend/models/uptime_monitor.py b/products/uptime_monitoring/backend/models/uptime_monitor.pynew file mode 100644index 000000000000..8770b9dcd6a9--- /dev/null+++ b/products/uptime_monitoring/backend/models/uptime_monitor.py@@ -0,0 +1,49 @@+"""A URL to check and how to check it.++The row holds no check results and no pointer to whatever runs the checks. Results belong to the+runner, so the runner can change without a migration here.+"""++from django.core.validators import MaxValueValidator, MinValueValidator+from django.db import models++from posthog.models.scoping.root_mixin import TeamScopedRootMixin+from posthog.models.utils import UUIDModel++from products.uptime_monitoring.backend.facade.enums import UptimeMonitorMethod++MIN_INTERVAL_SECONDS = 60+MAX_INTERVAL_SECONDS = 24 * 60 * 60+MIN_TIMEOUT_SECONDS = 1+MAX_TIMEOUT_SECONDS = 10+++class UptimeMonitor(TeamScopedRootMixin, UUIDModel):+ Method = UptimeMonitorMethod++ # No database constraint: creating one takes a lock on `posthog_team` that queues behind+ # live writes. Django still cascades the delete in Python.+ team = models.ForeignKey("posthog.Team", on_delete=models.CASCADE, db_constraint=False, related_name="+")+ # No database constraint, for the same reason on `posthog_user`.+ created_by = models.ForeignKey(+ "posthog.User", on_delete=models.SET_NULL, null=True, blank=True, db_constraint=False, related_name="+"+ )+ created_at = models.DateTimeField(auto_now_add=True)+ updated_at = models.DateTimeField(auto_now=True)++ name = models.CharField(max_length=255)+ url = models.URLField(max_length=2048)+ method = models.CharField(+ max_length=8, choices=Method.choices, default=Method.GET.value, db_default=Method.GET.value+ )+ interval_seconds = models.PositiveIntegerField(+ default=300,+ db_default=300,+ validators=[MinValueValidator(MIN_INTERVAL_SECONDS), MaxValueValidator(MAX_INTERVAL_SECONDS)],+ )+ timeout_seconds = models.PositiveIntegerField(+ default=10,+ db_default=10,+ validators=[MinValueValidator(MIN_TIMEOUT_SECONDS), MaxValueValidator(MAX_TIMEOUT_SECONDS)],+ )+ enabled = models.BooleanField(default=True, db_default=True)diff --git a/products/uptime_monitoring/backend/tests/test_models.py b/products/uptime_monitoring/backend/tests/test_models.pynew file mode 100644index 000000000000..8c7674f306e2--- /dev/null+++ b/products/uptime_monitoring/backend/tests/test_models.py@@ -0,0 +1,18 @@+import pytest+from posthog.test.base import BaseTest++from posthog.models import Team+from posthog.models.scoping.manager import TeamScopeError++from products.uptime_monitoring.backend.models import UptimeMonitor+++class TestUptimeMonitorScoping(BaseTest):+ def test_reads_are_team_scoped_and_fail_closed(self) -> None:+ other_team = Team.objects.create(organization=self.organization)+ own = UptimeMonitor.objects.unscoped().create(team=self.team, name="Own", url="https://example.com")+ UptimeMonitor.objects.unscoped().create(team=other_team, name="Other", url="https://example.org")++ assert list(UptimeMonitor.objects.for_team(self.team.id)) == [own]+ with pytest.raises(TeamScopeError):+ list(UptimeMonitor.objects.all())diff --git a/products/uptime_monitoring/turbo.json b/products/uptime_monitoring/turbo.jsonindex 0f13f3b421f9..d1764a666306 100644--- a/products/uptime_monitoring/turbo.json+++ b/products/uptime_monitoring/turbo.json@@ -7,7 +7,7 @@"backend/presentation/**","backend/webhook_consumers.py","backend/tasks/**",- "backend/models.py",+ "backend/models/**","backend/migrations/**"],"outputs": [],