-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdisable-sentry-monitors
More file actions
executable file
·37 lines (30 loc) · 1.08 KB
/
disable-sentry-monitors
File metadata and controls
executable file
·37 lines (30 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env python3
# ruff: noqa: T201,SIM108,TRY003
"""Disables sentry monitors for environment."""
import sys
from pathlib import Path
import requests
sentry_org = "weblate"
if len(sys.argv) != 2:
raise ValueError("Usage: disable-sentry-monitors PUBLIC_NAME")
public_name = sys.argv[1]
# Sentry
sentry_token_path = Path.home() / ".config" / "sentry_token"
sentry_token = sentry_token_path.read_text().strip()
auth = {"Authorization": f"Bearer {sentry_token}"}
response = requests.get(
f"https://de.sentry.io/api/0/organizations/{sentry_org}/monitors/",
params={"environment": public_name},
headers=auth,
)
response.raise_for_status()
cron_monitors = [cron for cron in response.json() if cron["environments"]]
print("Disabling cron monitors:", len(cron_monitors))
print(", ".join(monitor["slug"] for monitor in cron_monitors))
for cron in cron_monitors:
response = requests.delete(
f"https://de.sentry.io/api/0/organizations/{sentry_org}/monitors/{cron['slug']}/",
params={"environment": public_name},
headers=auth,
)
response.raise_for_status()