-
Notifications
You must be signed in to change notification settings - Fork 4
/
hotspot_user.py
36 lines (32 loc) · 1.49 KB
/
hotspot_user.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
from config import MIKROTIK_REST_API_URL, MIKROTIK_REST_API_USER, MIKROTIK_REST_API_PASSWORD
from logger import logger
def get_hotspot_user_data():
logger.debug("Fetching hotspot user data")
try:
response_users = requests.get(
f'{MIKROTIK_REST_API_URL}/ip/hotspot/user',
auth=(MIKROTIK_REST_API_USER, MIKROTIK_REST_API_PASSWORD)
)
response_users.raise_for_status()
users = response_users.json()
response_active = requests.get(
f'{MIKROTIK_REST_API_URL}/ip/hotspot/active',
auth=(MIKROTIK_REST_API_USER, MIKROTIK_REST_API_PASSWORD)
)
response_active.raise_for_status()
active_users = response_active.json()
response_hosts = requests.get(
f'{MIKROTIK_REST_API_URL}/ip/hotspot/host',
auth=(MIKROTIK_REST_API_USER, MIKROTIK_REST_API_PASSWORD)
)
response_hosts.raise_for_status()
hosts = response_hosts.json()
logger.info("Hotspot user data fetched successfully")
return f"Total data\n🚹User: {len(users)}\n🛜Active: {len(active_users)}\n🛗Host: {len(hosts)}"
except requests.exceptions.HTTPError as http_err:
logger.error(f"HTTP error occurred: {http_err}")
return f"Error fetching hotspot user data: {http_err}"
except Exception as err:
logger.error(f"Other error occurred: {err}")
return f"Error fetching hotspot user data: {err}"