mirror of
https://gh.llkk.cc/https://github.com/WeblateOrg/scripts.git
synced 2025-10-03 15:01:00 +08:00
37 lines
1.1 KiB
Python
Executable file
37 lines
1.1 KiB
Python
Executable file
#!/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()
|