diff --git a/app.py b/app.py index 1ae996d..94a78f9 100644 --- a/app.py +++ b/app.py @@ -55,18 +55,20 @@ class UnifiAPI: self.session = requests.Session() self.session.verify = False - def get_device_details(self, device_id): - try: - url = f"{self.base_url}/proxy/network/integration/v1/sites/{self.site_id}/devices/{device_id}" - response = self.session.get(url, headers=self.headers, timeout=5) - response.raise_for_status() - return response.json() - except requests.exceptions.RequestException as e: - logging.error(f"Failed to get device details: {e}") - return None + def get_all_devices(self): + url = f"{self.base_url}/proxy/network/integration/v1/sites/{self.site_id}/devices" + response = self.session.get(url, headers=self.headers) + return response.json() + + def get_device_details(self, ip_address): + devices = self.get_all_devices() + for device in devices: + if device['ipAddress'] == ip_address: + return device + return None def get_device_diagnostics(self, device): - details = self.get_device_details(device['device_id']) + details = self.get_device_details(device['ip']) if not details: return {'state': 'ERROR', 'error': 'Failed to fetch device details'} diff --git a/config.json b/config.json index c28fce8..1b06c3b 100644 --- a/config.json +++ b/config.json @@ -10,48 +10,14 @@ "ip": "10.10.10.1", "type": "router", "connection_type": "copper", - "critical": true, - "device_id": "udm-pro-id" - }, - { - "name": "USP PDU Pro", - "ip": "10.10.10.107", - "type": "pdu", - "connection_type": "copper", "critical": true }, - { - "name": "USW Aggregation", - "ip": "10.10.10.238", - "type": "switch", - "connection_type": "fiber", - "critical": true - }, - { - "name": "USW Flex Mini", - "ip": "10.10.10.169", - "type": "switch", - "connection_type": "copper" - }, { "name": "USW Pro 24 PoE", "ip": "10.10.10.139", "type": "switch", "connection_type": "fiber", - "critical": true, - "device_id": "usw-24-poe-id" - }, - { - "name": "U6 Lite", - "ip": "10.10.10.154", - "type": "access_point", - "connection_type": "copper" - }, - { - "name": "USP Strip", - "ip": "10.10.10.243", - "type": "pdu", - "connection_type": "copper" + "critical": true } ], "check_interval": 30,