-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation
27 lines (21 loc) · 1.14 KB
/
location
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
#!/usr/bin/env python3
from unifi_api import get_unifi_devices, get_connected_clients
from heartbeat import send_heartbeat
# Fetch the list of devices
devices = get_unifi_devices()
clients = get_connected_clients()
for device in devices:
# Remove "routeur" from the device name for the location value
location = device.get("name").replace("routeur-", "").strip()
# Filter clients connected to this specific device
connected_clients = [client for client in clients if client.get("ap_mac") == device.get("mac")]
for client in connected_clients:
print(f" Client Name: {client.get('hostname') or 'Unknown'}, MAC: {client.get('mac')}, IP: {client.get('ip')}")
# Collect MAC addresses of connected clients
mac_addresses = [client.get("mac") for client in connected_clients]
# If there are connected clients, send a heartbeat
if mac_addresses:
print(f"Sending heartbeat for device '{device.get('name')}' at location '{location}' with {len(mac_addresses)} clients.")
send_heartbeat(mac_addresses, location)
else:
print(f"No clients connected to device '{device.get('name')}'.")