Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Presence detection for "always-on" devices or imported devices #814

Closed
2 tasks done
ingoratsdorf opened this issue Sep 30, 2024 · 7 comments
Closed
2 tasks done

Presence detection for "always-on" devices or imported devices #814

ingoratsdorf opened this issue Sep 30, 2024 · 7 comments
Labels
bug 🐛 Something isn't working help wanted 🆘 Extra attention is needed next release/in dev image🚀 This is coming in the next release or was already released if the issue is Closed.

Comments

@ingoratsdorf
Copy link
Contributor

Is there an existing issue for this?

Current Behavior

When a device is always on or has been imported before being scanned and discovered, the presence detection fails.
Although the device is online, there are no sessions, no events, and mo presence.

Expected Behavior

Device to show up in presence when online.

Steps To Reproduce

  1. Have an always-on device like a smart switch, wifi router, access point or simply import devices from a previous backup.
  2. Check presence.
  3. Device not present, although online.

Example:
image
There's a an "online since" field that is populated, but not sure from where?

Cause there are no session:
image

And no events either:
image

Presence in the device details page seem to have randomly stopped somewhere:
image

And presence in the monitoring page is not even there at all:
image

I have a few of such devices, some of them do not even have a presence in device details page.

Any ideas?
The only thing I could think of would be: If a device gets detected as online, then check if there's a previuous 'device-online' event, if not, create one with now as datetime stamp.

app.conf

No response

docker-compose.yml

No response

What branch are you running?

Dev

app.log

No response

Debug enabled

  • I have read and followed the steps in the wiki link above and provided the required debug logs and the log section covers the time when the issue occurs.
@ingoratsdorf ingoratsdorf added the bug 🐛 Something isn't working label Sep 30, 2024
@jokob-sk
Copy link
Owner

Hi @ingoratsdorf ,

Thanks for the report!

I've been avoiding this part of the app since I started maintaining it. The code isn't very readable IMO so I tried to avoid touching it. I know there are a couple of bugs, but I'd say they are non-breaking issues. I will try to have a look in the next few days, but not sure if I can find the bug.

If you have the availability and interest, these are the 2 files which I think need to be fixed.

https://github.com/jokob-sk/NetAlertX/blob/main/front/php/server/events.php
https://github.com/jokob-sk/NetAlertX/blob/main/server/networkscan.py#L176

@jokob-sk jokob-sk added the help wanted 🆘 Extra attention is needed label Oct 8, 2024
@johnwang16
Copy link
Contributor

It's because of SELECT * FROM Convert_Events_to_Sessions on line 173 of networkscan.py

In the SQLite file, Convert_Events_to_Sessions corresponds to a view that selects from the Events table. This determines whether a session begins based on the following events: 'New Device','Connected', however this misses the event 'Down Reconnected', which is why it never starts a new session for some devices.

Connecting to SQLite and fixing the view allowed the sessions to show up for me. I'm not sure what the best way of fixing this for existing users would be since it's essentially a one time database update.

DROP VIEW Convert_Events_to_Sessions;
CREATE VIEW Convert_Events_to_Sessions AS     SELECT EVE1.eve_MAC,
           EVE1.eve_IP,
           EVE1.eve_EventType AS eve_EventTypeConnection,
           EVE1.eve_DateTime AS eve_DateTimeConnection,
           CASE WHEN EVE2.eve_EventType IN ('Disconnected', 'Device Down') OR
                     EVE2.eve_EventType IS NULL THEN EVE2.eve_EventType ELSE '<missing event>' END AS eve_EventTypeDisconnection,
           CASE WHEN EVE2.eve_EventType IN ('Disconnected', 'Device Down') THEN EVE2.eve_DateTime ELSE NULL END AS eve_DateTimeDisconnection,
           CASE WHEN EVE2.eve_EventType IS NULL THEN 1 ELSE 0 END AS eve_StillConnected,
           EVE1.eve_AdditionalInfo
      FROM Events AS EVE1
           LEFT JOIN
           Events AS EVE2 ON EVE1.eve_PairEventRowID = EVE2.RowID
     WHERE EVE1.eve_EventType IN ('New Device', 'Connected','Down Reconnected')
UNION
    SELECT eve_MAC,
           eve_IP,
           '<missing event>' AS eve_EventTypeConnection,
           NULL AS eve_DateTimeConnection,
           eve_EventType AS eve_EventTypeDisconnection,
           eve_DateTime AS eve_DateTimeDisconnection,
           0 AS eve_StillConnected,
           eve_AdditionalInfo
      FROM Events AS EVE1
     WHERE (eve_EventType = 'Device Down' OR
            eve_EventType = 'Disconnected') AND
           EVE1.eve_PairEventRowID IS NULL;

@jokob-sk
Copy link
Owner

Amazing @johnwang16 🙏 thanks a lot!

Just pushed it to dev and should be available for testing in ~15 min in the netalertx-dev image

@jokob-sk jokob-sk added Waiting for reply⏳ Waiting for the original poster to respond, or discussion in progress. next release/in dev image🚀 This is coming in the next release or was already released if the issue is Closed. labels Oct 18, 2024
@johnwang16
Copy link
Contributor

Looks like this doesn't fix the issue where a device is imported and never has a connection event to begin with. I'll take a look at what can be done to address that.

@johnwang16
Copy link
Contributor

this should do it #855

@jokob-sk
Copy link
Owner

thanks @johnwang16 , the -dev build should be ready in ~15 min

@jokob-sk jokob-sk removed the Waiting for reply⏳ Waiting for the original poster to respond, or discussion in progress. label Oct 24, 2024
@jokob-sk
Copy link
Owner

releasing in 15 min -> closing - thanks again @johnwang16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working help wanted 🆘 Extra attention is needed next release/in dev image🚀 This is coming in the next release or was already released if the issue is Closed.
Projects
None yet
Development

No branches or pull requests

3 participants