added debug for api calls
This commit is contained in:
39
app.py
39
app.py
@ -119,17 +119,15 @@ class UnifiAPI:
|
|||||||
|
|
||||||
# Monitoring functions
|
# Monitoring functions
|
||||||
def run_diagnostics(device):
|
def run_diagnostics(device):
|
||||||
config = load_config()
|
try:
|
||||||
unifi = UnifiAPI(config)
|
config = load_config()
|
||||||
|
unifi = UnifiAPI(config)
|
||||||
diagnostics = unifi.get_device_diagnostics(device)
|
diagnostics = unifi.get_device_diagnostics(device)
|
||||||
|
logger.debug(f"Got diagnostics for {device['name']}: {diagnostics}")
|
||||||
if device['connection_type'] == 'fiber':
|
return diagnostics
|
||||||
# Add fiber-specific diagnostics
|
except Exception as e:
|
||||||
sfp_data = get_sfp_diagnostics(device['ip'])
|
logger.error(f"Error getting diagnostics for {device['name']}: {str(e)}")
|
||||||
diagnostics['sfp'] = sfp_data
|
return {"error": str(e)}
|
||||||
|
|
||||||
return diagnostics
|
|
||||||
|
|
||||||
def update_status():
|
def update_status():
|
||||||
while True:
|
while True:
|
||||||
@ -160,14 +158,17 @@ def status():
|
|||||||
|
|
||||||
@app.route('/api/diagnostics')
|
@app.route('/api/diagnostics')
|
||||||
def get_diagnostics():
|
def get_diagnostics():
|
||||||
config = load_config()
|
try:
|
||||||
diagnostics = {}
|
config = load_config()
|
||||||
for device in config['devices']:
|
diagnostics = {}
|
||||||
if device.get('device_id'):
|
for device in config['devices']:
|
||||||
logger.debug(f"Fetching diagnostics for device: {device['name']}")
|
if device.get('device_id'):
|
||||||
diagnostics[device['name']] = run_diagnostics(device)
|
logger.debug(f"Fetching diagnostics for device: {device['name']}")
|
||||||
logger.debug(f"Returning diagnostics: {diagnostics}")
|
diagnostics[device['name']] = run_diagnostics(device)
|
||||||
return jsonify(diagnostics)
|
return jsonify(diagnostics)
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"Error in diagnostics endpoint: {str(e)}")
|
||||||
|
return jsonify({"error": str(e)}), 500
|
||||||
|
|
||||||
# Application entry point
|
# Application entry point
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|||||||
Reference in New Issue
Block a user