From 703fc9dd57409cc153a36576cb4277bea908a45b Mon Sep 17 00:00:00 2001 From: vladimir Date: Sat, 1 Aug 2026 04:49:22 +0300 Subject: [PATCH] =?UTF-8?q?build:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20pyproject.toml=20=D0=B8=20Makefile,=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D1=8B=20=D1=88=D0=B0?= =?UTF-8?q?=D0=B1=D0=BB=D0=BE=D0=BD=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 11 ++++++++++- .gitignore | 3 ++- Makefile | 11 +++++++++++ config.json.example | 29 ++++++++++++++++++----------- pyproject.toml | 26 ++++++++++++++++++++++++++ state.json.example | 13 +++++++++++++ 6 files changed, 80 insertions(+), 13 deletions(-) create mode 100644 Makefile create mode 100644 pyproject.toml create mode 100644 state.json.example diff --git a/.env.example b/.env.example index da32cc5..52ae9e2 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,10 @@ -VIRTFUSION_TOKEN=your_token_here \ No newline at end of file +# Токен доступа к API VirtFusion (передается в заголовке Authorization: Bearer ) +VIRTFUSION_TOKEN=your_virtfusion_token_here + +# Токен Telegram-бота, полученный от @BotFather +TELEGRAM_BOT_TOKEN=123456789:ABCdefGhIJKlmNoPQRsTUVwxyZ + +# ID чата или канала для отправки уведомлений +# Для персонального чата: 123456789 +# Для публичного/приватного канала: -1001234567890 (обязательно с префиксом -100) +TELEGRAM_CHAT_ID=-1001234567890 \ No newline at end of file diff --git a/.gitignore b/.gitignore index 42c5ac2..0ff63f0 100644 --- a/.gitignore +++ b/.gitignore @@ -221,4 +221,5 @@ __marimo__/ .streamlit/secrets.toml # This -config.json \ No newline at end of file +config.json +state.json \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..a515f72 --- /dev/null +++ b/Makefile @@ -0,0 +1,11 @@ +.PHONY: install-deps build clean + +install-deps: + echo "Проверка и установка зависимостей для сборки deb-пакета..." + sudo apt update && sudo apt install -y debhelper dh-python pybuild-plugin-pyproject python3-build python3-all python3-setuptools build-essential devscripts + +build: install-deps + dpkg-buildpackage -us -uc -b + +clean: + debian/rules clean diff --git a/config.json.example b/config.json.example index 9b36464..7de5091 100644 --- a/config.json.example +++ b/config.json.example @@ -1,14 +1,21 @@ { - "servers": [ - { - "uuid": "00000000-0000-0000-0000-000000000000", - "target": "Target name from xray-manager", - "pretty_name": "Pretty name from xray-manager" - }, - { - "uuid": "11111111-1111-1111-1111-111111111111", - "target": "Target name from xray-manager", - "pretty_name": "Pretty name from xray-manager" - } + "_comment": "Конфигурационный файл локально хранится в корне проекта (./config.json), а на сервере — в /etc/traffic-checker/config.json", + "thresholds": { + "warning_percents": [ + 80.0, + 90.0 ] + }, + "servers": [ + { + "uuid": "11111111-2222-4333-8444-555555555555", + "target": "nl1", + "pretty_name": "🇳🇱 Netherlands #1" + }, + { + "uuid": "a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d", + "target": "de1", + "pretty_name": "🇩🇪 Germany #1" + } + ] } \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..2fdf943 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,26 @@ +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" + +[project] +name = "traffic-checker" +version = "0.1" +description = "Traffic consumption monitoring CLI tool for remote servers with automated alerting" +requires-python = ">=3.11" +authors = [ + { name = "Vladimir Khvan", email = "thisisnotablownfuse@gmail.com" } +] +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.11", + "Operating System :: POSIX :: Linux", +] +dependencies = [ + "requests>=2.32.3", +] + +[project.scripts] +traffic-checker = "traffic_checker.main:main" + +[tool.setuptools.packages.find] +where = ["src"] \ No newline at end of file diff --git a/state.json.example b/state.json.example new file mode 100644 index 0000000..e934507 --- /dev/null +++ b/state.json.example @@ -0,0 +1,13 @@ +{ + "_comment": "Файл состояния локально хранится в корне проекта (./state.json), а на сервере — в /var/lib/traffic-checker/state.json", + "11111111-2222-4333-8444-555555555555": { + "last_threshold": 80.0, + "is_critical": false, + "period_reset": "2026-08-26T03:00:00+03:00" + }, + "a1b2c3d4-e5f6-4a5b-8c9d-0e1f2a3b4c5d": { + "last_threshold": 100.0, + "is_critical": true, + "period_reset": "2026-08-03T03:00:00+03:00" + } +} \ No newline at end of file