identify device by ip in api
This commit is contained in:
18
app.py
18
app.py
@ -55,18 +55,20 @@ class UnifiAPI:
|
|||||||
self.session = requests.Session()
|
self.session = requests.Session()
|
||||||
self.session.verify = False
|
self.session.verify = False
|
||||||
|
|
||||||
def get_device_details(self, device_id):
|
def get_all_devices(self):
|
||||||
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/{device_id}"
|
response = self.session.get(url, headers=self.headers)
|
||||||
response = self.session.get(url, headers=self.headers, timeout=5)
|
|
||||||
response.raise_for_status()
|
|
||||||
return response.json()
|
return response.json()
|
||||||
except requests.exceptions.RequestException as e:
|
|
||||||
logging.error(f"Failed to get device details: {e}")
|
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
|
return None
|
||||||
|
|
||||||
def get_device_diagnostics(self, device):
|
def get_device_diagnostics(self, device):
|
||||||
details = self.get_device_details(device['device_id'])
|
details = self.get_device_details(device['ip'])
|
||||||
if not details:
|
if not details:
|
||||||
return {'state': 'ERROR', 'error': 'Failed to fetch device details'}
|
return {'state': 'ERROR', 'error': 'Failed to fetch device details'}
|
||||||
|
|
||||||
|
|||||||
36
config.json
36
config.json
@ -10,48 +10,14 @@
|
|||||||
"ip": "10.10.10.1",
|
"ip": "10.10.10.1",
|
||||||
"type": "router",
|
"type": "router",
|
||||||
"connection_type": "copper",
|
"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
|
"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",
|
"name": "USW Pro 24 PoE",
|
||||||
"ip": "10.10.10.139",
|
"ip": "10.10.10.139",
|
||||||
"type": "switch",
|
"type": "switch",
|
||||||
"connection_type": "fiber",
|
"connection_type": "fiber",
|
||||||
"critical": true,
|
"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"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"check_interval": 30,
|
"check_interval": 30,
|
||||||
|
|||||||
Reference in New Issue
Block a user