Skip to content

Commit 4870e17

Browse files
committed
feat: started working on alertmanager and custom metrics
1 parent b2f5d92 commit 4870e17

18 files changed

Lines changed: 163 additions & 13 deletions

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,6 @@ TELEGRAM_CHANNEL=
2727

2828
CLICKUP_API_TOKEN=
2929
CLICKUP_SPACE_ID=
30+
31+
ALERTMANAGER_TELEGRAM_TOKEN=
32+
ALERTMANAGER_TELEGRAM_CHAT_ID=

Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ FROM python:3.11
22

33
RUN apt update --no-install-recommends -y
44

5+
RUN apt-get update && \
6+
apt-get install -y cmake && \
7+
rm -rf /var/lib/apt/lists/*
8+
59
ENV PYTHONFAULTHANDLER=1 \
610
PYTHONUNBUFFERED=1 \
711
PYTHONHASHSEED=random \

Makefile

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
11
up:
22
docker compose -f docker-compose.yml up -d
33
down:
4-
docker compose -f docker-compose.yml down
4+
docker compose -f docker-compose.yml down
5+
6+
build:
7+
docker compose -f docker-compose.yml build
8+
9+
superuser:
10+
docker exec -it web poetry run python manage.py createsuperuser
11+
12+
migrate:
13+
docker exec -it web poetry run python manage.py migrate
14+
15+
migrations:
16+
docker exec -it web poetry run python manage.py makemigrations
17+
18+
logs:
19+
docker container logs web

alerts/__init__.py

Whitespace-only changes.

alerts/admin.py

Whitespace-only changes.

alerts/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class AlertsConfig(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "alerts"

alerts/migrations/__init__.py

Whitespace-only changes.

alerts/urls.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from django.urls import path
2+
from .views import alert_webhook
3+
4+
app_name = "alerts"
5+
6+
urlpatterns = [
7+
path("webhook/", alert_webhook, name="alert_webhook"),
8+
]

alerts/views.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from django.http import JsonResponse
2+
from django.views.decorators.csrf import csrf_exempt
3+
import json
4+
import requests
5+
6+
from django.conf import settings
7+
8+
import logging
9+
10+
logger = logging.getLogger(__name__)
11+
12+
13+
@csrf_exempt
14+
def alert_webhook(request):
15+
if request.method == "POST":
16+
try:
17+
payload = json.loads(request.body)
18+
for alert in payload["alerts"]:
19+
message = f"Alert: {alert['annotations']['summary']} - {alert['status']}"
20+
send_telegram_message(message)
21+
except Exception as exc:
22+
logger.error(f"Failed to process alert {exc}", exc_info=exc)
23+
return JsonResponse({"status": "success"})
24+
return JsonResponse({"status": "error"}, status=400)
25+
26+
27+
def send_telegram_message(message):
28+
url = (
29+
f"https://api.telegram.org/bot{settings.ALERTMANAGER_TELEGRAM_TOKEN}/sendMessage"
30+
)
31+
data = {"chat_id": settings.ALERTMANAGER_TELEGRAM_CHAT_ID, "text": message}
32+
response = requests.post(url, data=data)
33+
return response.json()

docker-compose.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ services:
1010
command: bash ./scripts/startup.sh
1111
volumes:
1212
- ./log:/procollab/log
13+
- ./db.sqlite3:/procollab/db.sqlite3
1314
env_file:
1415
- .env
1516
environment:
1617
HOST: 0.0.0.0
1718
expose:
1819
- 8000
19-
2020
grafana:
2121
image: grafana/grafana-enterprise
2222
container_name: grafana
@@ -36,6 +36,15 @@ services:
3636
- prom-data:/prometheus
3737
- ./prometheus:/etc/prometheus
3838

39+
alertmanager:
40+
image: prom/alertmanager:latest
41+
container_name: alertmanager
42+
volumes:
43+
- ./prometheus/alertmanager.yml:/etc/alertmanager/alertmanager.yml
44+
command:
45+
- '--config.file=/etc/alertmanager/alertmanager.yml'
46+
ports:
47+
- '9093:9093'
3948

4049
nginx:
4150
container_name: nginx

0 commit comments

Comments
 (0)