more loggging
This commit is contained in:
22
app.py
22
app.py
@ -56,16 +56,18 @@ class UnifiAPI:
|
|||||||
self.session.verify = False
|
self.session.verify = False
|
||||||
|
|
||||||
def get_all_devices(self):
|
def get_all_devices(self):
|
||||||
logger.debug(f"Fetching all devices from {self.base_url}")
|
logger.info(f"Fetching devices from UniFi controller at {self.base_url}")
|
||||||
try:
|
try:
|
||||||
url = f"{self.base_url}/proxy/network/integration/v1/sites/{self.site_id}/devices"
|
url = f"{self.base_url}/proxy/network/integration/v1/sites/{self.site_id}/devices"
|
||||||
|
logger.debug(f"Making request to: {url}")
|
||||||
|
logger.debug(f"Using headers: {self.headers}")
|
||||||
response = self.session.get(url, headers=self.headers)
|
response = self.session.get(url, headers=self.headers)
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
devices = response.json()
|
devices = response.json()
|
||||||
logger.debug(f"API Response: {devices}")
|
logger.info(f"Successfully fetched {len(devices)} devices")
|
||||||
return devices
|
return devices
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error fetching devices: {e}")
|
logger.error(f"Failed to fetch devices: {str(e)}")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_device_details(self, ip_address):
|
def get_device_details(self, ip_address):
|
||||||
@ -171,18 +173,22 @@ def status():
|
|||||||
|
|
||||||
@app.route('/api/diagnostics')
|
@app.route('/api/diagnostics')
|
||||||
def get_diagnostics():
|
def get_diagnostics():
|
||||||
|
logger.info("Diagnostics endpoint called")
|
||||||
try:
|
try:
|
||||||
config = load_config()
|
config = load_config()
|
||||||
|
unifi = UnifiAPI(config)
|
||||||
|
devices = unifi.get_all_devices()
|
||||||
|
logger.info(f"Found {len(devices)} devices")
|
||||||
diagnostics = {}
|
diagnostics = {}
|
||||||
for device in config['devices']:
|
for device in config['devices']:
|
||||||
if device.get('device_id'):
|
logger.info(f"Getting diagnostics for {device['name']}")
|
||||||
logger.debug(f"Fetching diagnostics for device: {device['name']}")
|
device_details = unifi.get_device_details(device['ip'])
|
||||||
diagnostics[device['name']] = run_diagnostics(device)
|
if device_details:
|
||||||
logger.debug(f"Returning diagnostics: {diagnostics}")
|
diagnostics[device['name']] = device_details
|
||||||
return jsonify(diagnostics)
|
return jsonify(diagnostics)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in diagnostics endpoint: {str(e)}")
|
logger.error(f"Error in diagnostics endpoint: {str(e)}")
|
||||||
return jsonify({"error": str(e)}), 500
|
return jsonify({"error": str(e)})
|
||||||
|
|
||||||
# Application entry point
|
# Application entry point
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user