Initial commit for dev-8 branch with all current changes

This commit is contained in:
2025-08-31 15:35:42 +03:00
parent 5c2f9e501d
commit 98d12be67d
14 changed files with 157 additions and 1930 deletions

View File

@@ -1,83 +0,0 @@
#!/usr/bin/env python3
"""
Тестовый скрипт для проверки модуля мониторинга сервера
"""
import pytest
import asyncio
import sys
import os
# Добавляем путь к проекту
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from helper_bot.server_monitor import ServerMonitor
class MockBot:
"""Мок объект бота для тестирования"""
async def send_message(self, chat_id, text, parse_mode=None):
print(f"\n{'='*60}")
print(f"Отправка в чат: {chat_id}")
print(f"Текст сообщения:")
print(text)
print(f"{'='*60}\n")
@pytest.mark.asyncio
async def test_monitor():
"""Тестирование модуля мониторинга"""
print("🧪 Тестирование модуля мониторинга сервера")
print("=" * 60)
# Создаем мок бота
mock_bot = MockBot()
# Создаем монитор
monitor = ServerMonitor(
bot=mock_bot,
group_for_logs="-123456789",
important_logs="-987654321"
)
print("📊 Получение информации о системе...")
system_info = monitor.get_system_info()
if system_info:
print("✅ Информация о системе получена успешно")
print(f"CPU: {system_info['cpu_percent']}%")
print(f"RAM: {system_info['ram_percent']}%")
print(f"Disk: {system_info['disk_percent']}%")
print(f"Uptime: {system_info['system_uptime']}")
print("\n🤖 Проверка статуса процессов...")
voice_status, voice_uptime = monitor.check_process_status('voice_bot')
helper_status, helper_uptime = monitor.check_process_status('helper_bot')
print(f"Voice Bot: {voice_status} - {voice_uptime}")
print(f"Helper Bot: {helper_status} - {helper_uptime}")
print("\n📝 Тестирование отправки статуса...")
await monitor.send_status_message(system_info)
print("\n🚨 Тестирование отправки алерта...")
await monitor.send_alert_message(
"Использование CPU",
85.5,
"Нагрузка за 1 мин: 2.5"
)
print("\n✅ Тестирование отправки сообщения о восстановлении...")
await monitor.send_recovery_message(
"Использование CPU",
70.0,
85.5
)
else:
print("Не удалось получить информацию о системе")
print("\n🎯 Тестирование завершено!")
if __name__ == "__main__":
asyncio.run(test_monitor())