Обновить playbooks/statistica.yml

This commit is contained in:
2026-10-11 21:16:26 +03:00
parent 372b31bf43
commit 2c52588f0b
+31 -13
View File
@@ -1,5 +1,5 @@
--- ---
- name: Collect Debian system metrics and send to Telegram (with optional proxy) - name: Collect Debian system metrics and send to Telegram (via SOCKS5 proxy)
hosts: all hosts: all
gather_facts: yes gather_facts: yes
become: true become: true
@@ -7,9 +7,10 @@
vars: vars:
telegram_token: "8820292312:AAECFO1AEWOJTh30zNuhyjC5C81o_qJHQcM" telegram_token: "8820292312:AAECFO1AEWOJTh30zNuhyjC5C81o_qJHQcM"
telegram_chat_id: "407968638" telegram_chat_id: "407968638"
# Прокси: socks5h://user:pass@host:port — оставь пустым, если не нужен # SOCKS5-прокси на control node (машинке, откуда запускается Ansible)
proxy: "" telegram_proxy: "socks5h://administrator:60NthRegT@192.168.0.218:1080"
# Пакеты, нужные для метрик (Debian)
# Пакеты для метрик (Debian)
metrics_packages: metrics_packages:
- curl - curl
- bc - bc
@@ -19,7 +20,7 @@
- smartmontools - smartmontools
tasks: tasks:
# ---------- 0. PREFLIGHT: ставим зависимости на Debian ---------- # ---------- 0. PREFLIGHT: зависимости на Debian ----------
- name: Ensure required packages are installed (Debian/Ubuntu) - name: Ensure required packages are installed (Debian/Ubuntu)
ansible.builtin.apt: ansible.builtin.apt:
name: "{{ metrics_packages }}" name: "{{ metrics_packages }}"
@@ -27,7 +28,6 @@
update_cache: yes update_cache: yes
cache_valid_time: 3600 cache_valid_time: 3600
when: ansible_os_family == "Debian" when: ansible_os_family == "Debian"
register: apt_result
- name: Warn if host is not Debian family - name: Warn if host is not Debian family
ansible.builtin.debug: ansible.builtin.debug:
@@ -262,15 +262,33 @@
<b>🔥 Топ-5 процессов по памяти:</b> <b>🔥 Топ-5 процессов по памяти:</b>
<pre>{{ top_procs_joined }}</pre> <pre>{{ top_procs_joined }}</pre>
# ---------- 14. Отправка в Telegram ---------- # ---------- 14. Проверка доступности Telegram через прокси ----------
- name: Send to Telegram via proxy - name: Check Telegram API reachability via SOCKS5 proxy (from control node)
ansible.builtin.shell: |
curl -s -o /dev/null -w "%{http_code}" --max-time 15 \
--proxy "{{ telegram_proxy }}" \
"https://api.telegram.org/bot{{ telegram_token }}/getMe"
register: tg_check
changed_when: false
failed_when: false
delegate_to: localhost
become: false
- name: Fail early if Telegram API is unreachable via proxy
ansible.builtin.fail:
msg: >
Telegram API недоступен через прокси {{ telegram_proxy }}.
HTTP-код: {{ tg_check.stdout }}. Проверь прокси, учётку и сеть.
when: tg_check.stdout != "200"
delegate_to: localhost
become: false
# ---------- 15. Отправка в Telegram через SOCKS5-прокси ----------
- name: Send to Telegram via SOCKS5 proxy (from control node)
ansible.builtin.shell: | ansible.builtin.shell: |
set -e set -e
proxy_opt="" response=$(curl -s -w "\n%{http_code}" -X POST \
if [ -n "{{ proxy }}" ]; then --proxy "{{ telegram_proxy }}" \
proxy_opt="--socks5-hostname {{ proxy }}"
fi
response=$(curl -s -w "\n%{http_code}" -X POST $proxy_opt \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{"chat_id": "{{ telegram_chat_id }}", "text": {{ message_html | to_json }}, "parse_mode": "HTML"}' \ -d '{"chat_id": "{{ telegram_chat_id }}", "text": {{ message_html | to_json }}, "parse_mode": "HTML"}' \
"https://api.telegram.org/bot{{ telegram_token }}/sendMessage" 2>&1) "https://api.telegram.org/bot{{ telegram_token }}/sendMessage" 2>&1)