Повна довідка REST API для PyMon Enterprise Server Monitoring.
Базова URL: http://localhost:10000
Автентифікація: Всі API ендпоінти (крім /api/v1/auth/login) вимагають JWT токен в заголовку:
Authorization: Bearer <your_token>
Отримати JWT токен доступу.
POST /api/v1/auth/login
Body:
{
"username": "admin",
"password": "<your-password>"
}Відповідь:
{
"access_token": "eyJ...",
"token_type": "bearer",
"user": {
"id": 1,
"username": "admin",
"is_admin": true,
"must_change_password": false
}
}POST /api/v1/auth/change-password
Body:
{
"current_password": "oldpass",
"new_password": "NewSecurePass123"
}Створення: POST /api/v1/auth/api-keys
{"name": "my-key"}Список: GET /api/v1/auth/api-keys
Список: GET /api/v1/auth/users (admin only)
Створення: POST /api/v1/auth/users (admin only)
{"username": "user1", "password": "SecurePass123", "is_admin": false}Оновлення: PUT /api/v1/auth/users/{userId} (admin only)
Видалення: DELETE /api/v1/auth/users/{userId} (admin only, крім admin)
Поточний користувач: GET /api/v1/auth/me
GET /api/v1/servers
Відповідь:
{
"servers": [
{
"id": 1,
"name": "Web Server 1",
"host": "192.168.1.100",
"agent_port": 9100,
"os_type": "linux",
"enabled": 1,
"last_status": "up",
"cpu_percent": 45.5,
"memory_percent": 62.3,
"disk_percent": 78.1
}
]
}POST /api/v1/servers
{
"name": "New Server",
"host": "192.168.1.200",
"os_type": "linux",
"agent_port": 9100,
"enabled": true,
"server_group": "Production",
"scrape_interval": 0
}GET /api/v1/servers/{server_id}
PUT /api/v1/servers/{server_id}
DELETE /api/v1/servers/{server_id}
POST /api/v1/servers/{server_id}/scrape
POST /api/v1/servers/{server_id}/maintenance
{"is_maintenance": true}GET /api/v1/servers/{server_id}/history?range=1h
Параметри range: 5m, 15m, 1h, 6h, 12h, 24h, 3d, 7d, 15d, 30d
GET /api/v1/servers/{server_id}/history-detail?range=1h
GET /api/v1/servers/{server_id}/disk-breakdown
GET /api/v1/servers/{server_id}/uptime-timeline?days=7
GET /api/v1/servers/{server_id}/export?format=json&range=24h
GET /api/v1/servers/{server_id}/export?format=csv&range=24h
GET /api/v1/servers/export?format=json&range=24h
GET /api/v1/servers/compare?metric=cpu&range=1h
Параметри metric: cpu, memory, disk
GET /api/v1/servers/summary/all
GET /api/v1/servers/history?range=1h&metric=cpu
GET /api/v1/servers/{server_id}/summary
POST /api/v1/metrics
{
"name": "cpu_usage",
"value": 45.2,
"type": "gauge",
"labels": [{"name": "host", "value": "server1"}],
"help_text": "CPU usage percentage"
}GET /api/v1/metrics
GET /api/v1/metrics/trend?range=1h
DELETE /api/v1/metrics/history
GET /metrics
GET /api/v1/alerts
POST /api/v1/alerts
{
"name": "High CPU",
"metric": "cpu_percent",
"condition": ">",
"threshold": 90,
"duration": 300,
"severity": "critical",
"server_id": 1,
"description": "CPU above 90%"
}DELETE /api/v1/alerts/{alert_id}
GET /api/v1/settings/notifications
POST /api/v1/settings/notifications
POST /api/v1/settings/notifications/test
GET /api/v1/settings/config/export
POST /api/v1/settings/config/import-prometheus
{
"yaml_content": "scrape_configs:\n - job_name: 'node'\n static_configs:\n - targets: ['localhost:9100']"
}GET /api/v1/services
POST /api/v1/services
{
"name": "My Website",
"target_url": "https://example.com",
"check_type": "http",
"interval": 60,
"timeout": 10
}GET /api/v1/services/history?range=1h
DELETE /api/v1/services/{service_id}
GET /api/v1/backup/list
POST /api/v1/backup/create
POST /api/v1/backup/restore
{"filename": "pymon_backup_20240101_120000.db"}GET /api/v1/audit-log?limit=100&offset=0
DELETE /api/v1/audit-log
GET /api/v1/audit-log/system-logs?lines=200
DELETE /api/v1/audit-log/system-logs
GET /api/v1/reports/server/{server_id}
Повертає HTML звіт з графіками Chart.js.
GET /api/v1/health
{"status": "healthy"}ws /api/v1/ws/metrics
Підключення для отримання оновлень метрик в реальному часі.
import httpx
async with httpx.AsyncClient() as client:
# Логін
resp = await client.post("http://localhost:10000/api/v1/auth/login",
json={"username": "admin", "password": "<your-password>"})
token = resp.json()["access_token"]
headers = {"Authorization": f"Bearer {token}"}
# Список серверів
servers = await client.get("http://localhost:10000/api/v1/servers",
headers=headers)
print(servers.json())TOKEN=$(curl -s -X POST http://localhost:10000/api/v1/auth/login \
-H "Content-Type: application/json" \
-d '{"username":"admin","password": "<your-password>"}' | python3 -c "import sys,json;print(json.load(sys.stdin)['access_token'])")
curl -s http://localhost:10000/api/v1/servers \
-H "Authorization: Bearer $TOKEN"