revert
This commit is contained in:
36
app.py
36
app.py
@ -56,41 +56,15 @@ class UnifiAPI:
|
|||||||
'Accept': 'application/json'
|
'Accept': 'application/json'
|
||||||
}
|
}
|
||||||
|
|
||||||
def login(self):
|
|
||||||
"""Login to UDM Pro using the API key"""
|
|
||||||
login_url = f"{self.base_url}/api/auth/login"
|
|
||||||
response = self.session.post(login_url, json={
|
|
||||||
"username": "admin",
|
|
||||||
"apiKey": self.api_key
|
|
||||||
})
|
|
||||||
response.raise_for_status()
|
|
||||||
# Store CSRF token for subsequent requests
|
|
||||||
self.csrf_token = response.headers.get('X-CSRF-Token')
|
|
||||||
self.headers = {
|
|
||||||
'X-CSRF-Token': self.csrf_token,
|
|
||||||
'Accept': 'application/json'
|
|
||||||
}
|
|
||||||
|
|
||||||
def get_all_devices(self):
|
def get_all_devices(self):
|
||||||
logger.info(f"Fetching devices from UniFi controller at {self.base_url}")
|
url = f"{self.base_url}/v1/sites/{self.site_id}/devices"
|
||||||
try:
|
response = self.session.get(url, headers=self.headers)
|
||||||
url = f"{self.base_url}/proxy/network/integration/v1/sites/{self.site_id}/devices"
|
return response.json()['data']
|
||||||
logger.debug(f"Making request to: {url}")
|
|
||||||
response = self.session.get(url, headers=self.headers)
|
|
||||||
response.raise_for_status()
|
|
||||||
devices = response.json()
|
|
||||||
logger.info(f"Successfully fetched {len(devices)} devices")
|
|
||||||
return devices
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to fetch devices: {str(e)}")
|
|
||||||
return []
|
|
||||||
|
|
||||||
def get_device_details(self, device_id):
|
def get_device_details(self, device_id):
|
||||||
"""Get device details using the proxy/network prefix for UDM Pro"""
|
url = f"{self.base_url}/v1/sites/{self.site_id}/devices/{device_id}"
|
||||||
url = f"{self.base_url}/proxy/network/api/s/{self.site_id}/stat/device/{device_id}"
|
|
||||||
response = self.session.get(url, headers=self.headers)
|
response = self.session.get(url, headers=self.headers)
|
||||||
response.raise_for_status()
|
return response.json()
|
||||||
return response.json()['data'][0]
|
|
||||||
|
|
||||||
def get_device_diagnostics(self, device):
|
def get_device_diagnostics(self, device):
|
||||||
details = self.get_device_details(device['ip'])
|
details = self.get_device_details(device['ip'])
|
||||||
|
|||||||
Reference in New Issue
Block a user