Fortios device tracker updates (#92331)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com> Co-authored-by: Erik Montnemery <erik@montnemery.com>
This commit is contained in:
parent
3f936993a9
commit
bd0b8dc0bc
1 changed files with 18 additions and 16 deletions
|
@ -43,7 +43,7 @@ def get_scanner(hass: HomeAssistant, config: ConfigType) -> FortiOSDeviceScanner
|
||||||
fgt = FortiOSAPI()
|
fgt = FortiOSAPI()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
fgt.tokenlogin(host, token, verify_ssl)
|
fgt.tokenlogin(host, token, verify_ssl, None, 12, "root")
|
||||||
except ConnectionError as ex:
|
except ConnectionError as ex:
|
||||||
_LOGGER.error("ConnectionError to FortiOS API: %s", ex)
|
_LOGGER.error("ConnectionError to FortiOS API: %s", ex)
|
||||||
return None
|
return None
|
||||||
|
@ -77,7 +77,12 @@ class FortiOSDeviceScanner(DeviceScanner):
|
||||||
|
|
||||||
def update(self):
|
def update(self):
|
||||||
"""Update clients from the device."""
|
"""Update clients from the device."""
|
||||||
clients_json = self._fgt.monitor("user/device/query", "")
|
clients_json = self._fgt.monitor(
|
||||||
|
"user/device/query",
|
||||||
|
"",
|
||||||
|
parameters={"filter": "format=master_mac|hostname|is_online"},
|
||||||
|
)
|
||||||
|
|
||||||
self._clients_json = clients_json
|
self._clients_json = clients_json
|
||||||
|
|
||||||
self._clients = []
|
self._clients = []
|
||||||
|
@ -85,8 +90,12 @@ class FortiOSDeviceScanner(DeviceScanner):
|
||||||
if clients_json:
|
if clients_json:
|
||||||
try:
|
try:
|
||||||
for client in clients_json["results"]:
|
for client in clients_json["results"]:
|
||||||
if client["is_online"]:
|
if (
|
||||||
self._clients.append(client["mac"].upper())
|
"is_online" in client
|
||||||
|
and "master_mac" in client
|
||||||
|
and client["is_online"]
|
||||||
|
):
|
||||||
|
self._clients.append(client["master_mac"].upper())
|
||||||
except KeyError as kex:
|
except KeyError as kex:
|
||||||
_LOGGER.error("Key not found in clients: %s", kex)
|
_LOGGER.error("Key not found in clients: %s", kex)
|
||||||
|
|
||||||
|
@ -106,17 +115,10 @@ class FortiOSDeviceScanner(DeviceScanner):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
for client in data["results"]:
|
for client in data["results"]:
|
||||||
if client["mac"] == device:
|
if "master_mac" in client and client["master_mac"] == device:
|
||||||
try:
|
if "hostname" in client:
|
||||||
name = client["hostname"]
|
name = client["hostname"]
|
||||||
_LOGGER.debug("Getting device name=%s", name)
|
else:
|
||||||
return name
|
name = client["master_mac"].replace(":", "_")
|
||||||
except KeyError as kex:
|
return name
|
||||||
_LOGGER.debug(
|
|
||||||
"No hostname found for %s in client data: %s",
|
|
||||||
device,
|
|
||||||
kex,
|
|
||||||
)
|
|
||||||
return device.replace(":", "_")
|
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue