feat: integrate Uptime Kuma and Alertmanager into Docker setup

- Add Uptime Kuma service for status monitoring with health checks.
- Introduce Alertmanager service for alert management and notifications.
- Update docker-compose.yml to include new services and their configurations.
- Enhance Makefile with commands for managing Uptime Kuma and Alertmanager logs.
- Modify Ansible playbook to install necessary packages and configure SSL for new services.
- Update Nginx configuration to route traffic to Uptime Kuma and Alertmanager.
- Adjust Prometheus configuration to include alert rules and external URLs.
This commit is contained in:
2025-09-16 21:50:56 +03:00
parent 5e10204137
commit 9ec3f02767
20 changed files with 2173 additions and 38 deletions

View File

@@ -57,6 +57,15 @@
- nginx
- openssl
- apache2-utils
- certbot
- python3-certbot-nginx
state: present
- name: Установить Python библиотеки для Ansible
pip:
name:
- passlib
- bcrypt
state: present
- name: Установить часовой пояс Europe/Moscow
@@ -278,14 +287,40 @@
- "{{ project_root }}/infra/nginx"
- "{{ project_root }}/infra/nginx/ssl"
- "{{ project_root }}/infra/nginx/conf.d"
- "{{ project_root }}/infra/uptime-kuma"
- "{{ project_root }}/infra/alertmanager"
- "{{ project_root }}/infra/grafana/dashboards"
- "{{ project_root }}/scripts"
- name: Сгенерировать самоподписанный SSL сертификат
- name: Сгенерировать самоподписанный SSL сертификат (fallback)
command: >
openssl req -x509 -newkey rsa:4096 -keyout {{ project_root }}/infra/nginx/ssl/key.pem
-out {{ project_root }}/infra/nginx/ssl/cert.pem -days 365 -nodes
-subj "/CN={{ ansible_host }}/O=Monitoring/C=RU"
args:
creates: "{{ project_root }}/infra/nginx/ssl/cert.pem"
when: not use_letsencrypt | default(false)
- name: Создать директории для Let's Encrypt
file:
path: "{{ item }}"
state: directory
owner: root
group: root
mode: '0755'
loop:
- /etc/letsencrypt
- /etc/letsencrypt/live
- /etc/letsencrypt/archive
- /etc/letsencrypt/renewal
when: use_letsencrypt | default(false)
- name: Настроить cron для автоматического обновления SSL сертификатов
cron:
name: "SSL Certificate Renewal"
job: "0 2 * * 1 /usr/local/bin/ssl-renewal.sh"
user: root
when: use_letsencrypt | default(false)
- name: Установить права на SSL сертификаты
file:
@@ -314,6 +349,7 @@
group: root
mode: '0644'
backup: yes
remote_src: yes
- name: Скопировать конфигурации nginx для сервисов
copy:
@@ -323,6 +359,7 @@
group: root
mode: '0644'
backup: yes
remote_src: yes
- name: Скопировать SSL сертификаты
copy:
@@ -332,6 +369,7 @@
group: root
mode: '0600'
backup: yes
remote_src: yes
- name: Скопировать htpasswd файл
copy:
@@ -341,6 +379,47 @@
group: root
mode: '0644'
backup: yes
remote_src: yes
- name: Скопировать конфигурацию Alertmanager
copy:
src: "{{ project_root }}/infra/alertmanager/alertmanager.yml"
dest: "{{ project_root }}/infra/alertmanager/alertmanager.yml"
owner: "{{ deploy_user }}"
group: "{{ deploy_user }}"
mode: '0644'
backup: yes
remote_src: yes
- name: Скопировать правила алертов Prometheus
copy:
src: "{{ project_root }}/infra/prometheus/alert_rules.yml"
dest: "{{ project_root }}/infra/prometheus/alert_rules.yml"
owner: "{{ deploy_user }}"
group: "{{ deploy_user }}"
mode: '0644'
backup: yes
remote_src: yes
- name: Скопировать дашборды Grafana
copy:
src: "{{ project_root }}/infra/grafana/dashboards/"
dest: "{{ project_root }}/infra/grafana/dashboards/"
owner: "{{ deploy_user }}"
group: "{{ deploy_user }}"
mode: '0644'
backup: yes
remote_src: yes
- name: Скопировать скрипт настройки SSL
copy:
src: "{{ project_root }}/scripts/setup-ssl.sh"
dest: /usr/local/bin/setup-ssl.sh
owner: root
group: root
mode: '0755'
backup: yes
remote_src: yes
- name: Проверить конфигурацию nginx
command: nginx -t
@@ -811,6 +890,20 @@
timeout: 30
state: started
- name: Проверить, что порт 3001 (Uptime Kuma) открыт
wait_for:
port: 3001
host: "{{ ansible_host }}"
timeout: 30
state: started
- name: Проверить, что порт 9093 (Alertmanager) открыт
wait_for:
port: 9093
host: "{{ ansible_host }}"
timeout: 30
state: started
- name: Проверить доступность Nginx
uri:
url: "http://{{ ansible_host }}/nginx-health"
@@ -849,6 +942,26 @@
retries: 5
delay: 10
- name: Проверить доступность Uptime Kuma через Nginx
uri:
url: "https://{{ ansible_host }}/status"
method: GET
status_code: 200
validate_certs: no
register: uptime_kuma_nginx_health
retries: 5
delay: 10
- name: Проверить доступность Alertmanager через Nginx
uri:
url: "https://{{ ansible_host }}/alertmanager/"
method: GET
status_code: 200
validate_certs: no
register: alertmanager_nginx_health
retries: 5
delay: 10
- name: Закрыть старый SSH порт 22 в UFW (финальный шаг)
ufw:
@@ -858,7 +971,7 @@
- name: Проверка запуска ботов завершена — всё работает 🟢
debug:
msg: "Все сервисы запущены и слушают нужные порты. SSH настроен на порт 15722, Fail2ban активен, параметры безопасности ядра применены. Порт 22 закрыт для безопасности."
msg: "Все сервисы запущены и слушают нужные порты. SSH настроен на порт 15722, Fail2ban активен, параметры безопасности ядра применены. Порт 22 закрыт для безопасности. Добавлены: Uptime Kuma (статусная страница), Alertmanager (мониторинг), Let's Encrypt SSL, Grafana дашборды."
# handlers для перезагрузки сервисов
handlers: