FortiOS device_tracker

Great.
So it works until 5.6 at least.
I’ll try to run it against 6.0 sometime…

upgraded to 88.2
Seems like the FortiOS device tracker doesn’t work anymore.
Logs told me to change directories, so now I have custom_components/fortiOS/device_trackery.py

Now in logs I get this error.

Log Details (ERROR)
Sun Mar 03 2019 19:11:55 GMT-0600 (CST)

Error setting up platform fortiOS
Traceback (most recent call last):
  File "/usr/local/lib/python3.7/site-packages/homeassistant/components/device_tracker/__init__.py", line 177, in async_setup_platform
    platform.get_scanner, hass, {DOMAIN: p_config})
  File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/config/custom_components/fortiOS/device_tracker.py", line 32, in get_scanner
    scanner = FortiDeviceScanner(config[DOMAIN])
  File "/config/custom_components/fortiOS/device_tracker.py", line 50, in __init__
    self.success_init = self._update_info()
  File "/config/custom_components/fortiOS/device_tracker.py", line 70, in _update_info
    string_result = self._get_arp_data()
  File "/config/custom_components/fortiOS/device_tracker.py", line 104, in _get_arp_data
    from pexpect import pxssh
  File "/config/deps/lib/python3.7/site-packages/pexpect/__init__.py", line 75, in <module>
    from .pty_spawn import spawn, spawnu
  File "/config/deps/lib/python3.7/site-packages/pexpect/pty_spawn.py", line 15, in <module>
    from .spawnbase import SpawnBase
  File "/config/deps/lib/python3.7/site-packages/pexpect/spawnbase.py", line 218
    def expect(self, pattern, timeout=-1, searchwindowsize=-1, async=False):
                                                                   ^
SyntaxError: invalid syntax

Thoughts?

Any ideas? If not, I guess I will try another tracking system.

I didn’t have the time to look at the upgrade, but I saw that 88 was likely to break a lot of things. This component (which I rely on exclusively for device tracking), my central heater component too. So I decided to wait a bit before upgrading.

You have handled the first modification needed, move the custom component to the right directory. Have you created an empty __init__.py there ?

Next step will be to understand what has changed in the registration of the tracker. I’ll try to look at it (so break my system and upgrade !) next week. I run on VMWare so I can do a snapshot and restore if things go really bad !

@Mister_Slowhand

I ended up forgoing Fortinet tracking and used the unifi tracking. Everyone I want to track is on wifi, and I host my unifi controller on a VM via Google Engine. But I can certainly help you troubleshoot if you want. I did not create an empty init.py. Let me know if I can help. I am sure there are not too many home users with a Fortigate as a firewall. :slight_smile:

I’ve updated and tried… Move to 0.92 and everything went wrong.
Reverted to 0.91.4 and Fortios tracker seems to work. I didn’t do much :

  • move <custom>/device_tracker/fortios.py to <custom>/fortios/device_tracker.py
  • create an empty <custom>/fortios/__init.py__
  • don’t forget to ensure the full path has correct permissions for homeassistant user

At first nothing happened, but maybe 30 seconds later, the trackers were ok.

I have lots of problems though with other components, I’m not sure I won’t rollback (I’ve taken a VM snapshot to be safe !)

A few weeks later, I’m running 0.92.2 and everything is fine.
For this specific component :

  • create a __init__.py file with the domain information :
    DOMAIN= "FortiOS"
  • create a manifest.json (must be new with 0.92 from what I understand) :
{
  "domain": "FortiOS",
  "name": "FortiOS device tracker",
  "documentation": "https://www.home-assistant.io",
  "dependencies": [],
  "codeowners": [],
  "requirements": []
}

And that’s it.

Aside from HA compatibility, I could also test Forti Firmware compatibility. I’ve found every firmware compatible as of now :

  • 5.2 series, which are the latest for C generation. I wouldn’t recommend an early build though, they are not stable at all (DHCP mostly). 5.2.11 has proven reliable on a 111C. Move upwards without regrets with D series that support most recent releases.
  • 5.4 : only tested 5.4.6 as part of an upgrade path, it’s working too.
  • 5.6.4 is working great and also compatible. I guess this is the minimum version to use with devices with integrated wifi and/or FortiExtender.
  • 6.0.4 is fine too.
  • 6.2.0 works fine, is the latest and very fast. I’m running this one on my 100D and it’s the best firmware I’ve seen for years. (and it’s a .0 !)

Basically, it should work with any firmware that has the “get system arp” command.

I’m trying to implement this but I’ve never added a custom component before. I’ve read through the post and I think I understand but I can’t get it to work.

In my HA config directory I created the directory custom_components then device_tracker inside that, then created the fortiOS.py file and init.py

Inside the fortiOS.py I pasted the code as you had above but did not edit anything inside the file, maybe I missed something there.

The init.py file is left blank

The following keeps showing up in my logs:
2019-08-30 19:41:57 ERROR (MainThread) [homeassistant.components.hassio] extra keys not allowed @ data[‘custom_components’]

Any guidance would be greatly appreciated.

Whatever I try… nothing :-(… I tried both options:


not seeing any devices/integrations/users/entities…
what - is - wrong?

image

Can play around with the “#'s”

I happen to have a FortiGate 60D that is surplus and only ever used for a week, anyone interested then please DM me.

Whatever I try… nothing. Fortigate 81E and FortiOS 6.2

Hi, someone have try with success the fortigate integration?

I’ve managed to get it to work but is there any way to limit the devices? Right now, it’s pulling each and every device from the Fortigate and it create a device_tracker for all of them. In my case, this mean dozen and dozen of device where I only want to track two.

Any way to do this?

If you got the known_devices.yaml file you will see some options there. I use it to change the entity name

givenname:

And the friendly name

name: this one

Then there is also a “track” option.

Maybe you can do something with this?

I have never tried to hide devices. If you delete an entry from above file it will come back on restart of home assistant.

I was able to get it to show only the device I want by adding this to my configuration file:

track_new_devices: False

After that, it created a known_devices.yaml with all devices set to “track: False”. I just had to change those I wished to track to “True”.

Problem I have right now is the fact that the Fortigate seems to be unreliable in detecting wether the device is there or not. Every morning when my wife leaves, it switch to away for maybe 30-40 minutes, then it will be switch back to home (even if my wife’s phone is at the office 10km away) for 5-7 minutes, then back to away for another 5-7 minutes, then again it goes back to home for another 5-7 minutes before settling to away until she comes back. I just can’t understand why it does that.

I remember something in fortios to set the timing different… so that if the device is not detected the fortigate sets this as away quicker… let me try to google it…

YES! found it:

Device offline timeout

A device is considered offline if it has not sent any packets during the timeout period. The timeout can be set to any value from 30 to 31 536 000 seconds (365 days). The default value is 300 seconds (5 minutes). The timer is configurable in the CLI:

config system global

set device-idle-timeout 300

end

https://help.fortinet.com/fos50hlp/56/Content/FortiOS/fortigate-managing-devices/Device%20monitoring.htm

Did it work?

Hi there, I’m happy to find this threat in development / FortiOS / FortiGatte.
Thanks @DarthSebulba04 and all the others that made this possible. WONDERFUL
Presence is the CORE of any HomeAutomation/Domotica and may commercial products have a poor/non-complete implementation of presence/presentation: THÉ reason to start my HAS!

As my first integration (and one of the biggest motivators) I tried this integration.
After struggling for about 1/2 day (my bad), I have devices in my HAS… Yippee :wink: (yet not all I expected). However, I have a couple of log lines:

2020-07-09 13:17:25 ERROR (SyncWorker_1) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’ 2020-07-09 13:17:26 ERROR (SyncWorker_14) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’
2020-07-09 13:17:26 ERROR (SyncWorker_17) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’ 2020-07-09 13:17:26 ERROR (SyncWorker_18) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’
2020-07-09 13:17:26 ERROR (SyncWorker_19) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’ 2020-07-09 13:17:26 ERROR (SyncWorker_9)
[homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’
2020-07-09 13:17:26 ERROR (SyncWorker_14) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’ 2020-07-09 13:17:26 ERROR (SyncWorker_18) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’
2020-07-09 13:17:26 ERROR (SyncWorker_11) [homeassistant.components.fortios.device_tracker] Name not found in client data: ‘host’

can anyone relate to this or anyone have any idea?

Furthermore, can the “timer” be influenced? I.e. how fast/slow does HA “see” devices appear/disappear? It would be benneficial to have that every 300 seconds minimum.

Thanks a million in advance.
FB

I have those errors in the log too. Seems like it’s only when HA starts and I’ve seen no consequences. Even when I moved from the ssh Forti tracker I made to the standard fortios integration.

If I understand correctly your question, the “timer” is in the fortios device tracker configuration :

consider_home: 180

Removes the device in HA when not seen for 3mn.

could you please share the custom files